Instructions to use build-small-hackathon/sofia-qwen2.5-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use build-small-hackathon/sofia-qwen2.5-7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="build-small-hackathon/sofia-qwen2.5-7b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("build-small-hackathon/sofia-qwen2.5-7b") model = AutoModelForMultimodalLM.from_pretrained("build-small-hackathon/sofia-qwen2.5-7b") 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]:])) - PEFT
How to use build-small-hackathon/sofia-qwen2.5-7b with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use build-small-hackathon/sofia-qwen2.5-7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "build-small-hackathon/sofia-qwen2.5-7b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "build-small-hackathon/sofia-qwen2.5-7b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/build-small-hackathon/sofia-qwen2.5-7b
- SGLang
How to use build-small-hackathon/sofia-qwen2.5-7b 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 "build-small-hackathon/sofia-qwen2.5-7b" \ --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": "build-small-hackathon/sofia-qwen2.5-7b", "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 "build-small-hackathon/sofia-qwen2.5-7b" \ --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": "build-small-hackathon/sofia-qwen2.5-7b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use build-small-hackathon/sofia-qwen2.5-7b with Docker Model Runner:
docker model run hf.co/build-small-hackathon/sofia-qwen2.5-7b
Use Docker
docker model run hf.co/build-small-hackathon/sofia-qwen2.5-7bSofรญa โ Qwen2.5-7B-Instruct fine-tuneado para una compaรฑera de voz de una nena de 3 aรฑos
TL;DR (EN): QLoRA fine-tune of Qwen/Qwen2.5-7B-Instruct (merged, full
precision weights) that teaches the base model to consistently play
"Sofรญa" โ a warm, short-sentence Spanish-speaking companion for a ~3
year old โ to present curated content (<contenido>) verbatim
instead of paraphrasing/inventing it, and to gently refuse/redirect
unsafe topics. Built for the
Build Small Hackathon
(track Backyard AI, mรฉrito Well-Tuned). Powers the
sofia-educational-companion
Space.
Quรฉ es
Este modelo es el "pegamento conversacional" de Sofรญa, una compaรฑera
educativa por voz para una niรฑa de ~3 aรฑos (proyecto Lumi, Build Small
Hackathon, track Backyard AI). El LLM nunca es la fuente de hechos:
todo el contenido (cuentos, actividades, nรบmeros) vive curado en
content/ y se le inyecta al modelo entre <contenido>...</contenido>.
Este fine-tune entrena estilo y seguridad, no conocimiento.
Objetivos del fine-tune:
- Mantener siempre la persona "Sofรญa": cรกlida, frases muy cortas, espaรฑol rioplatense, una pregunta por turno.
- Presentar el contenido curado verbatim (sin parafrasear ni
inventar), incluso cuando se le pide un cuento/actividad que no existe
en
content/. - Rechazar o redirigir con cariรฑo temas no aptos para una niรฑa de 3 aรฑos,
generalizando mรกs allรก de los tรฉrminos exactos de
safety/blocklist.txt(defensa en profundidad).
Datos de entrenamiento
finetune/build_dataset.py genera finetune/dataset.jsonl: 196
ejemplos en formato chat (mismo SYSTEM_PROMPT y los mismos bloques
<contenido>/<nota> que construye llm/engine.py en producciรณn),
mezclando:
- saludos y charla / persona,
- entrega de actividades curadas (contar, formas, colores, animales), x3 frases cada una,
- cambio de color de Sofรญa (intent
sofia_color), - cuentos curados,
- ~62 rechazos/redirecciones de temas no aptos que no repiten los tรฉrminos exactos de la blocklist.
Entrenamiento
QLoRA sobre Qwen/Qwen2.5-7B-Instruct, corrido en Modal (GPU A10G):
- Carga en 4-bit NF4 (
bnb_4bit_use_double_quant=True), cรณmputo en bf16. - LoRA
r=16,alpha=32,target_modules=["q_proj", "k_proj", "v_proj", "o_proj"]. - 3 รฉpocas, batch size 2, gradient accumulation 4, learning rate 2e-4.
- 72 steps, ~408s en A10G. Loss 2.51 โ 0.14.
- El adapter se mergeรณ (
merge_and_unload) y se publicรณ en este repo como pesos completos en safetensors.
Cรณdigo: finetune/train_modal.py y finetune/merge_lora.py en el
repo del proyecto.
Evaluaciรณn (smoke test)
finetune/smoke_test_modal.py corriรณ 5 turnos representativos sobre este
modelo ya mergeado: saludo, entrega de <contenido> de conteo, una
pregunta sobre un arma, miedo a los monstruos, y un pedido de cuento
inventado ("un dragรณn que come autos"). Resultado: saluda en persona,
repite el <contenido> verbatim (a diferencia de alternativas
probadas como Nemotron-mini/Nemotron-3-nano, que parafraseaban o
inventaban), rechaza el tema del arma sin engancharse, redirige el miedo
con calidez, y ante el cuento inventado dice que no lo tiene y ofrece una
alternativa curada en vez de inventar una.
Cรณmo usarlo
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL_ID = "build-small-hackathon/sofia-qwen2.5-7b"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID, torch_dtype=torch.bfloat16
).to("cuda")
# SYSTEM_PROMPT exacto y bloques <contenido>/<nota>: ver llm/engine.py
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": "Hola Sofรญa"},
]
text = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
inputs = tokenizer(text, return_tensors="pt").to("cuda")
output = model.generate(
**inputs, max_new_tokens=120, do_sample=True, temperature=0.6
)
Limitaciones
- Entrenado para un caso de uso muy acotado: compaรฑera de juego para
una niรฑa de 3 aรฑos, en espaรฑol rioplatense, con contenido inyectado
por el sistema (
<contenido>/<nota>/<contexto>). Fuera de ese contexto se comporta bรกsicamente como el Qwen2.5-7B-Instruct base. - No agrega conocimiento factual nuevo: por diseรฑo, los hechos siguen
viviendo en
content/, nunca en los pesos. - Dataset chico (196 ejemplos), curado a mano para un hackathon โ no es un benchmark de seguridad general.
Licencia
Apache 2.0, igual que el modelo base Qwen/Qwen2.5-7B-Instruct.
- Downloads last month
- 24
Install from pip and serve model
# Install vLLM from pip: pip install vllm# Start the vLLM server: vllm serve "build-small-hackathon/sofia-qwen2.5-7b"# Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "build-small-hackathon/sofia-qwen2.5-7b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'