bjornrun/tgi-gaudi-fixed-llama3.1

Temporary repo for tgi-gaudi

Python

1

4 commits

updated Aug 14, 2024

See the code

README

Text Generation Inference on Habana Gaudi

Table of contents

Running TGI on Gaudi

To use 🤗 text-generation-inference on Habana Gaudi/Gaudi2, follow these steps:

  1. Pull the official Docker image with:
    docker pull ghcr.io/huggingface/tgi-gaudi:2.0.1
    

[!NOTE] Alternatively, you can build the Docker image using the Dockerfile located in this folder with:

docker build -t tgi_gaudi .
  1. Launch a local server instance:

    i. On 1 Gaudi/Gaudi2 card

    model=meta-llama/Llama-2-7b-hf
    volume=$PWD/data # share a volume with the Docker container to avoid downloading weights every run
    
    docker run -p 8080:80 -v $volume:/data --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host ghcr.io/huggingface/tgi-gaudi:2.0.1 --model-id $model --max-input-tokens 1024 --max-total-tokens 2048
    

    For gated models such as LLama or StarCoder, you will have to pass -e HUGGING_FACE_HUB_TOKEN=<token> to the docker run command above with a valid Hugging Face Hub read token.

    ii. On 1 Gaudi/Gaudi2 card using pytorch eager mode with torch compile:

    model=meta-llama/Llama-2-7b-hf
    volume=$PWD/data # share a volume with the Docker container to avoid downloading weights every run
    
    docker run -p 8080:80 -v $volume:/data --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e PT_HPU_LAZY_MODE=0 -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host ghcr.io/huggingface/tgi-gaudi:2.0.1 --model-id $model --max-input-tokens 1024 --max-total-tokens 2048
    

    iii. On 8 Gaudi/Gaudi2 cards:

    model=meta-llama/Llama-2-70b-hf
    volume=$PWD/data # share a volume with the Docker container to avoid downloading weights every run
    
    docker run -p 8080:80 -v $volume:/data --runtime=habana -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host ghcr.io/huggingface/tgi-gaudi:2.0.1 --model-id $model --sharded true --num-shard 8 --max-input-tokens 1024 --max-total-tokens 2048
    
  2. You can then send a simple request:

    curl 127.0.0.1:8080/generate \
      -X POST \
      -d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":32}}' \
      -H 'Content-Type: application/json'
    
  3. To run static benchmark test, please refer to TGI's benchmark tool.

    To run it on the same machine, you can do the following:

    • docker exec -it <docker name> bash , pick the docker started from step 2 using docker ps
    • text-generation-benchmark -t <model-id> , pass the model-id from docker run command
    • after the completion of tests, hit ctrl+c to see the performance data summary.
  4. To run continuous batching test, please refer to examples.

Adjusting TGI parameters

Maximum sequence length is controlled by two arguments:

  • --max-input-tokens is the maximum possible input prompt length. Default value is 4095.
  • --max-total-tokens is the maximum possible total length of the sequence (input and output). Default value is 4096.

Maximum batch size is controlled by two arguments:

  • For prefill operation, please set --max-prefill-total-tokens as bs * max-input-tokens, where bs is your expected maximum prefill batch size.
  • For decode operation, please set --max-batch-total-tokens as bs * max-total-tokens, where bs is your expected maximum decode batch size.
  • Please note that batch size will be always padded to the nearest multiplication of BATCH_BUCKET_SIZE and PREFILL_BATCH_BUCKET_SIZE.

To ensure greatest performance results, at the begginging of each server run, warmup is performed. It's designed to cover major recompilations while using HPU Graphs. It creates queries with all possible input shapes, based on provided parameters (described in this section) and runs basic TGI operations on them (prefill, decode, concatenate).

Except those already mentioned, there are other parameters that need to be properly adjusted to improve performance or memory usage:

  • PAD_SEQUENCE_TO_MULTIPLE_OF determines sizes of input legnth buckets. Since warmup creates several graphs for each bucket, it's important to adjust that value proportionally to input sequence length. Otherwise, some out of memory issues can be observed.
  • ENABLE_HPU_GRAPH enables HPU graphs usage, which is crucial for performance results. Recommended value to keep is true .

