Skip to content
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

[train] TransformersPredictor: Add support for custom pipeline class #36494

Merged
merged 6 commits into from
Jun 21, 2023

Conversation

krfricke
Copy link
Contributor

Why are these changes needed?

Creating a TransformersPredictor with a custom pipeline class is currently broken: The model can't be automatically inferred from a path. This only works in the transformers pipeline. This PR adds support for this by adding additional parameters to TransformersPredictor.from_checkpoint() that will call TransformersCheckpoint.get_model() to retrieve the model, if specified.

Related issue number

Solves https://discuss.ray.io/t/bug-in-ray-transformerpredictor-from-checkpoint/11033/2

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 :(

Kai Fricke added 2 commits June 16, 2023 11:14
Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <kai@anyscale.com>
@krfricke krfricke marked this pull request as ready for review June 16, 2023 13:33
@krfricke krfricke requested a review from Yard1 June 16, 2023 13:33
Copy link
Member

@Yard1 Yard1 left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me.

@krfricke
Copy link
Contributor Author

I will add more test cases for the new code paths.

Kai Fricke added 4 commits June 20, 2023 09:07
Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: Kai Fricke <kai@anyscale.com>
@krfricke krfricke merged commit 7ed5c6d into ray-project:master Jun 21, 2023
@krfricke krfricke deleted the train/hf-predictor branch June 21, 2023 11:02
krfricke added a commit that referenced this pull request Jun 22, 2023
krfricke added a commit that referenced this pull request Jun 22, 2023
krfricke added a commit that referenced this pull request Jun 22, 2023
krfricke added a commit that referenced this pull request Jun 23, 2023
… pipeline class"" (#36705)

Reverts #36701

This re-activates the changes in #36494 which were generally working. The problem was that an import of `TFPreTrainedModel` on a GPU instance seems to initialize the GPU and make it unusable by Ray workers, so that CUDA memory allocations fail.

Thus, imports of TF modules should be guarded behind the TYPE_CHECKING variable:

```
if TYPE_CHECKING:
    # ...
    from transformers.modeling_utils import PreTrainedModel
    from transformers.modeling_tf_utils import TFPreTrainedModel
```

Signed-off-by: Kai Fricke <kai@anyscale.com>
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
…ay-project#36494)

Creating a `TransformersPredictor` with a custom pipeline class is currently broken: The model can't be automatically inferred from a path. This only works in the transformers pipeline. This PR adds support for this by adding additional parameters to `TransformersPredictor.from_checkpoint()` that will call `TransformersCheckpoint.get_model()` to retrieve the model, if specified.

Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
…e class (ray-project#36494)" (ray-project#36701)

This reverts commit 7ed5c6d.

Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
… pipeline class"" (ray-project#36705)

Reverts ray-project#36701

This re-activates the changes in ray-project#36494 which were generally working. The problem was that an import of `TFPreTrainedModel` on a GPU instance seems to initialize the GPU and make it unusable by Ray workers, so that CUDA memory allocations fail.

Thus, imports of TF modules should be guarded behind the TYPE_CHECKING variable:

```
if TYPE_CHECKING:
    # ...
    from transformers.modeling_utils import PreTrainedModel
    from transformers.modeling_tf_utils import TFPreTrainedModel
```

Signed-off-by: Kai Fricke <kai@anyscale.com>
Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
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.

2 participants