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
OpenDAS
vllm_cscc
Commits
72fc97a0
Unverified
Commit
72fc97a0
authored
Sep 24, 2024
by
Lucas Wilkinson
Committed by
GitHub
Sep 24, 2024
Browse files
[Bugfix] Fix torch dynamo fixes caused by `replace_parameters` (#8748)
parent
2529d09b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
vllm/model_executor/layers/quantization/utils/layer_utils.py
vllm/model_executor/layers/quantization/utils/layer_utils.py
+8
-4
No files found.
vllm/model_executor/layers/quantization/utils/layer_utils.py
View file @
72fc97a0
...
...
@@ -21,13 +21,17 @@ def replace_parameter(mod: torch.nn.Module, name: str,
new
:
Union
[
torch
.
Tensor
,
torch
.
nn
.
Parameter
])
->
None
:
old
=
getattr
(
mod
,
name
)
if
old
.
dtype
==
new
.
dtype
and
\
if
type
(
old
)
is
type
(
new
)
and
old
.
dtype
==
new
.
dtype
and
\
old
.
untyped_storage
().
nbytes
()
==
new
.
untyped_storage
().
nbytes
():
# If we can just update in-place to avoid re-registering
# can be faster if the underlying storage is the same
update_tensor_inplace
(
old
,
new
)
else
:
# Fallback re-register parameter
# Fallback re-register parameter, convert to Parameter if necessary
# this not only ensures we don't register a tensor as a parameter, but
# also ensures that all parameter subclasses get re-registered as
# parameters for `torch.compile` compatibility
if
not
isinstance
(
new
,
torch
.
nn
.
Parameter
):
new
=
torch
.
nn
.
Parameter
(
new
)
mod
.
register_parameter
(
name
,
torch
.
nn
.
Parameter
(
new
))
new
=
torch
.
nn
.
Parameter
(
new
,
requires_grad
=
False
)
mod
.
register_parameter
(
name
,
torch
.
nn
.
Parameter
(
new
,
requires_grad
=
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