For more information and documentation about Text Generation Inference, checkout the README of the original repo.

Running TGI with FP8 precision

TGI supports FP8 precision runs within the limits provided by Habana Quantization Toolkit. Models with FP8 can be ran by properly setting QUANT_CONFIG environment variable. Detailed instruction on how to use that variable can be found in Optimum Habana FP8 guide. Summarising that instruction in TGI cases:

  1. Measure quantization statistics of requested model by using Optimum Habana measurement script
  2. Run requested model in TGI with proper QUANT_CONFIG setting - e.g. -e QUANT_CONFIG=./quantization_config/maxabs_quant.json.

[!NOTE] Only models pointed in supported configurations are guaranteed to work with FP8

Additional hints to quantize model for TGI when using run_lm_eval.py:

  • use --limit_hpu_graphs flag to save memory
  • try to model your use case situation by adjusting --batch_size , --max_new_tokens 512 and --max_input_tokens 512; in case of memory issues, lower those values
  • use dataset/tasks suitable for your use case (see --help for defining tasks/datasets)

Currently supported configurations

Not all features of TGI are currently supported as this is still a work in progress. Currently supported and validated configurations (other configurations are not guaranted to work or ensure reasonable performance):

LLama 7b BF16 on 1 Gaudi2 card

model=meta-llama/Llama-2-7b-chat-hf
hf_token=YOUR_ACCESS_TOKEN   # Llama2 is a gated model and requires a special access token
volume=$PWD/data   # share a volume with the Docker container to avoid downloading weights every run

docker run -p 8080:80 \
   --runtime=habana \
   -v $volume:/data \
   -e HABANA_VISIBLE_DEVICES=all \
   -e OMPI_MCA_btl_vader_single_copy_mechanism=none \
   -e HF_HUB_ENABLE_HF_TRANSFER=1 \
   -e HUGGING_FACE_HUB_TOKEN=$hf_token \
   -e PREFILL_BATCH_BUCKET_SIZE=1 \
   -e BATCH_BUCKET_SIZE=16 \
   -e PAD_SEQUENCE_TO_MULTIPLE_OF=128 \
   --cap-add=sys_nice \
   --ipc=host \
   ghcr.io/huggingface/tgi-gaudi:2.0.1 \
   --model-id $model \
   --max-input-tokens 1024 \
   --max-batch-prefill-tokens 4096 \
   --max-total-tokens 2048 \
   --max-batch-size 16

LLama 7b FP8 on 1 Gaudi2 card

model=meta-llama/Llama-2-7b-chat-hf
hf_token=YOUR_ACCESS_TOKEN   # Llama2 is a gated model and requires a special access token
volume=$PWD/data   # share a volume with the Docker container to avoid downloading weights every run

docker run -p 8080:80 \
   --runtime=habana \
   -v $volume:/data \
   -v $PWD/quantization_config:/usr/src/quantization_config \
   -v $PWD/hqt_output:/usr/src/hqt_output \
   -e HABANA_VISIBLE_DEVICES=all \
   -e OMPI_MCA_btl_vader_single_copy_mechanism=none \
   -e HF_HUB_ENABLE_HF_TRANSFER=1 \
   -e HUGGING_FACE_HUB_TOKEN=$hf_token \
   -e PREFILL_BATCH_BUCKET_SIZE=1 \
   -e BATCH_BUCKET_SIZE=64 \
   -e PAD_SEQUENCE_TO_MULTIPLE_OF=128 \
   -e QUANT_CONFIG=./quantization_config/maxabs_quant.json \
   --cap-add=sys_nice \
   --ipc=host \
   ghcr.io/huggingface/tgi-gaudi:2.0.1 \
   --model-id $model \
   --max-input-tokens 1024 \
   --max-batch-prefill-tokens 4096 \
   --max-total-tokens 2048 \
   --max-batch-size 64

LLama 70b BF16 on 8 Gaudi2 card

model=meta-llama/Llama-2-70b-chat-hf
hf_token=YOUR_ACCESS_TOKEN   # Llama2 is a gated model and requires a special access token
volume=$PWD/data   # share a volume with the Docker container to avoid downloading weights every run

docker run -p 8080:80 \
   --runtime=habana \
   -v $volume:/data \
   -e HABANA_VISIBLE_DEVICES=all \
   -e OMPI_MCA_btl_vader_single_copy_mechanism=none \
   -e HF_HUB_ENABLE_HF_TRANSFER=1 \
   -e HUGGING_FACE_HUB_TOKEN=$hf_token \
   -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true \
   -e PREFILL_BATCH_BUCKET_SIZE=1 \
   -e BATCH_BUCKET_SIZE=256 \
   -e PAD_SEQUENCE_TO_MULTIPLE_OF=128 \
   --cap-add=sys_nice \
   --ipc=host \
   ghcr.io/huggingface/tgi-gaudi:2.0.1 \
   --model-id $model \
   --max-input-tokens 1024 \
   --max-batch-prefill-tokens 16384 \
   --max-total-tokens 2048 \
   --max-batch-size 256 \
   --max-concurrent-requests 400 \
   --sharded true \
   --num-shard 8

LLama 70b FP8 on 8 Gaudi2 card

model=meta-llama/Llama-2-70b-chat-hf
hf_token=YOUR_ACCESS_TOKEN   # Llama2 is a gated model and requires a special access token
volume=$PWD/data   # share a volume with the Docker container to avoid downloading weights every run

docker run -p 8080:80 \
   --runtime=habana \
   -v $volume:/data \
   -v $PWD/quantization_config:/usr/src/quantization_config \
   -v $PWD/hqt_output:/usr/src/hqt_output \
   -e HABANA_VISIBLE_DEVICES=all \
   -e OMPI_MCA_btl_vader_single_copy_mechanism=none \
   -e HF_HUB_ENABLE_HF_TRANSFER=1 \
   -e HUGGING_FACE_HUB_TOKEN=$hf_token \
   -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true \
   -e PREFILL_BATCH_BUCKET_SIZE=1 \
   -e BATCH_BUCKET_SIZE=512 \
   -e PAD_SEQUENCE_TO_MULTIPLE_OF=128 \
   -e QUANT_CONFIG=./quantization_config/maxabs_quant.json \
   --cap-add=sys_nice \
   --ipc=host \
   ghcr.io/huggingface/tgi-gaudi:2.0.1 \
   --model-id $model \
   --max-input-tokens 1024 \
   --max-batch-prefill-tokens 16384 \
   --max-total-tokens 2048 \
   --max-batch-size 512 \
   --max-concurrent-requests 700 \
   --sharded true \
   --num-shard 8

Please note that the model warmup can take several minutes, especially for FP8 configs. To minimize this time in consecutive runs, please refer to Disk Caching Eviction Policy.

Other sequence lengths can be used with proportionally decreased/increased batch size (the higher sequence length, the lower batch size). Support for other models from Optimum Habana will be added successively.

Environment variables

NameValue(s)DefaultDescriptionUsage
ENABLE_HPU_GRAPHTrue/FalseTrueEnable hpu graph or notadd -e in docker run command
LIMIT_HPU_GRAPHTrue/FalseFalseSkip HPU graph usage for prefill to save memory, set to True for large sequence/decoding lengths(e.g. 300/212)add -e in docker run command
BATCH_BUCKET_SIZEinteger8Batch size for decode operation will be rounded to the nearest multiple of this number. This limits the number of cached graphsadd -e in docker run command
PREFILL_BATCH_BUCKET_SIZEinteger4Batch size for prefill operation will be rounded to the nearest multiple of this number. This limits the number of cached graphsadd -e in docker run command
PAD_SEQUENCE_TO_MULTIPLE_OFinteger128For prefill operation, sequences will be padded to a multiple of provided value.add -e in docker run command
SKIP_TOKENIZER_IN_TGITrue/FalseFalseSkip tokenizer for input/output processingadd -e in docker run command
WARMUP_ENABLEDTrue/FalseTrueEnable warmup during server initialization to recompile all graphs. This can increase TGI setup time.add -e in docker run command
QUEUE_THRESHOLD_MSinteger120Controls the threshold beyond which the request are considered overdue and handled with priority. Shorter requests are prioritized otherwise.add -e in docker run command
USE_FLASH_ATTENTIONTrue/FalseFalseWhether to enable Habana Flash Attention, provided that the model supports it. Currently only llama and mistral supports this feature. Please refer to https://docs.habana.ai/en/latest/PyTorch/Model_Optimization_PyTorch/Optimization_in_PyTorch_Models.html?highlight=fusedsdpa#using-fused-scaled-dot-product-attention-fusedsdpa
FLASH_ATTENTION_RECOMPUTETrue/FalseFalseWhether to enable Habana Flash Attention in recompute mode on first token generation.

Profiler

To collect performance profiling, please set below environment variables:

NameValue(s)DefaultDescriptionUsage
PROF_WAITSTEPinteger0Control profile wait stepsadd -e in docker run command
PROF_WARMUPSTEPinteger0Control profile warmup stepsadd -e in docker run command
PROF_STEPinteger0Enable/disable profile, control profile active stepsadd -e in docker run command
PROF_PATHstring/tmp/hpu_profileDefine profile folderadd -e in docker run command
PROF_RANKSstring0Comma-separated list of ranks to profileadd -e in docker run command
PROF_RECORD_SHAPESTrue/FalseFalseControl record_shapes option in the profileradd -e in docker run command

The license to use TGI on Habana Gaudi is the one of TGI: https://github.com/huggingface/text-generation-inference/blob/main/LICENSE

Please reach out to api-enterprise@huggingface.co if you have any question.

Contributors

bjornrun

4 commits

bjornrun/tgi-gaudi-fixed-llama3.1

Temporary repo for tgi-gaudi

Python

1

4 commits

updated Aug 14, 2024

See the code

README

Text Generation Inference on Habana Gaudi

Table of contents

Running TGI on Gaudi

To use 🤗 text-generation-inference on Habana Gaudi/Gaudi2, follow these steps:

  1. Pull the official Docker image with:
    docker pull ghcr.io/huggingface/tgi-gaudi:2.0.1
    

[!NOTE] Alternatively, you can build the Docker image using the Dockerfile located in this folder with:

docker build -t tgi_gaudi .
  1. Launch a local server instance:

    i. On 1 Gaudi/Gaudi2 card

    model=meta-llama/Llama-2-7b-hf
    volume=$PWD/data # share a volume with the Docker container to avoid downloading weights every run
    
    docker run -p 8080:80 -v $volume:/data --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host ghcr.io/huggingface/tgi-gaudi:2.0.1 --model-id $model --max-input-tokens 1024 --max-total-tokens 2048
    

    For gated models such as LLama or StarCoder, you will have to pass -e HUGGING_FACE_HUB_TOKEN=<token> to the docker run command above with a valid Hugging Face Hub read token.

    ii. On 1 Gaudi/Gaudi2 card using pytorch eager mode with torch compile:

    model=meta-llama/Llama-2-7b-hf
    volume=$PWD/data # share a volume with the Docker container to avoid downloading weights every run
    
    docker run -p 8080:80 -v $volume:/data --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e PT_HPU_LAZY_MODE=0 -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host ghcr.io/huggingface/tgi-gaudi:2.0.1 --model-id $model --max-input-tokens 1024 --max-total-tokens 2048
    

    iii. On 8 Gaudi/Gaudi2 cards:

    model=meta-llama/Llama-2-70b-hf
    volume=$PWD/data # share a volume with the Docker container to avoid downloading weights every run
    
    docker run -p 8080:80 -v $volume:/data --runtime=habana -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host ghcr.io/huggingface/tgi-gaudi:2.0.1 --model-id $model --sharded true --num-shard 8 --max-input-tokens 1024 --max-total-tokens 2048
    
  2. You can then send a simple request:

    curl 127.0.0.1:8080/generate \
      -X POST \
      -d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":32}}' \
      -H 'Content-Type: application/json'
    
  3. To run static benchmark test, please refer to TGI's benchmark tool.

    To run it on the same machine, you can do the following:

    • docker exec -it <docker name> bash , pick the docker started from step 2 using docker ps
    • text-generation-benchmark -t <model-id> , pass the model-id from docker run command
    • after the completion of tests, hit ctrl+c to see the performance data summary.
  4. To run continuous batching test, please refer to examples.

Adjusting TGI parameters

Maximum sequence length is controlled by two arguments:

  • --max-input-tokens is the maximum possible input prompt length. Default value is 4095.
  • --max-total-tokens is the maximum possible total length of the sequence (input and output). Default value is 4096.

Maximum batch size is controlled by two arguments:

  • For prefill operation, please set --max-prefill-total-tokens as bs * max-input-tokens, where bs is your expected maximum prefill batch size.
  • For decode operation, please set --max-batch-total-tokens as bs * max-total-tokens, where bs is your expected maximum decode batch size.
  • Please note that batch size will be always padded to the nearest multiplication of BATCH_BUCKET_SIZE and PREFILL_BATCH_BUCKET_SIZE.

To ensure greatest performance results, at the begginging of each server run, warmup is performed. It's designed to cover major recompilations while using HPU Graphs. It creates queries with all possible input shapes, based on provided parameters (described in this section) and runs basic TGI operations on them (prefill, decode, concatenate).

Except those already mentioned, there are other parameters that need to be properly adjusted to improve performance or memory usage:

  • PAD_SEQUENCE_TO_MULTIPLE_OF determines sizes of input legnth buckets. Since warmup creates several graphs for each bucket, it's important to adjust that value proportionally to input sequence length. Otherwise, some out of memory issues can be observed.
  • ENABLE_HPU_GRAPH enables HPU graphs usage, which is crucial for performance results. Recommended value to keep is true .

For more information and documentation about Text Generation Inference, checkout the README of the original repo.

Running TGI with FP8 precision

TGI supports FP8 precision runs within the limits provided by Habana Quantization Toolkit. Models with FP8 can be ran by properly setting QUANT_CONFIG environment variable. Detailed instruction on how to use that variable can be found in Optimum Habana FP8 guide. Summarising that instruction in TGI cases:

  1. Measure quantization statistics of requested model by using Optimum Habana measurement script
  2. Run requested model in TGI with proper QUANT_CONFIG setting - e.g. -e QUANT_CONFIG=./quantization_config/maxabs_quant.json.

[!NOTE] Only models pointed in supported configurations are guaranteed to work with FP8

Additional hints to quantize model for TGI when using run_lm_eval.py:

  • use --limit_hpu_graphs flag to save memory
  • try to model your use case situation by adjusting --batch_size , --max_new_tokens 512 and --max_input_tokens 512; in case of memory issues, lower those values
  • use dataset/tasks suitable for your use case (see --help for defining tasks/datasets)

Currently supported configurations

Not all features of TGI are currently supported as this is still a work in progress. Currently supported and validated configurations (other configurations are not guaranted to work or ensure reasonable performance):

LLama 7b BF16 on 1 Gaudi2 card

model=meta-llama/Llama-2-7b-chat-hf
hf_token=YOUR_ACCESS_TOKEN   # Llama2 is a gated model and requires a special access token
volume=$PWD/data   # share a volume with the Docker container to avoid downloading weights every run

