WebDataset with meta information files Extra Format: in webdataset (tar), for each sample there is a '.id'; for each tar file, there is a '.meta.jsonl' file with the same name; The '.meta.jsonl' file contains lines of json objects, each with a 'key' field to match '.id'.
| 231 | return samples |
| 232 | |
| 233 | class MetaDistributedWebDataset(DataPipeline): |
| 234 | '''WebDataset with meta information files |
| 235 | Extra Format: |
| 236 | in webdataset (tar), for each sample there is a '.id'; |
| 237 | for each tar file, there is a '.meta.jsonl' file with the same name; |
| 238 | The '.meta.jsonl' file contains lines of json objects, each with a 'key' field to match '.id'. |
| 239 | ''' |
| 240 | def __init__(self, path, process_fn, seed, *, meta_names=[], nshards=sys.maxsize, shuffle_buffer=1000, include_dirs=None): |
| 241 | # os.environ['WDS_SHOW_SEED'] = '1' |
| 242 | if include_dirs is not None: # /webdatasets/A,/webdatasets/C |
| 243 | other_paths = [] |
| 244 | include_dirs = include_dirs.split(',') |
| 245 | for include_dir in include_dirs: |
| 246 | if '*' in include_dir: |
| 247 | include_dir, n = include_dir.split('*') |
| 248 | n = int(n) |
| 249 | else: |
| 250 | n = 1 |
| 251 | for cur_dir, dirs, files in os.walk(include_dir): |
| 252 | for f in files: |
| 253 | if f.endswith('tar') and os.path.getsize(os.path.join(cur_dir,f)) > 0: |
| 254 | # other_paths.append(os.path.join(cur_dir,f)) |
| 255 | other_paths.extend([os.path.join(cur_dir,f)]*n) |
| 256 | # print(f'Adding dataset paths {",".join(other_paths)}') |
| 257 | from braceexpand import braceexpand |
| 258 | if len(path) > 0: # not "" |
| 259 | path = list(braceexpand(path)) + other_paths |
| 260 | else: |
| 261 | path = other_paths |
| 262 | |
| 263 | tarfile_samples = partial(tarfile_samples_with_meta, meta_names=meta_names) |
| 264 | tarfile_to_samples = pipelinefilter(tarfile_samples) |
| 265 | |
| 266 | # if model parallel, shuffle_buffer should be 1 to disable shuffling |
| 267 | try: |
| 268 | from sat.mpu import get_model_parallel_world_size |
| 269 | if get_model_parallel_world_size() > 1: |
| 270 | shuffle_buffer = 1 |
| 271 | except Exception: |
| 272 | pass |
| 273 | |
| 274 | super().__init__( |
| 275 | ConfiguredResampledShards(path, seed, nshards=nshards), |
| 276 | tarfile_to_samples(), |
| 277 | wds.shuffle(shuffle_buffer), |
| 278 | process_fn |
| 279 | ) |
| 280 | |
| 281 | # rclone support |
| 282 | from webdataset.gopen import Pipe |
no outgoing calls