Text Generation
Transformers
PyTorch
Core ML
Safetensors
English
falcon
conversational
custom_code
Eval Results
text-generation-inference
Instructions to use tiiuae/falcon-7b-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiiuae/falcon-7b-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b-instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-7b-instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiiuae/falcon-7b-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiiuae/falcon-7b-instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiiuae/falcon-7b-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tiiuae/falcon-7b-instruct
- SGLang
How to use tiiuae/falcon-7b-instruct with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "tiiuae/falcon-7b-instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiiuae/falcon-7b-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "tiiuae/falcon-7b-instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiiuae/falcon-7b-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tiiuae/falcon-7b-instruct with Docker Model Runner:
docker model run hf.co/tiiuae/falcon-7b-instruct
Use input attention mask instead of casual mask in attention
#74
by CyberZHG - opened
- modelling_RW.py +2 -2
modelling_RW.py
CHANGED
|
@@ -271,13 +271,14 @@ class Attention(nn.Module):
|
|
| 271 |
else:
|
| 272 |
present = None
|
| 273 |
|
|
|
|
| 274 |
if alibi is None:
|
| 275 |
query_layer_ = query_layer.reshape(batch_size, self.num_heads, -1, self.head_dim)
|
| 276 |
key_layer_ = key_layer.reshape(batch_size, self.num_kv, -1, self.head_dim)
|
| 277 |
value_layer_ = value_layer.reshape(batch_size, self.num_kv, -1, self.head_dim)
|
| 278 |
|
| 279 |
attn_output = F.scaled_dot_product_attention(
|
| 280 |
-
query_layer_, key_layer_, value_layer_,
|
| 281 |
)
|
| 282 |
|
| 283 |
x = attn_output.view(batch_size, self.num_heads, q_length, self.head_dim)
|
|
@@ -290,7 +291,6 @@ class Attention(nn.Module):
|
|
| 290 |
assert not output_attentions # not supported.
|
| 291 |
return outputs
|
| 292 |
else:
|
| 293 |
-
attention_mask_float = (attention_mask * 1.0).masked_fill(attention_mask, -1e9).to(torch.bfloat16)
|
| 294 |
matmul_result = query_layer @ key_layer.transpose(-1, -2)
|
| 295 |
|
| 296 |
# change view to [batch_size, num_heads, q_length, kv_length]
|
|
|
|
| 271 |
else:
|
| 272 |
present = None
|
| 273 |
|
| 274 |
+
attention_mask_float = (attention_mask * 1.0).masked_fill(attention_mask, -1e9).to(query_layer.dtype)
|
| 275 |
if alibi is None:
|
| 276 |
query_layer_ = query_layer.reshape(batch_size, self.num_heads, -1, self.head_dim)
|
| 277 |
key_layer_ = key_layer.reshape(batch_size, self.num_kv, -1, self.head_dim)
|
| 278 |
value_layer_ = value_layer.reshape(batch_size, self.num_kv, -1, self.head_dim)
|
| 279 |
|
| 280 |
attn_output = F.scaled_dot_product_attention(
|
| 281 |
+
query_layer_, key_layer_, value_layer_, attention_mask_float, 0.0, is_causal=False
|
| 282 |
)
|
| 283 |
|
| 284 |
x = attn_output.view(batch_size, self.num_heads, q_length, self.head_dim)
|
|
|
|
| 291 |
assert not output_attentions # not supported.
|
| 292 |
return outputs
|
| 293 |
else:
|
|
|
|
| 294 |
matmul_result = query_layer @ key_layer.transpose(-1, -2)
|
| 295 |
|
| 296 |
# change view to [batch_size, num_heads, q_length, kv_length]
|