Instructions to use tiiuae/falcon-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiiuae/falcon-7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tiiuae/falcon-7b", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-7b", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiiuae/falcon-7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiiuae/falcon-7b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiiuae/falcon-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/tiiuae/falcon-7b
- SGLang
How to use tiiuae/falcon-7b 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" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiiuae/falcon-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiiuae/falcon-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use tiiuae/falcon-7b with Docker Model Runner:
docker model run hf.co/tiiuae/falcon-7b
Question answering task with falcon model fails with "TypeError: forward() got an unexpected keyword argument 'token_type_ids'"
Hey all!
I really wanted to try out one of Falcon models with question answering task so I followed this tutorial in the docs: Question answering (huggingface.co) since on the top of it it says it's applicable with Falcon models.
So I reused the code and switch distilbert model to falcon-7b and my code fails this error message:
TypeError: forward() got an unexpected keyword argument 'token_type_ids'
My code looks like this:
from transformers import AutoModelForQuestionAnswering
model_name = "tiiuae/falcon-7b"
model = AutoModelForQuestionAnswering.from_pretrained(
pretrained_model_name_or_path=model_name,
cache_dir="/mnt/tmp",
trust_remote_code=True
)
from transformers import AutoTokenizer, PretrainedConfig
tokenizer = AutoTokenizer.from_pretrained(
pretrained_model_name_or_path=model_name,
cache_dir="/mnt/tmp",
trust_remote_code=True,
return_tensors="pt",
)
from transformers import pipeline
question_answerer = pipeline(
"question-answering",
model=model,
tokenizer=tokenizer
)
question_answerer(question=question, context=context)
Code fails on the very last step when I try to run inferencing on the pipeline. Any ideas?
I'm not sure you would be able to use HF pipeline for Falcon for this kind of QA since Falcon is a decoder-only model not expected to produce start/end logits. Do you get any errors when you run?
model = AutoModelForQuestionAnswering.from_pretrained(
pretrained_model_name_or_path=model_name,
cache_dir="/mnt/tmp",
trust_remote_code=True
)