-
Notifications
You must be signed in to change notification settings - Fork 115
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
support stateful model #493
Merged
Merged
Changes from all commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
d41110c
Allow loading of stateful models (no patching yet)
slyalin bcb7cac
Stateful models support
slyalin d4c165b
Fix forward for chatglm
slyalin a62dc6f
Passing stateful as a dedicated parameter
slyalin 403adb5
Fixed possibly misaligned types in ShapeOf Concat sub-expression
slyalin 6097bfd
Merge remote-tracking branch 'origin/main' into stateful
slyalin c54a466
Fixed critical typo in infer_request invocation
slyalin 6151bec
Merge remote-tracking branch 'origin/main' into stateful
slyalin 0e5aefc
Apply bettertransfomer when model is converted in stateful mode
slyalin 5087f92
Correct default value handling for stateful flag
slyalin 5ae6d5c
Apply bettertransformer under try-except to avoid crashes when model …
slyalin ddb182e
Added --stateful option in optimum-cli
slyalin 8e9a7e0
Merge remote-tracking branch 'origin/main' into stateful
slyalin a51ab27
Raise if too old version of opevino is used ans stateful=True
slyalin 6df798a
Fix openvino version check to be compatible with openvino-nightly
slyalin fa33784
Merged from recent main branch
slyalin aa299e6
Fix for bloom family
slyalin 70ff804
Allow loading of stateful models (no patching yet)
slyalin bf45cc7
Stateful models support
slyalin fafc040
Fix forward for chatglm
slyalin e4585fe
Passing stateful as a dedicated parameter
slyalin a5c48c4
Fixed possibly misaligned types in ShapeOf Concat sub-expression
slyalin 3ce4fe9
Fixed critical typo in infer_request invocation
slyalin 00bd0b3
Apply bettertransfomer when model is converted in stateful mode
slyalin 489799a
Correct default value handling for stateful flag
slyalin 312f24f
Apply bettertransformer under try-except to avoid crashes when model …
slyalin 4bca339
Added --stateful option in optimum-cli
slyalin a5f8558
Raise if too old version of opevino is used ans stateful=True
slyalin 2763639
Fix openvino version check to be compatible with openvino-nightly
slyalin f5da152
Fix for bloom family
slyalin da62d99
Fix general code style and appliy renaming suggestions
eaidova 33f86dc
fix version checking if openvino not in site-packages
eaidova 7d15415
use reset_stateif available
eaidova 0dfbb63
remove input patch in bettertransformer apply
eaidova 09bbe7b
add tests
eaidova e70a50d
add type hints and update doc strings
eaidova a57c86a
added more tests
eaidova 67deae2
Merge remote-tracking branch 'origin/main' into ea/stateful
slyalin 89ba0cb
Fixed outdated signature of InferRequest wrapper to fix one of the qu…
slyalin a85960a
Merge remote-tracking branch 'slyalin/stateful' into stateful
slyalin dcfcc2a
Merge remote-tracking branch 'origin/main' into stateful
slyalin df0e727
Switch to stateful model by default
slyalin 9992419
Merge remote-tracking branch 'origin/main' into stateful
slyalin 1c815a0
Allow loading of stateful models (no patching yet)
slyalin 132ae62
Stateful models support
slyalin fa02a9e
Fix forward for chatglm
slyalin 9094279
Passing stateful as a dedicated parameter
slyalin 14aeb55
Fixed possibly misaligned types in ShapeOf Concat sub-expression
slyalin 6594e70
Apply bettertransfomer when model is converted in stateful mode
slyalin 55c70fe
Correct default value handling for stateful flag
slyalin a1b41ac
Apply bettertransformer under try-except to avoid crashes when model …
slyalin a7d91b7
Added --stateful option in optimum-cli
slyalin 2aeaf68
Raise if too old version of opevino is used ans stateful=True
slyalin 72e9149
Fix openvino version check to be compatible with openvino-nightly
slyalin 4488836
Fix for bloom family
slyalin 843d364
Fix general code style and appliy renaming suggestions
eaidova 361e06e
fix version checking if openvino not in site-packages
eaidova 0b8ba34
use reset_stateif available
eaidova 6b88888
remove input patch in bettertransformer apply
eaidova 042944c
add tests
eaidova 662f615
add type hints and update doc strings
eaidova c75e40b
added more tests
eaidova 8531d3c
Fixed outdated signature of InferRequest wrapper to fix one of the qu…
slyalin b9d42a7
Stateful models support
slyalin 841c8ec
Fix forward for chatglm
slyalin 94ee68d
Passing stateful as a dedicated parameter
slyalin 7ce3eb4
Apply bettertransfomer when model is converted in stateful mode
slyalin 7ead0e8
Raise if too old version of opevino is used ans stateful=True
slyalin 49a7f8f
Fix openvino version check to be compatible with openvino-nightly
slyalin 3bf4272
Fix for bloom family
slyalin e2194b3
fix conflict
eaidova 70d086a
Merge remote-tracking branch 'sl/stateful' into ea/stateful
eaidova 6014294
fix test and add beam_idx attribute
eaidova 045cc69
apply review comments
eaidova 2c3e934
stateful by default fixes
eaidova 27c0f0a
less agressive stateful
eaidova 18caf84
ensure that task support stateful
eaidova b059a5f
remove debug print
eaidova dd9f41d
Apply suggestions from code review
eaidova 7006264
Apply suggestions from code review
eaidova 2fb9032
update requirements and warning messages
eaidova b5e87b2
Apply suggestions from code review
eaidova a18d57c
fix cli export
eaidova f79b4f1
Update optimum/exporters/openvino/__main__.py
eaidova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .__main__ import main_export | ||
from .convert import export, export_models, export_pytorch_via_onnx | ||
from .stateful import ensure_stateful_is_available, patch_stateful | ||
|
||
|
||
__all__ = ["main_export", "export", "export_models"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2023 The HuggingFace Team. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import logging as log | ||
|
||
from optimum.intel.utils.import_utils import is_torch_version | ||
|
||
|
||
def patch_model_with_bettertransformer(model): | ||
if is_torch_version("<", "2.0"): | ||
log.warn( | ||
"integration Scaled Dot Product Attention optimization supported only with torch > 2.0." | ||
"Usage model with stateful=True may be non-effective if model does not contain torch.functional.scaled_dot_product_attention" | ||
"It is recommended to upgrade PyTorch version for using stateful model or use stateful=False" | ||
) | ||
# model already has required SDPA implementation | ||
if getattr(model, "_supports_sdpa", False) and getattr(model.config, "_attn_implementation", "eager") == "sdpa": | ||
return model | ||
try: | ||
model = model.to_bettertransformer() | ||
except Exception as e: | ||
log.warn( | ||
f"Cannot apply model.to_bettertransformer because of the exception:\n{e}." | ||
" Usage model with stateful=True may be non-effective if model does not contain torch.functional.scaled_dot_product_attention" | ||
) | ||
return model | ||
|
||
return model |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most people will need to export the model they are exporting and "provide another model" is then not really helpful. In my experience, when export with PyTorch failed and ONNX was used instead, it was usually because of a technical issue, with optimum-intel or dependencies. So we could suggest to upgrade dependencies with
pip install --upgrade --upgrade-strategy eager optimum[openvino]
and maybe suggest to create an issue if exporting with PyTorch still fails?