Fix custom imports for both distributed and single device #1731
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
What is the purpose of this PR? Is it to
Closes #1540. To run custom recipes, you now need to specify via dotpath as if it were a module. this enables running with
python -m
under the hood oftorch.distributed.run
which will automatically prepend the current directory to sys.path.In
instantiate
, we append the current working directory to the sys.path so it is recognized byimport_module
in_get_component_from_path
in the Python path. This applies to both single device and distributed runs - previously we appended to sys.path BEFOREtorch.distributed.run
(#1617) which discards it for some reason. Now, we do it within instantiate itself.Test plan
Log before the fix, the CWD is not present in sys.path right before
import_module
:Log after the fix, you can see the CWD at the end of sys.path:
Tested both distributed and single device runs by using
tune cp
and modifying config to point to a local custom dataset builder atdata.dataset.custom_dataset
:Also tested the four combinations:
tune run full_finetune_single_device --config config/my_config_single_device.yaml
tune run recipe.tune_single --config config/my_config_single_device.yaml
tune run --nproc_per_node 4 full_finetune_distributed --config config/my_config.yaml
tune run --nproc_per_node 4 recipe.tune_dist --config config/my_config.yaml