mirror of
https://github.com/huggingface/diffusers.git
synced 2026-01-27 17:22:53 +03:00
fix "Expected all tensors to be on the same device, but found at least two devices" error (#11690)
* xx * fix Signed-off-by: YAO Matrix <matrix.yao@intel.com> * Update model_loading_utils.py * Update test_models_unet_2d_condition.py * Update test_models_unet_2d_condition.py * fix style Signed-off-by: YAO Matrix <matrix.yao@intel.com> * fix comments Signed-off-by: Matrix Yao <matrix.yao@intel.com> * Update unet_2d_blocks.py * update Signed-off-by: Matrix Yao <matrix.yao@intel.com> --------- Signed-off-by: YAO Matrix <matrix.yao@intel.com> Signed-off-by: Matrix Yao <matrix.yao@intel.com> Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
This commit is contained in:
@@ -165,7 +165,7 @@ class UNet2DConditionModel(
|
||||
"""
|
||||
|
||||
_supports_gradient_checkpointing = True
|
||||
_no_split_modules = ["BasicTransformerBlock", "ResnetBlock2D", "CrossAttnUpBlock2D"]
|
||||
_no_split_modules = ["BasicTransformerBlock", "ResnetBlock2D", "CrossAttnUpBlock2D", "UpBlock2D"]
|
||||
_skip_layerwise_casting_patterns = ["norm"]
|
||||
_repeated_blocks = ["BasicTransformerBlock"]
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ from diffusers.utils.testing_utils import (
|
||||
require_torch_2,
|
||||
require_torch_accelerator,
|
||||
require_torch_accelerator_with_training,
|
||||
require_torch_gpu,
|
||||
require_torch_multi_accelerator,
|
||||
require_torch_version_greater,
|
||||
run_test_in_subprocess,
|
||||
@@ -1829,8 +1828,8 @@ class ModelTesterMixin:
|
||||
|
||||
assert msg_substring in str(err_ctx.exception)
|
||||
|
||||
@parameterized.expand([0, "cuda", torch.device("cuda")])
|
||||
@require_torch_gpu
|
||||
@parameterized.expand([0, torch_device, torch.device(torch_device)])
|
||||
@require_torch_accelerator
|
||||
def test_passing_non_dict_device_map_works(self, device_map):
|
||||
init_dict, inputs_dict = self.prepare_init_args_and_inputs_for_common()
|
||||
model = self.model_class(**init_dict).eval()
|
||||
@@ -1839,8 +1838,8 @@ class ModelTesterMixin:
|
||||
loaded_model = self.model_class.from_pretrained(tmpdir, device_map=device_map)
|
||||
_ = loaded_model(**inputs_dict)
|
||||
|
||||
@parameterized.expand([("", "cuda"), ("", torch.device("cuda"))])
|
||||
@require_torch_gpu
|
||||
@parameterized.expand([("", torch_device), ("", torch.device(torch_device))])
|
||||
@require_torch_accelerator
|
||||
def test_passing_dict_device_map_works(self, name, device):
|
||||
# There are other valid dict-based `device_map` values too. It's best to refer to
|
||||
# the docs for those: https://huggingface.co/docs/accelerate/en/concept_guides/big_model_inference#the-devicemap.
|
||||
@@ -1945,7 +1944,7 @@ class ModelPushToHubTester(unittest.TestCase):
|
||||
delete_repo(self.repo_id, token=TOKEN)
|
||||
|
||||
|
||||
@require_torch_gpu
|
||||
@require_torch_accelerator
|
||||
@require_torch_2
|
||||
@is_torch_compile
|
||||
@slow
|
||||
@@ -2013,7 +2012,7 @@ class TorchCompileTesterMixin:
|
||||
model.eval()
|
||||
# TODO: Can test for other group offloading kwargs later if needed.
|
||||
group_offload_kwargs = {
|
||||
"onload_device": "cuda",
|
||||
"onload_device": torch_device,
|
||||
"offload_device": "cpu",
|
||||
"offload_type": "block_level",
|
||||
"num_blocks_per_group": 1,
|
||||
|
||||
@@ -358,7 +358,7 @@ class UNet2DConditionModelTests(ModelTesterMixin, UNetTesterMixin, unittest.Test
|
||||
model_class = UNet2DConditionModel
|
||||
main_input_name = "sample"
|
||||
# We override the items here because the unet under consideration is small.
|
||||
model_split_percents = [0.5, 0.3, 0.4]
|
||||
model_split_percents = [0.5, 0.34, 0.4]
|
||||
|
||||
@property
|
||||
def dummy_input(self):
|
||||
|
||||
Reference in New Issue
Block a user