Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
8480fda6
Unverified
Commit
8480fda6
authored
Jul 14, 2024
by
fxmarty
Committed by
GitHub
Jul 14, 2024
Browse files
Fix `GenerationMixin.generate` compatibility with pytorch profiler (#31935)
use torch.compiler.is_compiling() when possible
parent
7f79a973
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
src/transformers/utils/import_utils.py
src/transformers/utils/import_utils.py
+9
-7
No files found.
src/transformers/utils/import_utils.py
View file @
8480fda6
...
...
@@ -642,12 +642,8 @@ def is_torch_mlu_available(check_device=False):
def
is_torchdynamo_available
():
if
not
is_torch_available
():
return
False
try
:
import
torch._dynamo
as
dynamo
# noqa: F401
return
True
except
Exception
:
return
False
return
version
.
parse
(
_torch_version
)
>=
version
.
parse
(
"2.0.0"
)
def
is_torch_compile_available
():
...
...
@@ -665,9 +661,15 @@ def is_torchdynamo_compiling():
if
not
is_torch_available
():
return
False
try
:
import
torch._dynamo
as
dynamo
# noqa: F401
# Importing torch._dynamo causes issues with PyTorch profiler (https://github.com/pytorch/pytorch/issues/130622) hence rather relying on `torch.compiler.is_compiling()` when possible.
if
version
.
parse
(
_torch_version
)
>=
version
.
parse
(
"2.3.0"
):
import
torch
return
torch
.
compiler
.
is_compiling
()
else
:
import
torch._dynamo
as
dynamo
# noqa: F401
return
dynamo
.
is_compiling
()
return
dynamo
.
is_compiling
()
except
Exception
:
return
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment