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, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("swarecito/smol-256") model = AutoModelForImageTextToText.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
- 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 base64 | |
| import os | |
| import sys | |
| # Ajoutez le chemin du dossier parent pour que Python puisse trouver handler.py | |
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__)))) | |
| from handler import EndpointHandler # Assurez-vous que handler.py est dans le même dossier ou dans le PYTHONPATH | |
| # --- Configuration pour le test local --- | |
| # Le chemin vers le modèle n'est pas utilisé par notre handler car il charge le modèle par son ID | |
| # Mais l'EndpointHandler attend un argument `path`. | |
| # Pour le test local, on peut passer une chaîne vide ou un point. | |
| MODEL_PATH_FOR_HANDLER = "." | |
| # Chemin vers votre vidéo de test | |
| # Assurez-vous que ce chemin est correct par rapport à l'endroit où vous exécutez ce script | |
| VIDEO_FILE_PATH = "../../static/video-test.mp4" # Ajustez ce chemin si nécessaire | |
| # --- Initialisation du handler --- | |
| print("Initialisation du EndpointHandler...") | |
| # Pour le test local, le token n'est pas nécessaire car le modèle est chargé depuis le Hub public. | |
| # Si votre modèle était privé, vous devriez définir os.environ["HUGGING_FACE_HUB_TOKEN"] = "votre_token" | |
| handler = EndpointHandler(path=MODEL_PATH_FOR_HANDLER) | |
| print("EndpointHandler initialisé.") | |
| # --- Préparation du payload (simule l'entrée de l'API) --- | |
| print(f"Lecture de la vidéo de test: {VIDEO_FILE_PATH}") | |
| try: | |
| with open(VIDEO_FILE_PATH, "rb") as f: | |
| video_bytes = f.read() | |
| encoded_video = base64.b64encode(video_bytes).decode("utf-8") | |
| except FileNotFoundError: | |
| print(f"Erreur: Le fichier vidéo {VIDEO_FILE_PATH} n'a pas été trouvé.") | |
| exit() | |
| # Le payload doit correspondre à ce que votre handler.__call__ attend | |
| # C'est-à-dire un dictionnaire avec une clé "inputs" qui contient une liste de messages | |
| # et le contenu vidéo encodé en base64 sous la clé "data". | |
| payload = { | |
| "inputs": [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| {"type": "text", "text": "Describe this video in detail"}, | |
| {"type": "video", "data": encoded_video} # Ici, on passe la vidéo encodée | |
| ] | |
| } | |
| ], | |
| "parameters": { | |
| "max_new_tokens": 128 # Paramètres d'inférence optionnels | |
| } | |
| } | |
| # --- Exécution de l'inférence --- | |
| print("Lancement de l'inférence locale (cela peut prendre du temps)...") | |
| try: | |
| result = handler(payload) | |
| print("\n--- Résultat de l'inférence ---") | |
| print(result) | |
| except Exception as e: | |
| print(f"\nErreur lors de l'inférence: {e}") |