Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
bb6fa06f
Unverified
Commit
bb6fa06f
authored
Sep 29, 2022
by
Michael Benayoun
Committed by
GitHub
Sep 29, 2022
Browse files
Add a getattr method, which replaces _module_getattr in torch.fx.Tracer from PyTorch 1.13+ (#19233)
parent
9d732fd2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
1 deletion
+6
-1
src/transformers/utils/fx.py
src/transformers/utils/fx.py
+6
-1
No files found.
src/transformers/utils/fx.py
View file @
bb6fa06f
...
...
@@ -862,11 +862,12 @@ class HFTracer(Tracer):
return
rv
# Replaced by .getattr from PyTorch 1.13
def
_module_getattr
(
self
,
attr
,
attr_val
,
parameter_proxy_cache
):
if
getattr
(
self
,
"_disable_module_getattr"
,
False
):
return
attr_val
else
:
# return super()._module_getattr(attr, attr_val, parameter_proxy_cache)
def
maybe_get_proxy_for_attr
(
attr_val
,
collection_to_search
,
parameter_proxy_cache
):
for
n
,
p
in
collection_to_search
:
if
attr_val
is
p
:
...
...
@@ -899,6 +900,10 @@ class HFTracer(Tracer):
return
attr_val
# Needed for PyTorch 1.13+
def
getattr
(
self
,
attr
:
str
,
attr_val
:
Any
,
parameter_proxy_cache
:
Dict
[
str
,
Any
]):
return
self
.
_module_getattr
(
attr
,
attr_val
,
parameter_proxy_cache
)
def
call_module
(
self
,
m
,
forward
,
args
,
kwargs
):
self
.
orig_forward
=
forward
return
super
().
call_module
(
m
,
forward
,
args
,
kwargs
)
...
...
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