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
- 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
4th inference in a row does not work for Falcon7B in 8 or 4 bit
I built a tool that generates inferences in a loop with Falcon 7B in 16/8/4 bit. Weirdly, Falcon generates the first 3 inferences rapidly and then it blocks and never returns the 4th inference when I use it in 8 or 4 bit. Plus, the problem persists when I change the set of instructions I use to generate inferences.
Here is the code I use to load the model and generate inferences:
def load_falcon(weight_encoding):
model_path = "/falcon-7b-instruct"
eight_bit = weight_encoding == "8-bit"
four_bit = weight_encoding == "4-bit"
#creating a model
fmodel = AutoModelForCausalLM.from_pretrained(
model_path,
load_in_8bit = eight_bit,
load_in_4bit = four_bit,
trust_remote_code = True,
torch_dtype= torch.float16,
device_map = "auto")
fmodel.eval()
# fmodel.to(device)
tokenizer = AutoTokenizer.from_pretrained(model_path)
gen_text = transformers.pipeline(
model=fmodel,
tokenizer=tokenizer,
task='text-generation',
return_full_text=False,
max_length=5000,
temperature=0.1,
top_p=0.75, #select from top tokens whose probability adds up to 15%
top_k=40, #selecting from top 0 tokens
repetition_penalty=1.9, #without a penalty, output starts to repeat
do_sample=True,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id
)
return gen_text, tokenizer
def falcon_inference(instruction, gen_text):
response = gen_text(instruction)
texts = [ seq['generated_text'] for seq in response]
text = '\n'.join(texts)
return text
Configuration:
CUDA Version: 12.1
NVIDIA GeForce RTX 4090 (24 GO VRAM)
I have the latest versions of bitsandbytes (0.39.0), transformers (4.31.0.dev0) and accelerate (0.21.0.dev0).
Thank you for your help !
I am also having a similar issue where the 8-bit Falcon-7b-instruct model will not generate anything. Even the 'poem about Valencia' example from their article (https://huggingface.co/blog/falcon#inference) does not work. There is no error code, it just returns the prompt with no generated text. The regular Falcon-7b-instruct model works fine for me but is very slow.
I am also having a similar issue where the 8-bit Falcon-7b-instruct model will not generate anything. Even the 'poem about Valencia' example from their article (https://huggingface.co/blog/falcon#inference) does not work. There is no error code, it just returns the prompt with no generated text. The regular Falcon-7b-instruct model works fine for me but is very slow.
My issue was with the 8-bit model which was loaded from locally saved files, when I load it from the hub it works fine. There must be some issue with how Huggingface saves the 8-bit model.