Instructions to use prithivMLmods/SmolLM2-CoT-360M-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use prithivMLmods/SmolLM2-CoT-360M-GGUF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="prithivMLmods/SmolLM2-CoT-360M-GGUF") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("prithivMLmods/SmolLM2-CoT-360M-GGUF", dtype="auto") - llama-cpp-python
How to use prithivMLmods/SmolLM2-CoT-360M-GGUF with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="prithivMLmods/SmolLM2-CoT-360M-GGUF", filename="SmolLM2-CoT-360M.F16.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 prithivMLmods/SmolLM2-CoT-360M-GGUF with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M # Run inference directly in the terminal: llama-cli -hf prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M # Run inference directly in the terminal: llama-cli -hf prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M
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 prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M
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 prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M
Use Docker
docker model run hf.co/prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use prithivMLmods/SmolLM2-CoT-360M-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "prithivMLmods/SmolLM2-CoT-360M-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "prithivMLmods/SmolLM2-CoT-360M-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M
- SGLang
How to use prithivMLmods/SmolLM2-CoT-360M-GGUF 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 "prithivMLmods/SmolLM2-CoT-360M-GGUF" \ --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": "prithivMLmods/SmolLM2-CoT-360M-GGUF", "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 "prithivMLmods/SmolLM2-CoT-360M-GGUF" \ --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": "prithivMLmods/SmolLM2-CoT-360M-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use prithivMLmods/SmolLM2-CoT-360M-GGUF with Ollama:
ollama run hf.co/prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M
- Unsloth Studio new
How to use prithivMLmods/SmolLM2-CoT-360M-GGUF 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 prithivMLmods/SmolLM2-CoT-360M-GGUF 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 prithivMLmods/SmolLM2-CoT-360M-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for prithivMLmods/SmolLM2-CoT-360M-GGUF to start chatting
- Docker Model Runner
How to use prithivMLmods/SmolLM2-CoT-360M-GGUF with Docker Model Runner:
docker model run hf.co/prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M
- Lemonade
How to use prithivMLmods/SmolLM2-CoT-360M-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull prithivMLmods/SmolLM2-CoT-360M-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.SmolLM2-CoT-360M-GGUF-Q4_K_M
List all available models
lemonade list
SMOLLM CoT 360M GGUF ON CUSTOM SYNTHETIC DATA
SmolLM2 is a family of compact language models available in three size: 135M, 360M, and 1.7B parameters. They are capable of solving a wide range of tasks while being lightweight enough to run on-device. Fine-tuning a language model like SmolLM involves several steps, from setting up the environment to training the model and saving the results. Below is a detailed step-by-step guide based on the provided notebook file
How to use with Transformers
pip install transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
checkpoint = "prithivMLmods/SmolLM2-CoT-360M"
device = "cuda" # for GPU usage or "cpu" for CPU usage
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
messages = [{"role": "user", "content": "What is the capital of France."}]
input_text=tokenizer.apply_chat_template(messages, tokenize=False)
inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
print(tokenizer.decode(outputs[0]))
Step 1: Setting Up the Environment
Before diving into fine-tuning, you need to set up your environment with the necessary libraries and tools.
Install Required Libraries:
- Install the necessary Python libraries using
pip. These includetransformers,datasets,trl,torch,accelerate,bitsandbytes, andwandb. - These libraries are essential for working with Hugging Face models, datasets, and training loops.
!pip install transformers datasets trl torch accelerate bitsandbytes wandb- Install the necessary Python libraries using
Import Necessary Modules:
- Import the required modules from the installed libraries. These include
AutoModelForCausalLM,AutoTokenizer,TrainingArguments,pipeline,load_dataset, andSFTTrainer.
from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, pipeline from datasets import load_dataset from trl import SFTConfig, SFTTrainer, setup_chat_format import torch import os- Import the required modules from the installed libraries. These include
Detect Device (GPU, MPS, or CPU):
- Detect the available hardware (GPU, MPS, or CPU) to ensure the model runs on the most efficient device.
device = ( "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu" )
Step 2: Load the Pre-trained Model and Tokenizer
Next, load the pre-trained SmolLM model and its corresponding tokenizer.
Load the Model and Tokenizer:
- Use
AutoModelForCausalLMandAutoTokenizerto load the SmolLM model and tokenizer from Hugging Face.
model_name = "HuggingFaceTB/SmolLM2-360M" model = AutoModelForCausalLM.from_pretrained(pretrained_model_name_or_path=model_name) tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path=model_name)- Use
Set Up Chat Format:
- Use the
setup_chat_formatfunction to prepare the model and tokenizer for chat-based tasks.
model, tokenizer = setup_chat_format(model=model, tokenizer=tokenizer)- Use the
Test the Base Model:
- Test the base model with a simple prompt to ensure it’s working correctly.
prompt = "Explain AGI ?" pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0 if device == "cuda" else -1) print(pipe(prompt, max_new_tokens=200))If: Encountering:
- Chat template is already added to the tokenizer, indicates that the tokenizer already has a predefined chat template, which prevents the setup_chat_format() from modifying it again.
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
model_name = "HuggingFaceTB/SmolLM2-1.7B-Instruct"
model = AutoModelForCausalLM.from_pretrained(pretrained_model_name_or_path=model_name)
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path=model_name)
tokenizer.chat_template = None
from trl.models.utils import setup_chat_format
model, tokenizer = setup_chat_format(model=model, tokenizer=tokenizer)
prompt = "Explain AGI?"
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0)
print(pipe(prompt, max_new_tokens=200))
📍 Else Skip the Part [ Step 4 ] !
Step 3: Load and Prepare the Dataset
Fine-tuning requires a dataset. In this case, we’re using a custom dataset called Deepthink-Reasoning.
Load the Dataset:
- Use the
load_datasetfunction to load the dataset from Hugging Face.
ds = load_dataset("prithivMLmods/Deepthink-Reasoning")- Use the
Tokenize the Dataset:
- Define a tokenization function that processes the dataset in batches. This function applies the chat template to each prompt-response pair and tokenizes the text.
def tokenize_function(examples): prompts = [p.strip() for p in examples["prompt"]] responses = [r.strip() for r in examples["response"]] texts = [ tokenizer.apply_chat_template( [{"role": "user", "content": p}, {"role": "assistant", "content": r}], tokenize=False ) for p, r in zip(prompts, responses) ] return tokenizer(texts, truncation=True, padding="max_length", max_length=512)Apply Tokenization:
- Apply the tokenization function to the dataset.
ds = ds.map(tokenize_function, batched=True)
Step 4: Configure Training Arguments
Set up the training arguments to control the fine-tuning process.
Define Training Arguments:
- Use
TrainingArgumentsto specify parameters like batch size, learning rate, number of steps, and optimization settings.
use_bf16 = torch.cuda.is_bf16_supported() training_args = TrainingArguments( per_device_train_batch_size=2, gradient_accumulation_steps=4, warmup_steps=5, max_steps=60, learning_rate=2e-4, fp16=not use_bf16, bf16=use_bf16, logging_steps=1, optim="adamw_8bit", weight_decay=0.01, lr_scheduler_type="linear", seed=3407, output_dir="outputs", report_to="wandb", )- Use
Step 5: Initialize the Trainer
Initialize the SFTTrainer with the model, tokenizer, dataset, and training arguments.
trainer = SFTTrainer(
model=model,
processing_class=tokenizer,
train_dataset=ds["train"],
args=training_args,
)
Step 6: Start Training
Begin the fine-tuning process by calling the train method on the trainer.
trainer.train()
Step 7: Save the Fine-Tuned Model
After training, save the fine-tuned model and tokenizer to a local directory.
Save Model and Tokenizer:
- Use the
save_pretrainedmethod to save the model and tokenizer.
save_directory = "/content/my_model" model.save_pretrained(save_directory) tokenizer.save_pretrained(save_directory)- Use the
Zip and Download the Model:
- Zip the saved directory and download it for future use.
import shutil shutil.make_archive(save_directory, 'zip', save_directory) from google.colab import files files.download(f"{save_directory}.zip")
Run with Ollama [Ollama Run]
Ollama makes running machine learning models simple and efficient. Follow these steps to set up and run your GGUF models quickly.
Quick Start: Step-by-Step Guide
| Step | Description | Command / Instructions |
|---|---|---|
| 1 | Install Ollama 🦙 | Download Ollama from https://ollama.com/download and install it on your system. |
| 2 | Create Your Model File | - Create a file named after your model, e.g., metallama. |
| - Add the following line to specify the base model: | ||
| ```bash | ||
| FROM Llama-3.2-1B.F16.gguf | ||
| ``` | ||
| - Ensure the base model file is in the same directory. | ||
| 3 | Create and Patch the Model | Run the following commands to create and verify your model: |
| ```bash | ||
| ollama create metallama -f ./metallama | ||
| ollama list | ||
| ``` | ||
| 4 | Run the Model | Use the following command to start your model: |
| ```bash | ||
| ollama run metallama | ||
| ``` | ||
| 5 | Interact with the Model | Once the model is running, interact with it: |
| ```plaintext | ||
| >>> Tell me about Space X. | ||
| Space X, the private aerospace company founded by Elon Musk, is revolutionizing space exploration... | ||
| ``` |
Model & Quant
| Item | Link |
|---|---|
| Model | SmolLM2-CoT-360M |
| Quantized Version | SmolLM2-CoT-360M-GGUF |
Conclusion
Fine-tuning SmolLM involves setting up the environment, loading the model and dataset, configuring training parameters, and running the training loop. By following these steps, you can adapt SmolLM to your specific use case, whether it’s for reasoning tasks, chat-based applications, or other NLP tasks.
This process is highly customizable, so feel free to experiment with different datasets, hyperparameters, and training strategies to achieve the best results for your project.
- Downloads last month
- 91
4-bit
5-bit
8-bit
16-bit
Model tree for prithivMLmods/SmolLM2-CoT-360M-GGUF
Base model
HuggingFaceTB/SmolLM2-360M
