Skip to content

[Train] Update docstring and user guides for train_loop_config#43691

Merged
matthewdeng merged 9 commits intoray-project:masterfrom
woshiyyya:update_train_loop_config
Mar 8, 2024
Merged

[Train] Update docstring and user guides for train_loop_config#43691
matthewdeng merged 9 commits intoray-project:masterfrom
woshiyyya:update_train_loop_config

Conversation

@woshiyyya
Copy link
Member

@woshiyyya woshiyyya commented Mar 4, 2024

Why are these changes needed?

It's been a common issue that Ray Train users try to pass large data/model object through train_loop_config, which introduce large serialization overhead, and may incur some deserialization issues (e.g. deserialize cuda tensor on cpu actor (TrainTrainable)).

This PR adds comments in the user guide and docstring to warn users against similar attempts.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
@woshiyyya woshiyyya marked this pull request as ready for review March 4, 2024 23:33
from ray.train.torch import TorchTrainer
from ray.train import ScalingConfig

def train_func(config):
Copy link
Member Author

@woshiyyya woshiyyya Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not showing config argument in the first place, since we didn't specify train_loop_config in TorchTrainer in this code snippet. Users will be confused about where to put the train_func arguments.

Copy link
Contributor

@justinvyu justinvyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I agree, the config should not be promoted since it's mostly unnecessary for Train.

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Comment on lines 193 to 199
You can specify the input argument for `train_func` via the Trainer's `train_loop_config` parameter.

.. warning::

Avoid passing large data objects through `train_loop_config` to reduce the
serialization and deserialization overhead. Instead, it's preferred to
initialize large objects (e.g. datasets, models) directly in `train_func`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a code snippet to show how to populate these? I think we want to show that it's a dictionary.

def train_func(config):
    config[...]

config = {...}
trainer = TorchTrainer(train_func, train_loop_config=config, ...)

In the warning we can also show an example as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added two examples to

  • highlight the config format
  • show the good and bad practices of setting train_loop_config.


Each distributed training worker executes this function.

You can specify the input argument for `train_func` via the Trainer's `train_loop_config` parameter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally, we can extract this section out to a separate file and include it, similar to what's being done here.

In the future we may just have a full separate user guide for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I've extracted the common paragraph into a separate doc.

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
woshiyyya and others added 3 commits March 6, 2024 17:15
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: Yunxuan Xiao <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Copy link
Contributor

@c21 c21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from data side.

@matthewdeng matthewdeng merged commit 0edd366 into ray-project:master Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants