Text Generation
Transformers
Safetensors
English
ivme_conversate
ivme
small-language-model
instruct
chat
sft
muon
xsa
qk-norm
custom_code
conversational
Instructions to use IvmeLabs/Ivme-Conversate-v3.1-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use IvmeLabs/Ivme-Conversate-v3.1-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="IvmeLabs/Ivme-Conversate-v3.1-Instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("IvmeLabs/Ivme-Conversate-v3.1-Instruct", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use IvmeLabs/Ivme-Conversate-v3.1-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "IvmeLabs/Ivme-Conversate-v3.1-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": "IvmeLabs/Ivme-Conversate-v3.1-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/IvmeLabs/Ivme-Conversate-v3.1-Instruct
- SGLang
How to use IvmeLabs/Ivme-Conversate-v3.1-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 "IvmeLabs/Ivme-Conversate-v3.1-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": "IvmeLabs/Ivme-Conversate-v3.1-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 "IvmeLabs/Ivme-Conversate-v3.1-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": "IvmeLabs/Ivme-Conversate-v3.1-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use IvmeLabs/Ivme-Conversate-v3.1-Instruct with Docker Model Runner:
docker model run hf.co/IvmeLabs/Ivme-Conversate-v3.1-Instruct
Download training/train.py from IvmeLabs/Ivme-Conversate-v3.1-Instruct: direct link, hf CLI and curl.
- Browser
- Download file 4.92 kB
-
https://huggingface.co/IvmeLabs/Ivme-Conversate-v3.1-Instruct/resolve/main/training/train.py
- Command line
-
hf download hf://IvmeLabs/Ivme-Conversate-v3.1-Instruct/training/train.py
-
curl -L -o train.py https://huggingface.co/IvmeLabs/Ivme-Conversate-v3.1-Instruct/resolve/main/training/train.py
4.92 kB
| """SFT Ivme-Conversate-v3.1-Base -> Instruct with Muon (2D body weights) + AdamW (embeddings, norms). | |
| Logs JSON lines to RUN/log.jsonl; saves HF checkpoints to RUN/best and RUN/final. | |
| """ | |
| import json, math, os, sys, time, argparse | |
| import numpy as np, torch, torch.nn.functional as F | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--data", default="/marimo/ivme_sft/data") | |
| ap.add_argument("--run", default="/marimo/ivme_sft/run1") | |
| ap.add_argument("--epochs", type=float, default=2.0) | |
| ap.add_argument("--bs", type=int, default=64) | |
| ap.add_argument("--muon_lr", type=float, default=1.5e-4) | |
| ap.add_argument("--adam_lr", type=float, default=1e-5) | |
| ap.add_argument("--wd", type=float, default=0.01) | |
| ap.add_argument("--warmup", type=int, default=50) | |
| ap.add_argument("--decay_frac", type=float, default=0.3) | |
| ap.add_argument("--eval_every", type=int, default=200) | |
| ap.add_argument("--eot_w", type=float, default=1.0) | |
| a = ap.parse_args() | |
| os.makedirs(a.run, exist_ok=True) | |
| LOG = open(f"{a.run}/log.jsonl", "a") | |
| def log(**k): | |
| k["t"] = time.time(); LOG.write(json.dumps(k) + "\n"); LOG.flush(); print(k, flush=True) | |
| torch.manual_seed(0) | |
| torch.backends.cuda.matmul.allow_tf32 = True | |
| BASE = "IvmeLabs/Ivme-Conversate-v3.1-Base" | |
| model = AutoModelForCausalLM.from_pretrained(BASE, trust_remote_code=True, dtype=torch.float32).cuda() | |
| tok = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True) | |
| TX = torch.from_numpy(np.load(f"{a.data}/train_x.npy")); TY = torch.from_numpy(np.load(f"{a.data}/train_y.npy")) | |
| VX = torch.from_numpy(np.load(f"{a.data}/val_x.npy")); VY = torch.from_numpy(np.load(f"{a.data}/val_y.npy")) | |
| steps_per_epoch = len(TX) // a.bs | |
| total = int(steps_per_epoch * a.epochs) | |
| muon_p, adam_p = [], [] | |
| for n, p in model.named_parameters(): | |
| (muon_p if p.ndim == 2 and "tok_embed" not in n and "lm_head" not in n else adam_p).append(p) | |
| opt_m = torch.optim.Muon(muon_p, lr=a.muon_lr, weight_decay=a.wd, momentum=0.95, adjust_lr_fn="match_rms_adamw") | |
| opt_a = torch.optim.AdamW(adam_p, lr=a.adam_lr, betas=(0.9, 0.95), weight_decay=0.0) | |
| for o in (opt_m, opt_a): | |
| for g in o.param_groups: g["base_lr"] = g["lr"] | |
| log(event="start", total_steps=total, steps_per_epoch=steps_per_epoch, train_seqs=len(TX), | |
| muon_params=sum(p.numel() for p in muon_p), adam_params=sum(p.numel() for p in adam_p), args=vars(a)) | |
| def lr_mult(s): # warmup -> stable -> linear decay to 0 (WSD) | |
| if s < a.warmup: return (s + 1) / a.warmup | |
| d0 = int(total * (1 - a.decay_frac)) | |
| return 1.0 if s < d0 else max(0.0, (total - s) / max(1, total - d0)) | |
| cmodel = torch.compile(model) | |
| def loss_fn(x, y): | |
| with torch.autocast("cuda", dtype=torch.bfloat16): | |
| logits = cmodel(x).logits | |
| # shift: predict y[t+1] from x[..t] | |
| yt = y[:, 1:].reshape(-1) | |
| l = F.cross_entropy(logits[:, :-1].float().reshape(-1, logits.size(-1)), yt, ignore_index=-100, reduction="none") | |
| w = (yt != -100).float() * torch.where(yt == 0, a.eot_w, 1.0) | |
| return (l * w).sum() / w.sum() | |
| def evaluate(): | |
| model.eval(); tot, n = 0.0, 0 | |
| for i in range(0, len(VX), a.bs): | |
| x, y = VX[i:i + a.bs].cuda().long(), VY[i:i + a.bs].cuda().long() | |
| k = (y[:, 1:] != -100).sum().item(); tot += loss_fn(x, y).item() * k; n += k | |
| model.train(); return tot / n | |
| def save(path): | |
| model.save_pretrained(path); tok.save_pretrained(path) | |
| json.dump({"format": "<|endoftext|>User: {msg}\\n\\nAssistant: {reply}<|endoftext|>User: {msg2}\\n\\nAssistant: {reply2}<|endoftext|>", | |
| "stop": ["<|endoftext|>"]}, open(f"{path}/chat_format.json", "w"), indent=1) | |
| v0 = evaluate(); log(event="eval", step=0, val_loss=v0); best = v0 | |
| g = torch.Generator().manual_seed(0); perm = torch.randperm(len(TX), generator=g); pi = 0 | |
| model.train(); t_last, tok_count = time.time(), 0 | |
| for step in range(total): | |
| if pi + a.bs > len(perm): perm = torch.randperm(len(TX), generator=g); pi = 0 | |
| idx = perm[pi:pi + a.bs]; pi += a.bs | |
| x, y = TX[idx].cuda(non_blocking=True).long(), TY[idx].cuda(non_blocking=True).long() | |
| m = lr_mult(step) | |
| for o in (opt_m, opt_a): | |
| for gr in o.param_groups: gr["lr"] = gr["base_lr"] * m | |
| loss = loss_fn(x, y); loss.backward() | |
| gn = torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0) | |
| opt_m.step(); opt_a.step(); opt_m.zero_grad(set_to_none=True); opt_a.zero_grad(set_to_none=True) | |
| tok_count += x.numel() | |
| if step % 10 == 0: | |
| dt = time.time() - t_last | |
| log(event="train", step=step, loss=loss.item(), gnorm=gn.item(), lr_mult=m, tok_s=tok_count / dt, | |
| epoch=step / steps_per_epoch) | |
| t_last, tok_count = time.time(), 0 | |
| if (step + 1) % a.eval_every == 0 or step == total - 1: | |
| v = evaluate(); log(event="eval", step=step + 1, val_loss=v) | |
| if v < best: best = v; save(f"{a.run}/best") | |
| save(f"{a.run}/final"); log(event="done", best_val=best) | |