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
672b6626
Unverified
Commit
672b6626
authored
Aug 04, 2022
by
Thomas Wang
Committed by
GitHub
Aug 04, 2022
Browse files
Add FX support for torch.baddbmm andd torch.Tensor.baddbmm (#18363)
parent
df28de05
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
1 deletion
+13
-1
src/transformers/utils/fx.py
src/transformers/utils/fx.py
+13
-1
No files found.
src/transformers/utils/fx.py
View file @
672b6626
...
...
@@ -305,12 +305,22 @@ def torch_matmul(input, other, *, out=None):
def
torch_bmm
(
input
,
mat2
,
*
,
out
=
None
):
if
out
is
not
None
:
raise
ValueError
(
"Don't support in-place
abs
for MetaTensor analysis"
)
raise
ValueError
(
"Don't support in-place
bmm
for MetaTensor analysis"
)
batch_size
,
n
,
m
=
input
.
shape
_
,
_
,
p
=
mat2
.
shape
return
torch
.
empty
(
batch_size
,
n
,
p
,
device
=
"meta"
)
def
torch_baddbmm
(
input
,
batch1
,
batch2
,
*
,
beta
=
1
,
alpha
=
1
,
out
=
None
):
if
out
is
not
None
:
raise
ValueError
(
"Don't support in-place baddbmm for MetaTensor analysis"
)
return
torch_bmm
(
batch1
,
batch2
)
def
torch_tensor_baddbmm
(
self
,
batch1
,
batch2
,
*
,
beta
=
1
,
alpha
=
1
,
out
=
None
):
return
torch_baddbmm
(
self
,
batch1
,
batch2
,
beta
=
beta
,
alpha
=
alpha
,
out
=
out
)
def
torch_einsum
(
equation
,
*
operands
):
# TODO: infer shape without performing the computation, this might be quite hard.
concrete_operands
=
(
torch
.
empty_like
(
operand
,
device
=
"cpu"
)
for
operand
in
operands
)
...
...
@@ -495,6 +505,8 @@ _MANUAL_META_OVERRIDES: Dict[Callable, Callable] = {
torch
.
Tensor
.
mul
:
torch_tensor_mul
,
torch
.
matmul
:
torch_matmul
,
torch
.
bmm
:
torch_bmm
,
torch
.
baddbmm
:
torch_baddbmm
,
torch
.
Tensor
.
baddbmm
:
torch_tensor_baddbmm
,
torch
.
einsum
:
torch_einsum
,
torch
.
Tensor
.
repeat
:
torch_tensor_repeat
,
torch
.
roll
:
torch_roll
,
...
...
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