DeepSpeed
DeepSpeed copied to clipboard
[BUG] DeepSpeed Inference Error for Llama 3 Models AssertionError: Merging tensors is not allowed here!
Describe the bug Running inference on Llama 3 models gives an error
/src/chat-ai/venv3.10/lib/python3.10/site-packages/deepspeed/module_inject/replace_module.py in _replace_module(model, policies, prefix, layer_id, level_id, state_dict)
687 for name, child in model.named_children():
688 if child.__class__ in policies:
--> 689 replaced_module = policies[child.__class__][0](child,
690 policies[child.__class__][-1],
691 layer_id,
/src/chat-ai/venv3.10/lib/python3.10/site-packages/deepspeed/module_inject/replace_module.py in replace_fn(child, _policy, layer_id, prefix, state_dict)
325 # copy relevant state from child -> new module
326 if not is_autotp_training_mode() and config.replace_with_kernel_inject:
--> 327 new_module = replace_with_policy(child,
328 _policy,
329 config.triangular_masking,
/src/chat-ai/venv3.10/lib/python3.10/site-packages/deepspeed/module_inject/replace_module.py in replace_with_policy(child, policy_cls, triangular_masking, inference, layer_id)
252
253 # 9. deal with tensor parallelism.
--> 254 _container.apply_tensor_parallelism(mp_replace)
255
256 # 10. copy the tensors from the model-specific container to the new module
/src/chat-ai/venv3.10/lib/python3.10/site-packages/deepspeed/module_inject/containers/features/meta_tensor.py in apply_tensor_parallelism(self, mp_replace, **kwargs)
34 self.module.attention.attn_ob = None
35 else:
---> 36 super().apply_tensor_parallelism(mp_replace, **kwargs)
37
38 def copy_data_to_new_module(self):
/src/chat-ai/venv3.10/lib/python3.10/site-packages/deepspeed/module_inject/containers/features/hybrid_engine.py in apply_tensor_parallelism(self, mp_replace, reversed_dim)
87 """
88 # Setup the new Attention module
---> 89 self.attention_qkv_mp(mp_replace, reversed_dim=reversed_dim)
90 self.attention_o_mp(mp_replace, reversed_dim=reversed_dim)
91
/src/chat-ai/venv3.10/lib/python3.10/site-packages/deepspeed/module_inject/containers/features/split_qkv.py in attention_qkv_mp(self, mp_replace, reversed_dim)
47 allocate_tensor=reversed_dim) if src is not None else None
48 else:
---> 49 super().attention_qkv_mp(mp_replace)
50
51 def release_qkv(self):
/src/chat-ai/venv3.10/lib/python3.10/site-packages/deepspeed/module_inject/containers/base.py in attention_qkv_mp(self, mp_replace, reversed_dim)
238
239 def attention_qkv_mp(self, mp_replace, reversed_dim=False):
--> 240 self.module.attention.attn_qkvw = mp_replace.strided_copy(self.module.attention.attn_qkvw,
241 self.qkvw,
242 num_splits=3,
/src/chat-ai/venv3.10/lib/python3.10/site-packages/deepspeed/module_inject/auto_tp.py in strided_copy(self, dst, src, num_splits, int8, allocate_tensor)
75 dst.scale = src.scale
76 return dst
---> 77 self.merge_assert(src_shape[outer_dim], dst_shape[self.out_dim])
78 qkv_size = dst_shape[self.out_dim] // num_splits
79 qkv_split = [torch.split(src_s, qkv_size, dim=outer_dim) for src_s in src_split]
/src/chat-ai/venv3.10/lib/python3.10/site-packages/deepspeed/module_inject/auto_tp.py in merge_assert(self, dim1, dim2)
42
43 def merge_assert(self, dim1, dim2):
---> 44 assert dim1 > dim2, \
45 'Merging tensors is not allowed here! Please use deepspeed load_checkpoint\
46 for merging your checkpoints before replacing the transformer layer with\
AssertionError: Merging tensors is not allowed here! Please use deepspeed load_checkpoint for merging your checkpoints before replacing the transformer layer with inference-kernels
To Reproduce
# newer transformers have this issue for some models: https://github.com/unslothai/unsloth/issues/1476
pip install transformers==4.47.1
pip install deepspeed==0.16.7
and run
import transformers
from transformers import pipeline
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
import deepspeed
not_working_models = [
"HuggingFaceTB/SmolLM2-135M",
"meta-llama/Llama-3.2-1B",
"meta-llama/Llama-3.1-8B",
]
model_index = 0
model_name = not_working_models[model_index]
model = AutoModelForCausalLM.from_pretrained(model_name, low_cpu_mem_usage=True, device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(model_name)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
# Initialize the DeepSpeed-Inference engine
pipe.model = deepspeed.init_inference(
pipe.model,
dtype=torch.float16,
replace_method='auto',
replace_with_kernel_inject=True,
)
output = pipe('Hello')
Expected behavior Inference works, generates texts but faster than transformers.
ds_report output
--------------------------------------------------
DeepSpeed C++/CUDA extension op report
--------------------------------------------------
NOTE: Ops not installed will be just-in-time (JIT) compiled at
runtime if needed. Op compatibility means that your system
meet the required dependencies to JIT install the op.
--------------------------------------------------
JIT compiled ops requires ninja
ninja .................. [OKAY]
--------------------------------------------------
op name ................ installed .. compatible
--------------------------------------------------
[WARNING] async_io requires the dev libaio .so object and headers but these were not found.
[WARNING] async_io: please install the libaio-dev package with apt
[WARNING] If libaio is already installed (perhaps from source), try setting the CFLAGS and LDFLAGS environment variables to where it can be found.
async_io ............... [NO] ....... [NO]
fused_adam ............. [NO] ....... [OKAY]
cpu_adam ............... [NO] ....... [OKAY]
cpu_adagrad ............ [NO] ....... [OKAY]
cpu_lion ............... [NO] ....... [OKAY]
dc ..................... [NO] ....... [OKAY]
[WARNING] Please specify the CUTLASS repo directory as environment variable $CUTLASS_PATH
evoformer_attn ......... [NO] ....... [NO]
[WARNING] NVIDIA Inference is only supported on Ampere and newer architectures
[WARNING] FP Quantizer is using an untested triton version (3.2.0), only 2.3.(0, 1) and 3.0.0 are known to be compatible with these kernels
fp_quantizer ........... [NO] ....... [NO]
fused_lamb ............. [NO] ....... [OKAY]
fused_lion ............. [NO] ....... [OKAY]
[WARNING] gds requires the dev libaio .so object and headers but these were not found.
[WARNING] gds: please install the libaio-dev package with apt
[WARNING] If libaio is already installed (perhaps from source), try setting the CFLAGS and LDFLAGS environment variables to where it can be found.
gds .................... [NO] ....... [NO]
transformer_inference .. [NO] ....... [OKAY]
inference_core_ops ..... [NO] ....... [OKAY]
cutlass_ops ............ [NO] ....... [OKAY]
quantizer .............. [NO] ....... [OKAY]
ragged_device_ops ...... [NO] ....... [OKAY]
ragged_ops ............. [NO] ....... [OKAY]
random_ltd ............. [NO] ....... [OKAY]
[WARNING] sparse_attn requires a torch version >= 1.5 and < 2.0 but detected 2.6
[WARNING] using untested triton version (3.2.0), only 1.0.0 is known to be compatible
sparse_attn ............ [NO] ....... [NO]
spatial_inference ...... [NO] ....... [OKAY]
transformer ............ [NO] ....... [OKAY]
stochastic_transformer . [NO] ....... [OKAY]
--------------------------------------------------
DeepSpeed general environment info:
torch install path ............... ['/src/chat-ai/venv3.10/lib/python3.10/site-packages/torch']
torch version .................... 2.6.0+cu124
deepspeed install path ........... ['/src/chat-ai/venv3.10/lib/python3.10/site-packages/deepspeed']
deepspeed info ................... 0.16.7, unknown, unknown
torch cuda version ............... 12.4
torch hip version ................ None
nvcc version ..................... 11.7
deepspeed wheel compiled w. ...... torch 2.6, cuda 12.4
shared memory (/dev/shm) size .... 15.44 GB
System info (please complete the following information):
- OS: Ubuntu 22.04
- GPU count and types 1 GPU T4
- transformers 4.47.1
- deepspeed 0.16.7
- Python version 3.10.14
Similar Issues
https://github.com/deepspeedai/DeepSpeed/issues/3960 https://github.com/deepspeedai/DeepSpeed/issues/2691