# TGI and turn off Flash Attention v2

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftgi-and-turn-off-flash-attention-v2%2F100490%3E%5C
**Category:** Intermediate\
**Created:** [August 1, 2024, 11:45pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftgi-and-turn-off-flash-attention-v2%2F100490 "2024-08-01T23:45:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkettrey](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rkettrey/32/30076_2.png) [@rkettrey](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frkettrey)%5C
**Post date:** [August 1, 2024, 11:45pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftgi-and-turn-off-flash-attention-v2%2F100490%2F1 "2024-08-01T23:45:02Z")

</div>

We are running our own TGI container and trying to boot Mistral Instruct. It’s dieing trying to utilize Flash Attention 2. I know this is because I am using a T4 GPU, but for the life of me I can’t figure out how to tell TGI not to use Flash Attention 2.

Somehow, when we deploy it through HuggingFace on an AWS T4, it knows. Looking at the logs for HF deployment I see:

- 2024-08-01T01:48:41.507+00:00 {“timestamp”:“2024-08-01T01:48:41.507739Z”,“level”:“INFO”,“fields”:{“message”:“Successfully downloaded weights.”},“target”:“text\_generation\_launcher”,“span”:{“name”:“download”},“spans”:[{“name”:“download”}]}
- 2024-08-01T01:48:41.507+00:00 {“timestamp”:“2024-08-01T01:48:41.507904Z”,“level”:“INFO”,“fields”:{“message”:“Starting shard”},“target”:“text\_generation\_launcher”,“span”:{“rank”:0,“name”:“shard-manager”},“spans”:[{“rank”:0,“name”:“shard-manager”}]}
- 2024-08-01T01:48:41.507+00:00 {“timestamp”:“2024-08-01T01:48:41.507914Z”,“level”:“INFO”,“fields”:{“message”:“Starting shard”},“target”:“text\_generation\_launcher”,“span”:{“rank”:1,“name”:“shard-manager”},“spans”:[{“rank”:1,“name”:“shard-manager”}]}
- 2024-08-01T01:48:41.507+00:00 {“timestamp”:“2024-08-01T01:48:41.507952Z”,“level”:“INFO”,“fields”:{“message”:“Starting shard”},“target”:“text\_generation\_launcher”,“span”:{“rank”:2,“name”:“shard-manager”},“spans”:[{“rank”:2,“name”:“shard-manager”}]}
- 2024-08-01T01:48:41.508+00:00 {“timestamp”:“2024-08-01T01:48:41.507977Z”,“level”:“INFO”,“fields”:{“message”:“Starting shard”},“target”:“text\_generation\_launcher”,“span”:{“rank”:3,“name”:“shard-manager”},“spans”:[{“rank”:3,“name”:“shard-manager”}]}
- 2024-08-01T01:48:46.187+00:00 {“timestamp”:“2024-08-01T01:48:46.187088Z”,“level”:“WARN”,“fields”:{“message”:“Unable to use Flash Attention V2: GPU with CUDA capability 7 5 is not supported for Flash Attention V2\n”},“target”:“text\_generation\_launcher”}
- 2024-08-01T01:48:46.204+00:00 {“timestamp”:“2024-08-01T01:48:46.204816Z”,“level”:“WARN”,“fields”:{“message”:“Unable to use Flash Attention V2: GPU with CUDA capability 7 5 is not supported for Flash Attention V2\n”},“target”:“text\_generation\_launcher”}
- 2024-08-01T01:48:46.210+00:00 {“timestamp”:“2024-08-01T01:48:46.210281Z”,“level”:“WARN”,“fields”:{“message”:“Unable to use Flash Attention V2: GPU with CUDA capability 7 5 is not supported for Flash Attention V2\n”},“target”:“text\_generation\_launcher”}
- 2024-08-01T01:48:46.210+00:00 {“timestamp”:“2024-08-01T01:48:46.210527Z”,“level”:“WARN”,“fields”:{“message”:“Unable to use Flash Attention V2: GPU with CUDA capability 7 5 is not supported for Flash Attention V2\n”},“target”:“text\_generation\_launcher”}
- 2024-08-01T01:48:51.516+00:00 {“timestamp”:“2024-08-01T01:48:51.516157Z”,“level”:“INFO”,“fields”:{“message”:“Waiting for shard to be ready…”},“target”:“text\_generation\_launcher”,“span”:{“rank”:3,“name”:“shard-manager”},“spans”:[{“rank”:3,“name”:“shard-manager”}]}
- 2024-08-01T01:48:51.516+00:00 {“timestamp”:“2024-08-01T01:48:51.516157Z”,“level”:“INFO”,“fields”:{“message”:“Waiting for shard to be ready…”},“target”:“text\_generation\_launcher”,“span”:{“rank”:2,“name”:“shard-manager”},“spans”:[{“rank”:2,“name”:“shard-manager”}]}
- 2024-08-01T01:48:51.516+00:00 {“timestamp”:“2024-08-01T01:48:51.516157Z”,“level”:“INFO”,“fields”:{“message”:“Waiting for shard to be ready…”},“target”:“text\_generation\_launcher”,“span”:{“rank”:0,“name”:“shard-manager”},“spans”:[{“rank”:0,“name”:“shard-manager”}]}
- 2024-08-01T01:48:51.516+00:00 {“timestamp”:“2024-08-01T01:48:51.516157Z”,“level”:“INFO”,“fields”:{“message”:“Waiting for shard to be ready…”},“target”:“text\_generation\_launcher”,“span”:{“rank”:1,“name”:“shard-manager”},“spans”:[{“rank”:1,“name”:“shard-manager”}]}

Notice it correctly says it can’t use Flash Attention V2.

When we run this on our own T4 in our AWS, we don’t see this output. Instead, it bombs out trying to use Flash Attention v2 with:

Traceback (most recent call last):  
File “/opt/conda/bin/text-generation-server”, line 8, in   
sys.exit(app())  
File “/opt/conda/lib/python3.10/site-packages/typer/main.py”, line 311, in **call**  
return get\_command(self)(\*args, \*\*kwargs)  
File “/opt/conda/lib/python3.10/site-packages/click/core.py”, line 1157, in **call**  
return self.main(\*args, \*\*kwargs)  
File “/opt/conda/lib/python3.10/site-packages/typer/core.py”, line 778, in main  
return \_main(  
File “/opt/conda/lib/python3.10/site-packages/typer/core.py”, line 216, in \_main  
rv = self.invoke(ctx)  
File “/opt/conda/lib/python3.10/site-packages/click/core.py”, line 1688, in invoke  
return \_process\_result(sub\_ctx.command.invoke(sub\_ctx))  
File “/opt/conda/lib/python3.10/site-packages/click/core.py”, line 1434, in invoke  
return ctx.invoke(self.callback, \*\*ctx.params)  
File “/opt/conda/lib/python3.10/site-packages/click/core.py”, line 783, in invoke  
return \_\_callback(\*args, \*\*kwargs)  
File “/opt/conda/lib/python3.10/site-packages/typer/main.py”, line 683, in wrapper  
return callback(\*\*use\_params) # type: ignore  
File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/cli.py”, line 109, in serve  
server.serve(  
File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/server.py”, line 274, in serve  
asyncio.run(  
File “/opt/conda/lib/python3.10/asyncio/runners.py”, line 44, in run  
return loop.run\_until\_complete(main)  
File “/opt/conda/lib/python3.10/asyncio/base\_events.py”, line 636, in run\_until\_complete  
self.run\_forever()  
File “/opt/conda/lib/python3.10/asyncio/base\_events.py”, line 603, in run\_forever  
self.\_run\_once()  
File “/opt/conda/lib/python3.10/asyncio/base\_events.py”, line 1909, in \_run\_once  
handle.\_run()  
File “/opt/conda/lib/python3.10/asyncio/events.py”, line 80, in \_run  
self.\_context.run(self.\_callback, \*self.\_args)  
File “/opt/conda/lib/python3.10/site-packages/grpc\_interceptor/server.py”, line 165, in invoke\_intercept\_method  
return await self.intercept(

> File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/interceptor.py”, line 21, in intercept  
> return await response  
> File “/opt/conda/lib/python3.10/site-packages/opentelemetry/instrumentation/grpc/\_aio\_server.py”, line 120, in \_unary\_interceptor  
> raise error  
> File “/opt/conda/lib/python3.10/site-packages/opentelemetry/instrumentation/grpc/\_aio\_server.py”, line 111, in \_unary\_interceptor  
> return await behavior(request\_or\_iterator, context)  
> File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/server.py”, line 123, in Warmup  
> max\_supported\_total\_tokens = self.model.warmup(batch)  
> File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/models/flash\_causal\_lm.py”, line 1099, in warmup  
> \_, batch, \_ = self.generate\_token(batch)  
> File “/opt/conda/lib/python3.10/contextlib.py”, line 79, in inner  
> return func(\*args, \*\*kwds)  
> File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/models/flash\_causal\_lm.py”, line 1374, in generate\_token  
> out, speculative\_logits = self.forward(batch, adapter\_data)  
> File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/models/flash\_causal\_lm.py”, line 1299, in forward  
> logits, speculative\_logits = self.model.forward(  
> File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/models/custom\_modeling/flash\_mistral\_modeling.py”, line 516, in forward  
> hidden\_states = self.model(  
> File “/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1553, in \_wrapped\_call\_impl  
> return self.\_call\_impl(\*args, \*\*kwargs)  
> File “/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1562, in \_call\_impl  
> return forward\_call(\*args, \*\*kwargs)  
> File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/models/custom\_modeling/flash\_mistral\_modeling.py”, line 440, in forward  
> hidden\_states, residual = layer(  
> File “/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1553, in \_wrapped\_call\_impl  
> return self.\_call\_impl(\*args, \*\*kwargs)  
> File “/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1562, in \_call\_impl  
> return forward\_call(\*args, \*\*kwargs)  
> File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/models/custom\_modeling/flash\_mistral\_modeling.py”, line 365, in forward  
> attn\_output = self.self\_attn(  
> File “/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1553, in \_wrapped\_call\_impl  
> return self.\_call\_impl(\*args, \*\*kwargs)  
> File “/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1562, in \_call\_impl  
> return forward\_call(\*args, \*\*kwargs)  
> File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/models/custom\_modeling/flash\_mistral\_modeling.py”, line 218, in forward  
> attn\_output = attention(  
> File “/opt/conda/lib/python3.10/site-packages/text\_generation\_server/layers/attention/cuda.py”, line 221, in attention  
> return flash\_attn\_2\_cuda.varlen\_fwd(  
> RuntimeError: FlashAttention only supports Ampere GPUs or newer.

Does anyone know how I am supposed to tell TGI not to use Flash Attention v2, or how HF TGI deployment is getting just a warning and moving on?

---

<div class="post-metadata">

**Author:** ![mleiter](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mleiter](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmleiter)%5C
**Post date:** [August 6, 2024, 5:01am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftgi-and-turn-off-flash-attention-v2%2F100490%2F2 "2024-08-06T05:01:59Z")

</div>

I am also desperate for this. Hello fellow (likely) govcloud user.

---

<div class="post-metadata">

**Author:** ![rkettrey](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rkettrey/32/30076_2.png) [@rkettrey](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frkettrey)%5C
**Post date:** [August 13, 2024, 9:43pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftgi-and-turn-off-flash-attention-v2%2F100490%2F3 "2024-08-13T21:43:17Z")

</div>

FYI, they fixed this in the latest version of the image:

> **[Build software better, together](https://github.com/huggingface/text-generation-inference/pkgs/container/text-generation-inference)**
>
> GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.

---

<div class="post-metadata">

**Author:** ![sumanthnall](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@sumanthnall](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsumanthnall)%5C
**Post date:** [August 22, 2024, 9:42pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftgi-and-turn-off-flash-attention-v2%2F100490%2F4 "2024-08-22T21:42:22Z")

</div>

Hi @rkettrey, just to clarify your fix- the model you were trying to use actually didn’t need FlashAttention 2? And once you used this new version of the TGI, the SageMaker deployment script from the HuggingFace website no longer tried to utilize FlashAttention 2?

---

<div class="post-metadata">

**Author:** ![rkettrey](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rkettrey/32/30076_2.png) [@rkettrey](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frkettrey)%5C
**Post date:** [August 23, 2024, 11:54am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftgi-and-turn-off-flash-attention-v2%2F100490%2F5 "2024-08-23T11:54:36Z")

</div>

The model we were trying to use was using FlashAttention 2, but our chip we were booting on (T4) is not supported for FA2. Therefore, we were expecting the boot process to NOT try to use FA2 and it was trying to.

The updated TGI now properly detects and does not try to use FA2.
