-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple call to transforms warm_up() #2317
Comments
Hi @vince62s, The transforms will warm_up twice in the build_vocab step, but not in the training step. That was the case before version 3.0. We did not bother to optimize for build_vocab as it was not an urgent issue at that time. The changes introduced in the release 3.0 switching to Dataloader makes things different: OpenNMT-py/onmt/inputters/dynamic_iterator.py Lines 346 to 351 in fcc205b
The To mitigate this issue, we should only initialize/warm_up transform objects in the processes where they will be used to avoid pickling and unpicking. One way we can try is to delay OpenNMT-py/onmt/inputters/dynamic_iterator.py Line 185 in fcc205b
def build_dynamic_dataset_iter
...
# transforms = make_transforms(opt, transforms_cls, vocabs)
# delay this to DynamicDatasetIter._init_datasets
corpora = get_corpora(opt, task)
if corpora is None:
assert task != CorpusTask.TRAIN, "only valid corpus is ignorable."
return None
data_iter = DynamicDatasetIter.from_opt(
corpora, transforms_cls, # pass class rather than object
vocabs, opt, task, copy=copy,
stride=stride, offset=offset)
... |
I really thought your bandwidth was unlimited :) There is an issue with your solution. We need to access "opt" to build the transforms from the cls. Instead what if we remove the |
@Zenglinxiao
When you implemented #1912 you added setstate / getstate logics for multiprocessing.
If I am not wrong and @anderleich / @panosk faced the same issue, here is what happening:
When using build_vocab.py there is a call to make_transforms() in the main process, and then we spawn n_threads. Because we pass the
transforms
created in main, the pickling/unpickling mechanism triggers another call to warm_up() in the__setstate__
hence we could avoid the first call towarm_up
in themake_transforms
.Even when we use
n_threads=1
we spawn another process so same behavior.When we train the story is a little different.
If we use
num_worker=0
the Dataloader is not used, everything is happening in the main process, hence callingwarm_up
is required somewhere (currently in themake_transforms
of thebuild_dynamic_dataset_iter
If
num_worker>0
then we fall back in the same situation as in build_vocab.What do you think should be the best approach to avoid double
warm_up
(which is quite annoying for some transforms that loads big stuff)cc @francoishernandez
The text was updated successfully, but these errors were encountered: