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

Text Embedding: Add optimizations with PT2_COMPILE and/or IPEX #274

Merged
merged 6 commits into from
Nov 29, 2023

Conversation

markstur
Copy link
Contributor

@markstur markstur commented Nov 20, 2023

Add flag to use pytorch compile and/or try IPEX.

To use IPEX:

  1. Install intel-extension-for-pytorch
  2. Set env var USE_IPEX=true

Default is false. If set to true, but the import fails, then a warning will be logged and USE_IPEX will be disabled.
Optionally, USE_XPU may be set to true to allow IPEX to use its xpu (only applies when IPEX is active).

USE_MPS has been added for GPU testing on Macbook (ignored when IPEX is used).

To invoke torch.compile() optimization, set the env var PT2_COMPILE=true.
torch.compile() is not available on all versions/platforms. A warning message is logged if this is enabled and throws an exception.

Copy link
Collaborator

@evaline-ju evaline-ju left a comment

Choose a reason for hiding this comment

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

source code updates look good to me in theory but there are a decent number of code branches - would it be possible to add a few small unit test cases to check that the expected device is used/set with any configuration?

* Was not very testable
* Refactored into testable pieces
* Added tests
* Pretty good coverage of env toggles using monkeypatch
* Still not requiring (or mocking) the optional libraries

Signed-off-by: markstur <[email protected]>
@markstur
Copy link
Contributor Author

source code updates look good to me in theory but there are a decent number of code branches - would it be possible to add a few small unit test cases to check that the expected device is used/set with any configuration?

Yep. The way it was written, I just didn't think unit tests made sense (which I know obviously meant it was written wrong). So I refactored and added tests to cover most of the code. Not mocking the actual optimize or compile at this point, but enough tests to get through those decision branches with monkeypatch env var fixtures.

Also added one line to "warmup" the model.

@markstur
Copy link
Contributor Author

I forgot the "mps" test will only work on a Mac GPU. Fix coming asap.

Thanks!

MPS only works on Mac GPU.  Add tests to tests.

Signed-off-by: markstur <[email protected]>
* undo the MPS conditional that was not needed

Signed-off-by: markstur <[email protected]>
Copy link
Collaborator

@evaline-ju evaline-ju left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for adding tests

@evaline-ju evaline-ju merged commit 86335af into caikit:main Nov 29, 2023
5 checks passed
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