Instructions to use tiiuae/falcon-mamba-7b-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiiuae/falcon-mamba-7b-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tiiuae/falcon-mamba-7b-instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-mamba-7b-instruct") model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-mamba-7b-instruct") 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-mamba-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-mamba-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-mamba-7b-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tiiuae/falcon-mamba-7b-instruct
- SGLang
How to use tiiuae/falcon-mamba-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-mamba-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-mamba-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-mamba-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-mamba-7b-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tiiuae/falcon-mamba-7b-instruct with Docker Model Runner:
docker model run hf.co/tiiuae/falcon-mamba-7b-instruct
The model doesn't load into Google colab with 4bit nf4 quantization. Why?
I just had a little query about this model. Is it not possible to load this model into a 15 GB VRAM of google colab? I have been trying to load it using the following quantization config:
# defining the config
nf4_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
)
But it gives cuda out of memory error every single time.
If it can't be loaded, then I'm confused as to why not? Since mistral-7B loads just fine and it's safetensors take a lot more memory than this model's. So by contrast I feel this model should load. But maybe it's because of something I have done wrong, that it doesn't load. I would really appreciate it if you resolved my query.
Here is the code which I have used to load and quantize it.
def generate_result(summary_model: str, config: BitsAndBytesConfig,
document_ids: Dict[str, str], device = "cpu") -> List[Dict[str, str]]:
# summarization models
summarizer = pipeline("summarization", model=summary_model,
device = device, quantization_config=config)
# zero-shot-classification models
docs = []
for document_name, document_id in tqdm.tqdm(document_ids.items()):
print("-"*100)
print("Document Name: %s" % document_name)
# timing the duration
begin = time.time()
texts = get_pdf_by_code(document_id)
summary = summarizer(texts, max_length=300, truncation=True, do_sample=False)
summary = " ".join(item["summary_text"] for item in summary)
pprint.pprint("-"*100)
duration = time.time() - begin
docs.append({
"document_name": document_name,
"summary": summary,
"seconds": duration,
"model_name": summary_model,
})
return docs
model_checkpoint = "tiiuae/falcon-mamba-7b-instruct"
device = "cuda:0" if torch.cuda.is_available() else "cpu"
output = generate_result(summary_model=model_checkpoint,
config = nf4_config, document_ids=hashcodes, device=device)
df = pd.DataFrame(output)
Hello @perceptron-743
Please see my comment in: https://huggingface.co/tiiuae/falcon-mamba-7b-instruct-4bit/discussions/3#66c729eb9201ce2767f2b9f8