docker run -p 8080:80 \
   --runtime=habana \
   -v $volume:/data \
   -e HABANA_VISIBLE_DEVICES=all \
   -e OMPI_MCA_btl_vader_single_copy_mechanism=none \
   -e HF_HUB_ENABLE_HF_TRANSFER=1 \
   -e HUGGING_FACE_HUB_TOKEN=$hf_token \
   -e PREFILL_BATCH_BUCKET_SIZE=1 \
   -e BATCH_BUCKET_SIZE=16 \
   -e PAD_SEQUENCE_TO_MULTIPLE_OF=128 \
   --cap-add=sys_nice \
   --ipc=host \
   ghcr.io/huggingface/tgi-gaudi:2.0.1 \
   --model-id $model \
   --max-input-tokens 1024 \
   --max-batch-prefill-tokens 4096 \
   --max-total-tokens 2048 \
   --max-batch-size 16

LLama 7b FP8 on 1 Gaudi2 card

model=meta-llama/Llama-2-7b-chat-hf
hf_token=YOUR_ACCESS_TOKEN   # Llama2 is a gated model and requires a special access token
volume=$PWD/data   # share a volume with the Docker container to avoid downloading weights every run

docker run -p 8080:80 \
   --runtime=habana \
   -v $volume:/data \
   -v $PWD/quantization_config:/usr/src/quantization_config \
   -v $PWD/hqt_output:/usr/src/hqt_output \
   -e HABANA_VISIBLE_DEVICES=all \
   -e OMPI_MCA_btl_vader_single_copy_mechanism=none \
   -e HF_HUB_ENABLE_HF_TRANSFER=1 \
   -e HUGGING_FACE_HUB_TOKEN=$hf_token \
   -e PREFILL_BATCH_BUCKET_SIZE=1 \
   -e BATCH_BUCKET_SIZE=64 \
   -e PAD_SEQUENCE_TO_MULTIPLE_OF=128 \
   -e QUANT_CONFIG=./quantization_config/maxabs_quant.json \
   --cap-add=sys_nice \
   --ipc=host \
   ghcr.io/huggingface/tgi-gaudi:2.0.1 \
   --model-id $model \
   --max-input-tokens 1024 \
   --max-batch-prefill-tokens 4096 \
   --max-total-tokens 2048 \
   --max-batch-size 64

LLama 70b BF16 on 8 Gaudi2 card

model=meta-llama/Llama-2-70b-chat-hf
hf_token=YOUR_ACCESS_TOKEN   # Llama2 is a gated model and requires a special access token
volume=$PWD/data   # share a volume with the Docker container to avoid downloading weights every run

docker run -p 8080:80 \
   --runtime=habana \
   -v $volume:/data \
   -e HABANA_VISIBLE_DEVICES=all \
   -e OMPI_MCA_btl_vader_single_copy_mechanism=none \
   -e HF_HUB_ENABLE_HF_TRANSFER=1 \
   -e HUGGING_FACE_HUB_TOKEN=$hf_token \
   -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true \
   -e PREFILL_BATCH_BUCKET_SIZE=1 \
   -e BATCH_BUCKET_SIZE=256 \
   -e PAD_SEQUENCE_TO_MULTIPLE_OF=128 \
   --cap-add=sys_nice \
   --ipc=host \
   ghcr.io/huggingface/tgi-gaudi:2.0.1 \
   --model-id $model \
   --max-input-tokens 1024 \
   --max-batch-prefill-tokens 16384 \
   --max-total-tokens 2048 \
   --max-batch-size 256 \
   --max-concurrent-requests 400 \
   --sharded true \
   --num-shard 8

LLama 70b FP8 on 8 Gaudi2 card

model=meta-llama/Llama-2-70b-chat-hf
hf_token=YOUR_ACCESS_TOKEN   # Llama2 is a gated model and requires a special access token
volume=$PWD/data   # share a volume with the Docker container to avoid downloading weights every run

docker run -p 8080:80 \
   --runtime=habana \
   -v $volume:/data \
   -v $PWD/quantization_config:/usr/src/quantization_config \
   -v $PWD/hqt_output:/usr/src/hqt_output \
   -e HABANA_VISIBLE_DEVICES=all \
   -e OMPI_MCA_btl_vader_single_copy_mechanism=none \
   -e HF_HUB_ENABLE_HF_TRANSFER=1 \
   -e HUGGING_FACE_HUB_TOKEN=$hf_token \
   -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true \
   -e PREFILL_BATCH_BUCKET_SIZE=1 \
   -e BATCH_BUCKET_SIZE=512 \
   -e PAD_SEQUENCE_TO_MULTIPLE_OF=128 \
   -e QUANT_CONFIG=./quantization_config/maxabs_quant.json \
   --cap-add=sys_nice \
   --ipc=host \
   ghcr.io/huggingface/tgi-gaudi:2.0.1 \
   --model-id $model \
   --max-input-tokens 1024 \
   --max-batch-prefill-tokens 16384 \
   --max-total-tokens 2048 \
   --max-batch-size 512 \
   --max-concurrent-requests 700 \
   --sharded true \
   --num-shard 8

Please note that the model warmup can take several minutes, especially for FP8 configs. To minimize this time in consecutive runs, please refer to Disk Caching Eviction Policy.

Other sequence lengths can be used with proportionally decreased/increased batch size (the higher sequence length, the lower batch size). Support for other models from Optimum Habana will be added successively.

Environment variables

NameValue(s)DefaultDescriptionUsage
ENABLE_HPU_GRAPHTrue/FalseTrueEnable hpu graph or notadd -e in docker run command
LIMIT_HPU_GRAPHTrue/FalseFalseSkip HPU graph usage for prefill to save memory, set to True for large sequence/decoding lengths(e.g. 300/212)add -e in docker run command
BATCH_BUCKET_SIZEinteger8Batch size for decode operation will be rounded to the nearest multiple of this number. This limits the number of cached graphsadd -e in docker run command
PREFILL_BATCH_BUCKET_SIZEinteger4Batch size for prefill operation will be rounded to the nearest multiple of this number. This limits the number of cached graphsadd -e in docker run command
PAD_SEQUENCE_TO_MULTIPLE_OFinteger128For prefill operation, sequences will be padded to a multiple of provided value.add -e in docker run command
SKIP_TOKENIZER_IN_TGITrue/FalseFalseSkip tokenizer for input/output processingadd -e in docker run command
WARMUP_ENABLEDTrue/FalseTrueEnable warmup during server initialization to recompile all graphs. This can increase TGI setup time.add -e in docker run command
QUEUE_THRESHOLD_MSinteger120Controls the threshold beyond which the request are considered overdue and handled with priority. Shorter requests are prioritized otherwise.add -e in docker run command
USE_FLASH_ATTENTIONTrue/FalseFalseWhether to enable Habana Flash Attention, provided that the model supports it. Currently only llama and mistral supports this feature. Please refer to https://docs.habana.ai/en/latest/PyTorch/Model_Optimization_PyTorch/Optimization_in_PyTorch_Models.html?highlight=fusedsdpa#using-fused-scaled-dot-product-attention-fusedsdpa
FLASH_ATTENTION_RECOMPUTETrue/FalseFalseWhether to enable Habana Flash Attention in recompute mode on first token generation.

Profiler

To collect performance profiling, please set below environment variables:

NameValue(s)DefaultDescriptionUsage
PROF_WAITSTEPinteger0Control profile wait stepsadd -e in docker run command
PROF_WARMUPSTEPinteger0Control profile warmup stepsadd -e in docker run command
PROF_STEPinteger0Enable/disable profile, control profile active stepsadd -e in docker run command
PROF_PATHstring/tmp/hpu_profileDefine profile folderadd -e in docker run command
PROF_RANKSstring0Comma-separated list of ranks to profileadd -e in docker run command
PROF_RECORD_SHAPESTrue/FalseFalseControl record_shapes option in the profileradd -e in docker run command

The license to use TGI on Habana Gaudi is the one of TGI: https://github.com/huggingface/text-generation-inference/blob/main/LICENSE

Please reach out to api-enterprise@huggingface.co if you have any question.

Contributors

bjornrun

4 commits

Languages

Python

90.0%

Rust

5.9%

Cuda

2.2%

MDX

1.2%