Text Generation
Transformers
ONNX
Safetensors
English
llama
alignment-handbook
trl
sft
conversational
text-generation-inference
Instructions to use HuggingFaceTB/SmolLM-1.7B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HuggingFaceTB/SmolLM-1.7B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="HuggingFaceTB/SmolLM-1.7B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/SmolLM-1.7B-Instruct") model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM-1.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
- vLLM
How to use HuggingFaceTB/SmolLM-1.7B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HuggingFaceTB/SmolLM-1.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": "HuggingFaceTB/SmolLM-1.7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/HuggingFaceTB/SmolLM-1.7B-Instruct
- SGLang
How to use HuggingFaceTB/SmolLM-1.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 "HuggingFaceTB/SmolLM-1.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": "HuggingFaceTB/SmolLM-1.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 "HuggingFaceTB/SmolLM-1.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": "HuggingFaceTB/SmolLM-1.7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use HuggingFaceTB/SmolLM-1.7B-Instruct with Docker Model Runner:
docker model run hf.co/HuggingFaceTB/SmolLM-1.7B-Instruct
| { | |
| "best_metric": null, | |
| "best_model_checkpoint": null, | |
| "epoch": 0.9872958257713249, | |
| "eval_steps": 100, | |
| "global_step": 68, | |
| "is_hyper_param_search": false, | |
| "is_local_process_zero": true, | |
| "is_world_process_zero": true, | |
| "log_history": [ | |
| { | |
| "epoch": 0.014519056261343012, | |
| "grad_norm": 2.5819620488760253, | |
| "learning_rate": 7.142857142857143e-07, | |
| "logits/chosen": 0.902682900428772, | |
| "logits/rejected": 0.8661031723022461, | |
| "logps/chosen": -125.2274169921875, | |
| "logps/rejected": -145.89674377441406, | |
| "loss": 0.6931, | |
| "rewards/accuracies": 0.0, | |
| "rewards/chosen": 0.0, | |
| "rewards/margins": 0.0, | |
| "rewards/rejected": 0.0, | |
| "step": 1 | |
| }, | |
| { | |
| "epoch": 0.14519056261343014, | |
| "grad_norm": 3.2242486672937045, | |
| "learning_rate": 4.970219740227693e-06, | |
| "logits/chosen": 0.8677890300750732, | |
| "logits/rejected": 0.88941490650177, | |
| "logps/chosen": -120.65478515625, | |
| "logps/rejected": -149.0773468017578, | |
| "loss": 0.6925, | |
| "rewards/accuracies": 0.4097222089767456, | |
| "rewards/chosen": 0.0005513947107829154, | |
| "rewards/margins": -0.0005504629807546735, | |
| "rewards/rejected": 0.001101857633329928, | |
| "step": 10 | |
| }, | |
| { | |
| "epoch": 0.29038112522686027, | |
| "grad_norm": 4.0763010346326904, | |
| "learning_rate": 4.460299516441777e-06, | |
| "logits/chosen": 1.0478929281234741, | |
| "logits/rejected": 1.0530675649642944, | |
| "logps/chosen": -115.20359802246094, | |
| "logps/rejected": -142.4711456298828, | |
| "loss": 0.6887, | |
| "rewards/accuracies": 0.543749988079071, | |
| "rewards/chosen": -0.007147049065679312, | |
| "rewards/margins": 0.007046631071716547, | |
| "rewards/rejected": -0.014193681068718433, | |
| "step": 20 | |
| }, | |
| { | |
| "epoch": 0.4355716878402904, | |
| "grad_norm": 2.868995154924774, | |
| "learning_rate": 3.441819734087963e-06, | |
| "logits/chosen": 1.0493364334106445, | |
| "logits/rejected": 1.0137263536453247, | |
| "logps/chosen": -115.47831726074219, | |
| "logps/rejected": -145.4583282470703, | |
| "loss": 0.681, | |
| "rewards/accuracies": 0.53125, | |
| "rewards/chosen": -0.013122054748237133, | |
| "rewards/margins": 0.018696457147598267, | |
| "rewards/rejected": -0.031818509101867676, | |
| "step": 30 | |
| }, | |
| { | |
| "epoch": 0.5807622504537205, | |
| "grad_norm": 2.4635583297317165, | |
| "learning_rate": 2.1790041121336223e-06, | |
| "logits/chosen": 1.2130175828933716, | |
| "logits/rejected": 1.1768478155136108, | |
| "logps/chosen": -154.19398498535156, | |
| "logps/rejected": -181.88272094726562, | |
| "loss": 0.6762, | |
| "rewards/accuracies": 0.581250011920929, | |
| "rewards/chosen": -0.04483573138713837, | |
| "rewards/margins": 0.041850604116916656, | |
| "rewards/rejected": -0.08668633550405502, | |
| "step": 40 | |
| }, | |
| { | |
| "epoch": 0.7259528130671506, | |
| "grad_norm": 3.188683944287027, | |
| "learning_rate": 9.994642986290797e-07, | |
| "logits/chosen": 1.3518016338348389, | |
| "logits/rejected": 1.2714142799377441, | |
| "logps/chosen": -131.69985961914062, | |
| "logps/rejected": -161.8300018310547, | |
| "loss": 0.6622, | |
| "rewards/accuracies": 0.6499999761581421, | |
| "rewards/chosen": -0.011605720035731792, | |
| "rewards/margins": 0.06830872595310211, | |
| "rewards/rejected": -0.07991443574428558, | |
| "step": 50 | |
| }, | |
| { | |
| "epoch": 0.8711433756805808, | |
| "grad_norm": 3.3445679325076476, | |
| "learning_rate": 2.092077387824884e-07, | |
| "logits/chosen": 1.367594838142395, | |
| "logits/rejected": 1.2992292642593384, | |
| "logps/chosen": -121.10174560546875, | |
| "logps/rejected": -139.6844940185547, | |
| "loss": 0.6612, | |
| "rewards/accuracies": 0.612500011920929, | |
| "rewards/chosen": -0.017885591834783554, | |
| "rewards/margins": 0.07065734267234802, | |
| "rewards/rejected": -0.08854293823242188, | |
| "step": 60 | |
| }, | |
| { | |
| "epoch": 0.9872958257713249, | |
| "step": 68, | |
| "total_flos": 0.0, | |
| "train_loss": 0.6753217893488267, | |
| "train_runtime": 321.7901, | |
| "train_samples_per_second": 27.366, | |
| "train_steps_per_second": 0.211 | |
| } | |
| ], | |
| "logging_steps": 10, | |
| "max_steps": 68, | |
| "num_input_tokens_seen": 0, | |
| "num_train_epochs": 1, | |
| "save_steps": 500, | |
| "stateful_callbacks": { | |
| "TrainerControl": { | |
| "args": { | |
| "should_epoch_stop": false, | |
| "should_evaluate": false, | |
| "should_log": false, | |
| "should_save": false, | |
| "should_training_stop": false | |
| }, | |
| "attributes": {} | |
| } | |
| }, | |
| "total_flos": 0.0, | |
| "train_batch_size": 2, | |
| "trial_name": null, | |
| "trial_params": null | |
| } | |