TensorRT-LLM icon indicating copy to clipboard operation
TensorRT-LLM copied to clipboard

build llama fail

Open ixp9891 opened this issue 3 years ago • 18 comments

# pip list | grep torch pytorch-quantization 2.1.2 torch 1.12.1+cu113 torch-tensorrt 2.0.0.dev0 torchdata 0.7.0a0 torchtext 0.16.0a0 torchvision 0.16.0a0

# nvidia-smi +-----------------------------------------------------------------------------+ | NVIDIA-SMI 525.105.17 Driver Version: 525.105.17 CUDA Version: 12.2 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 NVIDIA A10 On | 00000000:00:07.0 Off | 0 | | 0% 24C P8 15W / 150W | 0MiB / 23028MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+

# make -C docker release_build CUDA_ARCHS="89-real;90-real" # make -C docker release_run # python3 ./scripts/build_wheel.py --trt_root /usr/local/tensorrt # pip install ./build/tensorrt_llm.whl* # python build.py --model_dir /code/model/llama/llama-2-7b-hf
--dtype float16
--remove_input_padding
--use_gpt_attention_plugin float16
--enable_context_fmha
--use_gemm_plugin float16
--output_dir /code/model/llama_tensor
--world_size 8
--tp_size 8

build llama fail

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py", line 1099, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/local/lib/python3.10/dist-packages/transformers/models/llama/modeling_llama.py", line 32, in <module>
    from ...modeling_utils import PreTrainedModel
  File "/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py", line 86, in <module>
    from accelerate import dispatch_model, infer_auto_device_map, init_empty_weights
  File "/usr/local/lib/python3.10/dist-packages/accelerate/__init__.py", line 3, in <module>
    from .accelerator import Accelerator
  File "/usr/local/lib/python3.10/dist-packages/accelerate/accelerator.py", line 34, in <module>
    from .checkpointing import load_accelerator_state, load_custom_state, save_accelerator_state, save_custom_state
  File "/usr/local/lib/python3.10/dist-packages/accelerate/checkpointing.py", line 24, in <module>
    from .utils import (
  File "/usr/local/lib/python3.10/dist-packages/accelerate/utils/__init__.py", line 112, in <module>
    from .launch import (
  File "/usr/local/lib/python3.10/dist-packages/accelerate/utils/launch.py", line 27, in <module>
    from ..utils.other import merge_dicts
  File "/usr/local/lib/python3.10/dist-packages/accelerate/utils/other.py", line 24, in <module>
    from .transformer_engine import convert_model
  File "/usr/local/lib/python3.10/dist-packages/accelerate/utils/transformer_engine.py", line 21, in <module>
    import transformer_engine.pytorch as te
  File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/__init__.py", line 6, in <module>
    from .module import LayerNormLinear
  File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/module/__init__.py", line 6, in <module>
    from .layernorm_linear import LayerNormLinear
  File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/module/layernorm_linear.py", line 15, in <module>
    from .. import cpp_extensions as tex
  File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/cpp_extensions/__init__.py", line 6, in <module>
    from transformer_engine_extensions import *
ImportError: /usr/local/lib/python3.10/dist-packages/transformer_engine_extensions.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZN2at4_ops5zeros4callEN3c108ArrayRefINS2_6SymIntEEENS2_8optionalINS2_10ScalarTypeEEENS6_INS2_6LayoutEEENS6_INS2_6DeviceEEENS6_IbEE

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/code/tensorrt_llm/examples/llama/build.py", line 24, in <module>
    from transformers import LlamaConfig, LlamaForCausalLM
  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
  File "/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py", line 1090, in __getattr__
    value = getattr(module, name)
  File "/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py", line 1089, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py", line 1101, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.models.llama.modeling_llama because of the following error (look up to see its traceback):
/usr/local/lib/python3.10/dist-packages/transformer_engine_extensions.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZN2at4_ops5zeros4callEN3c108ArrayRefINS2_6SymIntEEENS2_8optionalINS2_10ScalarTypeEEENS6_INS2_6LayoutEEENS6_INS2_6DeviceEEENS6_IbEE

ixp9891 avatar Nov 21 '23 01:11 ixp9891

What kind of GPU do you use?

byshiue avatar Nov 21 '23 01:11 byshiue

What kind of GPU do you use?

A10

ixp9891 avatar Nov 21 '23 01:11 ixp9891

Where do you get the following info?

# pip list | grep torch
pytorch-quantization 2.1.2
torch 1.12.1+cu113
torch-tensorrt 2.0.0.dev0
torchdata 0.7.0a0
torchtext 0.16.0a0
torchvision 0.16.0a0

We should use torch 2 in the docker image, do you print the info outside the docker container? It looks a environment setup issue about the transformers, and I don't have many insight now.

byshiue avatar Nov 21 '23 01:11 byshiue

Where do you get the following info?

# pip list | grep torch
pytorch-quantization 2.1.2
torch 1.12.1+cu113
torch-tensorrt 2.0.0.dev0
torchdata 0.7.0a0
torchtext 0.16.0a0
torchvision 0.16.0a0

We should use torch 2 in the docker image, do you print the info outside the docker container? It looks a environment setup issue about the transformers, and I don't have many insight now.

in docker image image

ixp9891 avatar Nov 21 '23 01:11 ixp9891

Could u please share us info with this cmd pip list installed -v |grep torch?

nv-guomingz avatar Nov 21 '23 03:11 nv-guomingz

Could u please share us info with this cmd pip list installed -v |grep torch?

I also encountered a similar problem when build llama.

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py", line 1099, in _get_module return importlib.import_module("." + module_name, self.name) File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/usr/local/lib/python3.10/dist-packages/transformers/models/llama/modeling_llama.py", line 32, in from ...modeling_utils import PreTrainedModel File "/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py", line 86, in from accelerate import dispatch_model, infer_auto_device_map, init_empty_weights File "/usr/local/lib/python3.10/dist-packages/accelerate/init.py", line 3, in from .accelerator import Accelerator File "/usr/local/lib/python3.10/dist-packages/accelerate/accelerator.py", line 34, in from .checkpointing import load_accelerator_state, load_custom_state, save_accelerator_state, save_custom_state File "/usr/local/lib/python3.10/dist-packages/accelerate/checkpointing.py", line 24, in from .utils import ( File "/usr/local/lib/python3.10/dist-packages/accelerate/utils/init.py", line 112, in from .launch import ( File "/usr/local/lib/python3.10/dist-packages/accelerate/utils/launch.py", line 27, in from ..utils.other import merge_dicts File "/usr/local/lib/python3.10/dist-packages/accelerate/utils/other.py", line 24, in from .transformer_engine import convert_model File "/usr/local/lib/python3.10/dist-packages/accelerate/utils/transformer_engine.py", line 21, in import transformer_engine.pytorch as te File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/init.py", line 6, in from .module import LayerNormLinear File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/module/init.py", line 6, in from .layernorm_linear import LayerNormLinear File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/module/layernorm_linear.py", line 15, in from .. import cpp_extensions as tex File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/cpp_extensions/init.py", line 6, in from transformer_engine_extensions import * ImportError: /usr/local/lib/python3.10/dist-packages/transformer_engine_extensions.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

The above exception was the direct cause of the following exception:

Traceback` (most recent call last):

File "/code/tensorrt_llm/examples/llama/build.py", line 24, in from transformers import LlamaConfig, LlamaForCausalLM File "", line 1075, in _handle_fromlist File "/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py", line 1090, in getattr value = getattr(module, name) File "/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py", line 1089, in getattr module = self._get_module(self._class_to_module[name]) File "/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py", line 1101, in _get_module raise RuntimeError( RuntimeError: Failed to import transformers.models.llama.modeling_llama because of the following error (look up to see its traceback): /usr/local/lib/python3.10/dist-packages/transformer_engine_extensions.cpython-310-x86_64-linux-gnu.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

root@k8s-110-release:/code/tensorrt_llm/examples/llama# pip list installed -v |grep torch pytorch-quantization 2.1.2 /usr/local/lib/python3.10/dist-packages pip torch 2.1.1 /usr/local/lib/python3.10/dist-packages pip torch-tensorrt 2.0.0.dev0 /usr/local/lib/python3.10/dist-packages pip torchdata 0.7.0a0 /usr/local/lib/python3.10/dist-packages pip torchtext 0.16.0a0 /usr/local/lib/python3.10/dist-packages pip torchvision 0.16.0a0 /usr/local/lib/python3.10/dist-packages pip

changer-zxy avatar Nov 21 '23 06:11 changer-zxy

Could u please share us info with this cmd pip list installed -v |grep torch?

image

ixp9891 avatar Nov 21 '23 06:11 ixp9891

Could u please share us info with this cmd pip list installed -v |grep torch?

image

That's weird. It should be pt 2.1.0a0+32f93b1

image.

nv-guomingz avatar Nov 21 '23 07:11 nv-guomingz

Could u please share us info with this cmd pip list installed -v |grep torch?

image

That's weird. It should be pt 2.1.0a0+32f93b1

image.

@nv-guomingz Do I have to use this version of torch? It was this version when I just finished building it. After running, it prompted that it did not match my GPU, so I upgraded torch again. Then the above error occurred. I guess ixp9891 is also the same as me.

changer-zxy avatar Nov 21 '23 08:11 changer-zxy

From the error message, the issue happens on transformers. So, we can only suggesting you using the torch version (also for other packages) to prevent the environment alignment issue.

Can you share the error message for "After running, it prompted that it did not match my GPU"?

byshiue avatar Nov 21 '23 08:11 byshiue

From the error message, the issue happens on transformers. So, we can only suggesting you using the torch version (also for other packages) to prevent the environment alignment issue.

Can you share the error message for "After running, it prompted that it did not match my GPU"?

I recreated an docker image , torch=2.1.0a0+29c30b1, but build llama still fail image image

The libcuda.so.1 file exists,Then I execute the command " export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-12.2/compat ",but no work image

ixp9891 avatar Nov 21 '23 14:11 ixp9891

make -C docker release_build CUDA_ARCHS="89-real;90-real"

I rembemer you build the docker with above cmd on A10. A10 is not ada lovelace or hopper arch. Could u please try below cmd? make -C docker release_build CUDA_ARCHS="80-real"

nv-guomingz avatar Nov 22 '23 02:11 nv-guomingz

make -C docker release_build CUDA_ARCHS="89-real;90-real"

I rembemer you build the docker with above cmd on A10. A10 is not ada lovelace or hopper arch. Could u please try below cmd? make -C docker release_build CUDA_ARCHS="80-real"

it work for me , but The build process is killed; image

python build.py --model_dir /home/model/llama-2-7b-hf \
                --dtype float16 \
                --remove_input_padding \
                --enable_context_fmha \
                --output_dir /home/model/llama_tensor/

ECS configuration CPU: 8 core memory: 30g gpu: A10 24g

ixp9891 avatar Nov 23 '23 00:11 ixp9891

Could you try smaller batch size, input length and output length first?

byshiue avatar Nov 23 '23 01:11 byshiue

Could you try smaller batch size, input length and output length first?

I reduced the batch size, input length, and output length successively until max_batch_size = 2, input length=10, output length = 10, but error still reported image

ixp9891 avatar Nov 24 '23 04:11 ixp9891

@ixp9891 I recommend increasing your swap. I was able to build Llama-7b with limited RAM of 16 GB when I increased my swap (on G5.xlarge).

In this case, you can monitor your RAM usage through tools like nmon or ntop during the build phase.

sudo fallocate -l 128G /swapfile && chmod 600 /swapfile && mkswap /swapfile && sudo swapon /swapfile && free -h 

Additionally, I believe you need to build TensorRT-LLM with both SM80 and SM86 together.

make -C docker release_build CUDA_ARCHS="80-real;86-real"

kmati-dev avatar Nov 24 '23 07:11 kmati-dev

Thanks all, I upgraded the ecs configuration to 64GB memory and solved the problem;

ECS configuration CPU: 16 core memory: 60g gpu: A10 24g

apt-get update && apt-get -y install git git-lfs
git clone https://github.com/NVIDIA/TensorRT-LLM.git
cd TensorRT-LLM
git submodule update --init --recursive
git lfs install
git lfs pull

# create image
make -C docker release_build CUDA_ARCHS="80-real;86-real"
make -C docker release_run

# build tensorrt_llm
python3 ./scripts/build_wheel.py --trt_root /usr/local/tensorrt
python3 ./scripts/build_wheel.py --clean  --trt_root /usr/local/tensorrt

# build llama and run
python build.py --model_dir /code/llama/llama-2-7b-hf/ \
                --dtype float16 \
                --remove_input_padding \
                --use_gpt_attention_plugin float16 \
                --enable_context_fmha \
                --use_gemm_plugin float16 \
                --output_dir /code/model/llama_tensor/ 

python3 run.py --max_output_len=50 \
               --tokenizer_dir /code/llama/llama-2-7b-hf/ \
               --engine_dir=/code/model/llama_tensor/

ixp9891 avatar Nov 27 '23 09:11 ixp9891

@ixp9891 I recommend increasing your swap. I was able to build Llama-7b with limited RAM of 16 GB when I increased my swap (on G5.xlarge).

In this case, you can monitor your RAM usage through tools like nmon or ntop during the build phase.

sudo fallocate -l 128G /swapfile && chmod 600 /swapfile && mkswap /swapfile && sudo swapon /swapfile && free -h 

Additionally, I believe you need to build TensorRT-LLM with both SM80 and SM86 together.

make -C docker release_build CUDA_ARCHS="80-real;86-real"

Hi, I increase my sawp to 128G but still meet the RAM issue. I want to build Baichuan2-7B.

          total        used        free      shared  buff/cache   available

Mem: 31Gi 836Mi 30Gi 1.0Mi 278Mi 30Gi Swap: 127Gi 2.1Gi 125Gi

[12/05/2023-07:27:09] [TRT-LLM] [W] Found pynvml==11.4.1. Please use pynvml>=11.5.0 to get accurate memory usage [12/05/2023-07:27:09] [TRT-LLM] [I] Serially build TensorRT engines. [12/05/2023-07:27:10] [TRT] [I] [MemUsageChange] Init CUDA: CPU +12, GPU +0, now: CPU 118, GPU 308 (MiB) [12/05/2023-07:27:13] [TRT] [I] [MemUsageChange] Init builder kernel library: CPU +482, GPU +80, now: CPU 736, GPU 388 (MiB) [12/05/2023-07:27:13] [TRT-LLM] [W] Invalid timing cache, using freshly created one [12/05/2023-07:27:41] [TRT-LLM] [I] Loading HF Baichuan v2_7b ... from /model/finetune_intent2_prompt_1114_ep-2 [12/05/2023-07:27:51] Xformers is not installed correctly. If you want to use memory_efficient_attention to accelerate training use the following command to install Xformers pip install xformers. Loading checkpoint shards: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [01:42<00:00, 51.31s/it] [12/05/2023-07:29:34] [TRT-LLM] [I] HF Baichuan v2_7b loaded. Total time: 00:01:53 [12/05/2023-07:29:34] [TRT-LLM] [I] Loading weights from HF Baichuan v2_7b... Killed

Kevinddddddd avatar Dec 05 '23 07:12 Kevinddddddd