|
85 | 85 | _update_init_kwargs_with_connected_pipeline, |
86 | 86 | load_sub_model, |
87 | 87 | maybe_raise_or_warn, |
88 | | - model_has_device_map, |
89 | 88 | variant_compatible_siblings, |
90 | 89 | warn_deprecated_model_variant, |
91 | 90 | ) |
@@ -407,16 +406,6 @@ def module_is_offloaded(module): |
407 | 406 |
|
408 | 407 | return hasattr(module, "_hf_hook") and isinstance(module._hf_hook, accelerate.hooks.CpuOffload) |
409 | 408 |
|
410 | | - # device-mapped modules should not go through any device placements. |
411 | | - device_mapped_components = [ |
412 | | - key for key, component in self.components.items() if model_has_device_map(component) |
413 | | - ] |
414 | | - if device_mapped_components: |
415 | | - raise ValueError( |
416 | | - "The following pipeline components have been found to use a device map: " |
417 | | - f"{device_mapped_components}. This is incompatible with explicitly setting the device using `to()`." |
418 | | - ) |
419 | | - |
420 | 409 | # .to("cuda") would raise an error if the pipeline is sequentially offloaded, so we raise our own to make it clearer |
421 | 410 | pipeline_is_sequentially_offloaded = any( |
422 | 411 | module_is_sequentially_offloaded(module) for _, module in self.components.items() |
@@ -1013,16 +1002,6 @@ def enable_model_cpu_offload(self, gpu_id: Optional[int] = None, device: Union[t |
1013 | 1002 | The PyTorch device type of the accelerator that shall be used in inference. If not specified, it will |
1014 | 1003 | default to "cuda". |
1015 | 1004 | """ |
1016 | | - # device-mapped modules should not go through any device placements. |
1017 | | - device_mapped_components = [ |
1018 | | - key for key, component in self.components.items() if model_has_device_map(component) |
1019 | | - ] |
1020 | | - if device_mapped_components: |
1021 | | - raise ValueError( |
1022 | | - "The following pipeline components have been found to use a device map: " |
1023 | | - f"{device_mapped_components}. This is incompatible with `enable_model_cpu_offload()`." |
1024 | | - ) |
1025 | | - |
1026 | 1005 | is_pipeline_device_mapped = self.hf_device_map is not None and len(self.hf_device_map) > 1 |
1027 | 1006 | if is_pipeline_device_mapped: |
1028 | 1007 | raise ValueError( |
@@ -1125,16 +1104,6 @@ def enable_sequential_cpu_offload(self, gpu_id: Optional[int] = None, device: Un |
1125 | 1104 | The PyTorch device type of the accelerator that shall be used in inference. If not specified, it will |
1126 | 1105 | default to "cuda". |
1127 | 1106 | """ |
1128 | | - # device-mapped modules should not go through any device placements. |
1129 | | - device_mapped_components = [ |
1130 | | - key for key, component in self.components.items() if model_has_device_map(component) |
1131 | | - ] |
1132 | | - if device_mapped_components: |
1133 | | - raise ValueError( |
1134 | | - "The following pipeline components have been found to use a device map: " |
1135 | | - f"{device_mapped_components}. This is incompatible with `enable_sequential_cpu_offload()`." |
1136 | | - ) |
1137 | | - |
1138 | 1107 | if is_accelerate_available() and is_accelerate_version(">=", "0.14.0"): |
1139 | 1108 | from accelerate import cpu_offload |
1140 | 1109 | else: |
|
0 commit comments