Comments (3)
It's unlikely that there is an actual memory leak, since all the operations in WebDataset are synchronous, and we have run exabytes of data through these pipelines.
Possible sources are:
- attempts to decode entire videos into memory (with torchvision.io.read_video applied to long videos rather than clips)
- too large num_workers
- too large of a shuffle buffer, or a shuffle operation in the wrong place
Can you share your input pipeline, a "tar tvf ... | sed 30q" for one of your shards, and your machine configuration?
from webdataset.
So, the problem is not the webdataset (that is realy fast), it much faster than my GPUs could process and accumulate too much batch into memory.
To resolve this problem I created the follow PR #18 that limit how much batch is keep in memory.
example of my pipeline:
tar example: https://drive.google.com/file/d/18AdaxeWQO_dkA3O1po-9_kwBPb57scTz/view?usp=sharing
batch_size = 256
train_paths = ["gs://bla/bla/bla1", "gs://bla/bla/bla2"]
val_paths = ["gs://bla/bla/bla1", "gs://bla/bla/bla2"]
workers = 4
def decode_image(element):
img = io.BytesIO(element)
img = Image.open(img)
return np.array(img)
def parse(input):
data = json.loads(input['json'])
return input['jpg'], data['subfamilia_idx']
def norm_imgs(imgs):
imgs[:, 0] = (imgs[:, 0] - 0.485) / 0.229
imgs[:, 1] = (imgs[:, 1] - 0.456) / 0.224
imgs[:, 2] = (imgs[:, 2] - 0.406) / 0.225
return imgs
augmentation = build_aug()
def decode_batch(batch):
x, y = batch
x = np.stack([decode_image(img) for img in x], 0)
x = augmentation(images=x)
x = np.rollaxis(x, 3, 1).astype('float32')
x = norm_imgs(x)
x = torch.from_numpy(x)
return (x, torch.Tensor(np.array(y, dtype=np.int64)).type(torch.int64))
def decode_batch_val(batch):
x, y = batch
x = np.stack([decode_image(img) for img in x], 0)
x = np.rollaxis(x, 3, 1).astype('float32')
x = norm_imgs(x)
x = torch.from_numpy(x)
return (x, torch.Tensor(np.array(y, dtype=np.int64)).type(torch.int64))
# the strategy to execute ao process are much faster than process one by one.
dataset = wds.Dataset(train_paths).map(parse).shuffle(1000).batched(batch_size).map(decode_batch)
dataset_val = wds.Dataset(val_paths).map(parse).batched(batch_size).map(decode_batch_val)
dataloader = wds.MultiDataset(dataset, workers=workers)
dataloader_val = wds.MultiDataset(dataset_val, workers=workers)
for epoch in range(1000):
for i, (input_var, output_var) in enumerate(dataloader):
x = input_var.to(device)
y = output_var.to(device, non_blocking=True)
# do training
for i, (input_var, output_var) in enumerate(dataloader_val):
x = input_var.to(device)
y = output_var.to(device, non_blocking=True)
# do eval
from webdataset.
Ah, thanks, that's helpful.
Keep in mind that you do not need to use MultiDataset with WebDataset; it's an optional class that is simpler internally than DataLoader and gives you more options for shuffling and batching (e.g., you unbatch, shuffle, and rebatch in it). In most cases, regular DataLoader is just fine.
Please also have a look at github.com/nvlabs/tensorcom
from webdataset.
Related Issues (20)
- FAQ : What's the meaning of n in `with_epoch(n)` HOT 2
- Distributed Training with videos not working? HOT 1
- [Errno 32] Broken pipe - Download Failed Error with S3 URLs HOT 1
- Webdataset (Liaon115M) + Torchlightning (pl.DataModule) with visualizing progressbar during training HOT 1
- Seed in multiprocessing (DDP) is not fixed in shuffle() HOT 1
- Update pypi with 0.2.88?
- How does shuffling work? HOT 1
- Restricting the number of samples in the dataset HOT 1
- wds.Decoder TypeError: 'functools.partial' object is not iterable HOT 2
- Loop through same tar file 10 times? HOT 1
- Excess memory usage when generating short sequence clips HOT 3
- seed not used in shuffle HOT 1
- Memory leak during training with standard DataLoader coupled with WebDataset dataloader HOT 3
- `pipe:s3cmd` or `pipe:aws s3 cp` ?
- custom batch sampler ?
- PyPI packages not available for 2.90 or 2.88
- ShardListDataset does not work with multiprocessing_context=spawn
- batched augmentations with kornia
- Incorrect Documentation for default_collation_fn
- Validation Set Distributed Sampling when using WebDataset with FSDP
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webdataset.