|
105 | 105 | CONFIG_NAME, |
106 | 106 | GENERATION_CONFIG_NAME, |
107 | 107 | SAFE_WEIGHTS_NAME, |
108 | | - is_accelerate_available, |
109 | 108 | is_torch_bf16_available_on_device, |
110 | 109 | is_torch_fp16_available_on_device, |
111 | 110 | ) |
112 | 111 |
|
113 | 112 | from .generation.test_utils import GenerationTesterMixin |
114 | 113 |
|
115 | 114 |
|
116 | | -if is_accelerate_available(): |
117 | | - from accelerate.utils import compute_module_sizes |
118 | | - |
119 | | - |
120 | 115 | if is_torch_available(): |
121 | 116 | import torch |
122 | 117 | from safetensors import safe_open |
|
125 | 120 | from torch import nn |
126 | 121 |
|
127 | 122 | from transformers import MODEL_MAPPING |
| 123 | + from transformers.integrations.accelerate import compute_module_sizes |
128 | 124 | from transformers.integrations.tensor_parallel import _get_parameter_tp_plan |
129 | 125 | from transformers.modeling_utils import load_state_dict |
130 | 126 | from transformers.pytorch_utils import id_tensor_storage |
@@ -2370,7 +2366,7 @@ def test_disk_offload_bin(self): |
2370 | 2366 | torch.manual_seed(0) |
2371 | 2367 | base_output = model(**inputs_dict_class) |
2372 | 2368 |
|
2373 | | - model_size = compute_module_sizes(model)[""] |
| 2369 | + model_size = compute_module_sizes(model)[0][""] |
2374 | 2370 | with tempfile.TemporaryDirectory() as tmp_dir: |
2375 | 2371 | model.cpu().save_pretrained(tmp_dir, safe_serialization=False) |
2376 | 2372 |
|
@@ -2416,7 +2412,7 @@ def test_disk_offload_safetensors(self): |
2416 | 2412 | torch.manual_seed(0) |
2417 | 2413 | base_output = model(**inputs_dict_class) |
2418 | 2414 |
|
2419 | | - model_size = compute_module_sizes(model)[""] |
| 2415 | + model_size = compute_module_sizes(model)[0][""] |
2420 | 2416 | with tempfile.TemporaryDirectory() as tmp_dir: |
2421 | 2417 | model.cpu().save_pretrained(tmp_dir) |
2422 | 2418 |
|
@@ -2455,7 +2451,7 @@ def test_cpu_offload(self): |
2455 | 2451 | torch.manual_seed(0) |
2456 | 2452 | base_output = model(**inputs_dict_class) |
2457 | 2453 |
|
2458 | | - model_size = compute_module_sizes(model)[""] |
| 2454 | + model_size = compute_module_sizes(model)[0][""] |
2459 | 2455 | # We test several splits of sizes to make sure it works. |
2460 | 2456 | max_gpu_sizes = [int(p * model_size) for p in self.model_split_percents[1:]] |
2461 | 2457 | with tempfile.TemporaryDirectory() as tmp_dir: |
@@ -2498,7 +2494,7 @@ def test_model_parallelism(self): |
2498 | 2494 | torch.manual_seed(0) |
2499 | 2495 | base_output = model(**inputs_dict_class) |
2500 | 2496 |
|
2501 | | - model_size = compute_module_sizes(model)[""] |
| 2497 | + model_size = compute_module_sizes(model)[0][""] |
2502 | 2498 | # We test several splits of sizes to make sure it works. |
2503 | 2499 | max_gpu_sizes = [int(p * model_size) for p in self.model_split_percents[1:]] |
2504 | 2500 | with tempfile.TemporaryDirectory() as tmp_dir: |
|
0 commit comments