Instructions to use stabilityai/stablelm-2-zephyr-1_6b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use stabilityai/stablelm-2-zephyr-1_6b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="stabilityai/stablelm-2-zephyr-1_6b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("stabilityai/stablelm-2-zephyr-1_6b") model = AutoModelForCausalLM.from_pretrained("stabilityai/stablelm-2-zephyr-1_6b") 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]:])) - llama-cpp-python
How to use stabilityai/stablelm-2-zephyr-1_6b with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="stabilityai/stablelm-2-zephyr-1_6b", filename="stablelm-2-zephyr-1_6b-Q4_0.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use stabilityai/stablelm-2-zephyr-1_6b with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf stabilityai/stablelm-2-zephyr-1_6b:Q4_0 # Run inference directly in the terminal: llama-cli -hf stabilityai/stablelm-2-zephyr-1_6b:Q4_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf stabilityai/stablelm-2-zephyr-1_6b:Q4_0 # Run inference directly in the terminal: llama-cli -hf stabilityai/stablelm-2-zephyr-1_6b:Q4_0
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf stabilityai/stablelm-2-zephyr-1_6b:Q4_0 # Run inference directly in the terminal: ./llama-cli -hf stabilityai/stablelm-2-zephyr-1_6b:Q4_0
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf stabilityai/stablelm-2-zephyr-1_6b:Q4_0 # Run inference directly in the terminal: ./build/bin/llama-cli -hf stabilityai/stablelm-2-zephyr-1_6b:Q4_0
Use Docker
docker model run hf.co/stabilityai/stablelm-2-zephyr-1_6b:Q4_0
- LM Studio
- Jan
- vLLM
How to use stabilityai/stablelm-2-zephyr-1_6b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "stabilityai/stablelm-2-zephyr-1_6b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "stabilityai/stablelm-2-zephyr-1_6b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/stabilityai/stablelm-2-zephyr-1_6b:Q4_0
- SGLang
How to use stabilityai/stablelm-2-zephyr-1_6b 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 "stabilityai/stablelm-2-zephyr-1_6b" \ --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": "stabilityai/stablelm-2-zephyr-1_6b", "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 "stabilityai/stablelm-2-zephyr-1_6b" \ --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": "stabilityai/stablelm-2-zephyr-1_6b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use stabilityai/stablelm-2-zephyr-1_6b with Ollama:
ollama run hf.co/stabilityai/stablelm-2-zephyr-1_6b:Q4_0
- Unsloth Studio new
How to use stabilityai/stablelm-2-zephyr-1_6b with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for stabilityai/stablelm-2-zephyr-1_6b to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for stabilityai/stablelm-2-zephyr-1_6b to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for stabilityai/stablelm-2-zephyr-1_6b to start chatting
- Docker Model Runner
How to use stabilityai/stablelm-2-zephyr-1_6b with Docker Model Runner:
docker model run hf.co/stabilityai/stablelm-2-zephyr-1_6b:Q4_0
- Lemonade
How to use stabilityai/stablelm-2-zephyr-1_6b with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull stabilityai/stablelm-2-zephyr-1_6b:Q4_0
Run and chat with the model
lemonade run user.stablelm-2-zephyr-1_6b-Q4_0
List all available models
lemonade list
How to finetuning this model?
I would like to work on finetuning this model.
It seems that we can do this with axolotl
Which axolotl configuration file to adapt?
Or a second solution of using PEFT LoRA and bitsandbytes (for exemple: fine tune OPT-6.7b)
Any recommendations for me on how to do this?
hi LeMoussel,
I just finished finetuning the model with the following axolotl config:
base_model: stabilityai/stablelm-2-zephyr-1_6b
base_model_config: stabilityai/stablelm-2-zephyr-1_6b
model_type: StableLMEpochForCausalLM
tokenizer_type: AutoTokenizer
trust_remote_code: true
load_in_8bit: false
load_in_4bit: true
strict: false
datasets:
- path: interstellarninja/tool-calls-multiturn
type: sharegpt.load_multirole
conversation: zephyr
val_set_size: 0
dataset_prepared_path: last_run_prepared
output_dir: ./stablelm-1_6b-tool-calling-1
sequence_len: 4096
sample_packing: false
eval_sample_packing: false
eval_batch_size: 1
adapter: qlora
lora_r: 32
lora_alpha: 16
lora_dropout: 0.05
lora_target_linear: true
lora_on_cpu: true
lora_modules_to_save:
- embed_tokens
- lm_head
wandb_project: tool-calling-multiturn-1_6b
wandb_run_id: stablelm-1_6b-tool-calling-1
data_seed: 42
seed: 42
gradient_accumulation_steps: 1
micro_batch_size: 1
warmup_steps: 25
num_epochs: 3
optimizer: adamw_bnb_8bit
learning_rate: 0.00001
lr_scheduler: cosine
weight_decay: 0.02
train_on_inputs: false
group_by_length: true
bf16: true
fp16: false
tf32: true
gradient_checkpointing: true
logging_steps: 1
xformers_attention: false
flash_attention: false
save_strategy: epoch
save_safetensors: true
resume_from_checkpoint: false
hub_model_id: interstellarninja/stablelm-2-zephyr-1_6b-tool-caller
Thank you for your help. Very interesting.
I don't find your dataset interstellarninja/tool-calls-multiturn on HuggingFace. Do you have an example dataset for finetuning this model?
here's my notebook for finetuning it, no trainer like axolotl though, just HF code
https://github.com/geronimi73/TinyLlama-versus-StableLM2/blob/main/nb_finetune_StableLM2_OA2.ipynb
Thank you so much !
You use g-ronimo/oasst2_top1_en as dataset.
From what I understand the dataset must be in the form an list of array like this[ { "content": "Some content user ....", "role": "user" }, { "content": "Some content assistant ...", "role": "assistant" } ]
Do you think it is necessary to have content assistant? Could this be empty?
Rem: I want to create a dataset in French.
Do you think it is necessary to have
content assistant? Could this be empty?
could you please rephrase, not sure what you mean
Does dataset may contain only Some content user ....
Eg:
[ { "content": "Some content1 ....", "role": "user" }, { "content": "", "role": "assistant" } ]
[ { "content": "Some content2 ....", "role": "user" }, { "content": "", "role": "assistant" } ]
.....
I think the idea was to create at least a question and an answer, if you remove the assistant object, you remove the answer.
If your use case is to expose to "user questions" you can do it but I think it can make the model to answer questions with "", which I think is not desirable. My suggestion is that you explain more your use case or to create synthetic answers with a more capable model or even humans.