Instructions to use swarecito/smol-256 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use swarecito/smol-256 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="swarecito/smol-256") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("swarecito/smol-256") model = AutoModelForMultimodalLM.from_pretrained("swarecito/smol-256") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use swarecito/smol-256 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "swarecito/smol-256" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "swarecito/smol-256", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/swarecito/smol-256
- SGLang
How to use swarecito/smol-256 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 "swarecito/smol-256" \ --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": "swarecito/smol-256", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "swarecito/smol-256" \ --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": "swarecito/smol-256", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use swarecito/smol-256 with Docker Model Runner:
docker model run hf.co/swarecito/smol-256
| import torch | |
| from transformers import AutoProcessor, AutoModelForImageTextToText | |
| import base64 | |
| from PIL import Image | |
| import io | |
| import os | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| # Le token est automatiquement disponible pour les endpoints privés/protégés | |
| token = os.getenv("HUGGING_FACE_HUB_TOKEN") | |
| # On spécifie quel modèle charger via une variable d'environnement | |
| # Si elle n'est pas définie, on prend une valeur par défaut | |
| model_id = os.getenv("MODEL_ID", "HuggingFaceTB/SmolVLM2-256M-Video-Instruct") | |
| self.device = "cuda" if torch.cuda.is_available() else "cpu" | |
| self.dtype = torch.bfloat16 if self.device == "cuda" else torch.float32 | |
| # Charger le processeur et le modèle DEPUIS L'ID DU MODÈLE ORIGINAL | |
| self.processor = AutoProcessor.from_pretrained(model_id, token=token) | |
| self.model = AutoModelForImageTextToText.from_pretrained( | |
| model_id, | |
| torch_dtype=self.dtype, | |
| token=token | |
| ).to(self.device) | |
| print(f"✅ Modèle {model_id} chargé avec succès sur {self.device}") | |
| print("✅ Modèle et processeur chargés avec succès sur le device:", self.device) | |
| def __call__(self, data: dict) -> dict: | |
| """ | |
| Cette fonction est appelée pour chaque requête API. | |
| `data` est le JSON envoyé dans la requête. | |
| """ | |
| # Extraire les entrées du JSON de la requête | |
| inputs = data.pop("inputs", data) | |
| parameters = data.pop("parameters", {}) | |
| # Le payload attendu est une liste de messages, comme dans notre API | |
| # Exemple: {"inputs": [{"role": "user", "content": [{"type": "text", "text": "prompt"}, {"type": "video", "data": "base64_string"}]}]} | |
| messages = inputs | |
| # Le modèle attend un chemin de fichier, nous devons donc décoder la vidéo base64 | |
| # et la sauvegarder temporairement. | |
| video_content = messages[0]['content'][1]['data'] | |
| video_data = base64.b64decode(video_content) | |
| # Sauvegarder le fichier vidéo temporairement | |
| temp_video_path = "/tmp/temp_video.mp4" | |
| with open(temp_video_path, "wb") as f: | |
| f.write(video_data) | |
| # Mettre à jour le message pour pointer vers le chemin du fichier | |
| messages[0]['content'][1] = {"type": "video", "path": temp_video_path} | |
| # Préparer les entrées pour le modèle | |
| inputs = self.processor.apply_chat_template( | |
| messages, | |
| add_generation_prompt=True, | |
| tokenize=True, | |
| return_dict=True, | |
| return_tensors="pt", | |
| ).to(self.device, dtype=self.dtype) | |
| # Exécuter l'inférence | |
| with torch.no_grad(): | |
| generated_ids = self.model.generate(**inputs, **parameters) | |
| generated_texts = self.processor.batch_decode( | |
| generated_ids, | |
| skip_special_tokens=True, | |
| ) | |
| # Nettoyer le fichier temporaire | |
| os.remove(temp_video_path) | |
| # Retourner le résultat | |
| return {"generated_text": generated_texts[0]} | |