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
renzhc
diffusers_dcu
Commits
16c955c5
Unverified
Commit
16c955c5
authored
Jun 06, 2025
by
Sayak Paul
Committed by
GitHub
Jun 06, 2025
Browse files
[tests] add test for torch.compile + group offloading (#11670)
* add a test for group offloading + compilation. * tests
parent
0f91f2f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
5 deletions
+29
-5
tests/models/test_modeling_common.py
tests/models/test_modeling_common.py
+29
-5
No files found.
tests/models/test_modeling_common.py
View file @
16c955c5
...
@@ -1744,6 +1744,10 @@ class ModelPushToHubTester(unittest.TestCase):
...
@@ -1744,6 +1744,10 @@ class ModelPushToHubTester(unittest.TestCase):
delete_repo
(
self
.
repo_id
,
token
=
TOKEN
)
delete_repo
(
self
.
repo_id
,
token
=
TOKEN
)
@
require_torch_gpu
@
require_torch_2
@
is_torch_compile
@
slow
class
TorchCompileTesterMixin
:
class
TorchCompileTesterMixin
:
def
setUp
(
self
):
def
setUp
(
self
):
# clean up the VRAM before each test
# clean up the VRAM before each test
...
@@ -1759,12 +1763,7 @@ class TorchCompileTesterMixin:
...
@@ -1759,12 +1763,7 @@ class TorchCompileTesterMixin:
gc
.
collect
()
gc
.
collect
()
backend_empty_cache
(
torch_device
)
backend_empty_cache
(
torch_device
)
@
require_torch_gpu
@
require_torch_2
@
is_torch_compile
@
slow
def
test_torch_compile_recompilation_and_graph_break
(
self
):
def
test_torch_compile_recompilation_and_graph_break
(
self
):
torch
.
compiler
.
reset
()
init_dict
,
inputs_dict
=
self
.
prepare_init_args_and_inputs_for_common
()
init_dict
,
inputs_dict
=
self
.
prepare_init_args_and_inputs_for_common
()
model
=
self
.
model_class
(
**
init_dict
).
to
(
torch_device
)
model
=
self
.
model_class
(
**
init_dict
).
to
(
torch_device
)
...
@@ -1778,6 +1777,31 @@ class TorchCompileTesterMixin:
...
@@ -1778,6 +1777,31 @@ class TorchCompileTesterMixin:
_
=
model
(
**
inputs_dict
)
_
=
model
(
**
inputs_dict
)
_
=
model
(
**
inputs_dict
)
_
=
model
(
**
inputs_dict
)
def
test_compile_with_group_offloading
(
self
):
torch
.
_dynamo
.
config
.
cache_size_limit
=
10000
init_dict
,
inputs_dict
=
self
.
prepare_init_args_and_inputs_for_common
()
model
=
self
.
model_class
(
**
init_dict
)
if
not
getattr
(
model
,
"_supports_group_offloading"
,
True
):
return
model
.
eval
()
# TODO: Can test for other group offloading kwargs later if needed.
group_offload_kwargs
=
{
"onload_device"
:
"cuda"
,
"offload_device"
:
"cpu"
,
"offload_type"
:
"block_level"
,
"num_blocks_per_group"
:
1
,
"use_stream"
:
True
,
"non_blocking"
:
True
,
}
model
.
enable_group_offload
(
**
group_offload_kwargs
)
model
.
compile
()
with
torch
.
no_grad
():
_
=
model
(
**
inputs_dict
)
_
=
model
(
**
inputs_dict
)
@
slow
@
slow
@
require_torch_2
@
require_torch_2
...
...
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