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
d704c0b6
Unverified
Commit
d704c0b6
authored
Apr 05, 2024
by
Adam Louly
Committed by
GitHub
Apr 05, 2024
Browse files
Fix mixtral ONNX Exporter Issue. (#29858)
* fix mixtral onnx export * fix qwen model
parent
79d62b2d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
12 deletions
+4
-12
src/transformers/models/mixtral/modeling_mixtral.py
src/transformers/models/mixtral/modeling_mixtral.py
+2
-6
src/transformers/models/qwen2_moe/modeling_qwen2_moe.py
src/transformers/models/qwen2_moe/modeling_qwen2_moe.py
+2
-6
No files found.
src/transformers/models/mixtral/modeling_mixtral.py
View file @
d704c0b6
...
@@ -871,15 +871,11 @@ class MixtralSparseMoeBlock(nn.Module):
...
@@ -871,15 +871,11 @@ class MixtralSparseMoeBlock(nn.Module):
if
top_x
.
shape
[
0
]
==
0
:
if
top_x
.
shape
[
0
]
==
0
:
continue
continue
# in torch it is faster to index using lists than torch tensors
top_x_list
=
top_x
.
tolist
()
idx_list
=
idx
.
tolist
()
# Index the correct hidden states and compute the expert hidden state for
# Index the correct hidden states and compute the expert hidden state for
# the current expert. We need to make sure to multiply the output hidden
# the current expert. We need to make sure to multiply the output hidden
# states by `routing_weights` on the corresponding tokens (top-1 and top-2)
# states by `routing_weights` on the corresponding tokens (top-1 and top-2)
current_state
=
hidden_states
[
None
,
top_x
_list
].
reshape
(
-
1
,
hidden_dim
)
current_state
=
hidden_states
[
None
,
top_x
].
reshape
(
-
1
,
hidden_dim
)
current_hidden_states
=
expert_layer
(
current_state
)
*
routing_weights
[
top_x
_list
,
idx_list
,
None
]
current_hidden_states
=
expert_layer
(
current_state
)
*
routing_weights
[
top_x
,
idx
,
None
]
# However `index_add_` only support torch tensors for indexing so we'll use
# However `index_add_` only support torch tensors for indexing so we'll use
# the `top_x` tensor here.
# the `top_x` tensor here.
...
...
src/transformers/models/qwen2_moe/modeling_qwen2_moe.py
View file @
d704c0b6
...
@@ -843,15 +843,11 @@ class Qwen2MoeSparseMoeBlock(nn.Module):
...
@@ -843,15 +843,11 @@ class Qwen2MoeSparseMoeBlock(nn.Module):
if
top_x
.
shape
[
0
]
==
0
:
if
top_x
.
shape
[
0
]
==
0
:
continue
continue
# in torch it is faster to index using lists than torch tensors
top_x_list
=
top_x
.
tolist
()
idx_list
=
idx
.
tolist
()
# Index the correct hidden states and compute the expert hidden state for
# Index the correct hidden states and compute the expert hidden state for
# the current expert. We need to make sure to multiply the output hidden
# the current expert. We need to make sure to multiply the output hidden
# states by `routing_weights` on the corresponding tokens (top-1 and top-2)
# states by `routing_weights` on the corresponding tokens (top-1 and top-2)
current_state
=
hidden_states
[
None
,
top_x
_list
].
reshape
(
-
1
,
hidden_dim
)
current_state
=
hidden_states
[
None
,
top_x
].
reshape
(
-
1
,
hidden_dim
)
current_hidden_states
=
expert_layer
(
current_state
)
*
routing_weights
[
top_x
_list
,
idx_list
,
None
]
current_hidden_states
=
expert_layer
(
current_state
)
*
routing_weights
[
top_x
,
idx
,
None
]
# However `index_add_` only support torch tensors for indexing so we'll use
# However `index_add_` only support torch tensors for indexing so we'll use
# the `top_x` tensor here.
# the `top_x` tensor here.
...
...
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