Text Generation
Transformers
ONNX
English
French
agentic
function-calling
tool-use
structured-generation
orchestration
code-agent
mcp
edge
small-language-model
Eval Results (legacy)
Run this model with HF Jobs
Run AMFORGE/samg-cobratooling on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/AMFORGE/samg-cobratooling. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/AMFORGE/samg-cobratooling on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/AMFORGE/samg-cobratooling. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/AMFORGE/samg-cobratooling. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use AMFORGE/samg-cobratooling with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AMFORGE/samg-cobratooling with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AMFORGE/samg-cobratooling")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("AMFORGE/samg-cobratooling", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use AMFORGE/samg-cobratooling with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AMFORGE/samg-cobratooling" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AMFORGE/samg-cobratooling", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/AMFORGE/samg-cobratooling
- SGLang
How to use AMFORGE/samg-cobratooling 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 "AMFORGE/samg-cobratooling" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AMFORGE/samg-cobratooling", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "AMFORGE/samg-cobratooling" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AMFORGE/samg-cobratooling", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use AMFORGE/samg-cobratooling with Docker Model Runner:
docker model run hf.co/AMFORGE/samg-cobratooling
ONNX release (BSL-1.1): add run_samg_onnx.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188"""Minimal SAM-G ONNX runner — DRAFT, NOT PUBLISHED.
Runs a SAM-G structured-action model exported to ONNX, with theSentencePiece tokenizer loaded from an already-compiled .model file.
What it needs (local files, no Hugging Face account, no torch): - samg-cobratooling.onnx (+ samg-cobratooling.onnx.data in the same folder) - samg_tokenizer.model
Usage: python run_samg_onnx.py --onnx samg-cobratooling.onnx \ --tokenizer samg_tokenizer.model \ --task "open src/main.js and run the tests"
The model answers with a JSON plan, e.g. [{"op": "open_file", "args": {"path": "src/main.js"}, "risk": "safe"}]
Prompt format (from the model card): routing: "<instruction> [ACTION]" reactive: "<instruction> | {<observation JSON>} [ACTION]"
Generation loop (sampling, EOS, guarded stop on a balanced [...] block)lives here in Python; the ONNX file only computes forward logits."""import argparseimport jsonimport osimport time
import numpy as np
# ---------------------------------------------------------------------------# Tokenizer — LOADING ONLY (SentencePiece, from a compiled .model file)# ---------------------------------------------------------------------------class Tokenizer: def __init__(self, model_path): import sentencepiece as spm if not os.path.exists(model_path): raise FileNotFoundError(f"Tokenizer file not found: {model_path}") self.sp = spm.SentencePieceProcessor() self.sp.Load(model_path) self.pad_id = self.sp.pad_id() if self.sp.pad_id() >= 0 else 0 self.eos_id = self.sp.eos_id() if self.sp.eos_id() >= 0 else 2
def encode(self, text): return self.sp.EncodeAsIds(text)
def decode(self, ids): return self.sp.DecodeIds([i for i in ids if i >= 0])
# ---------------------------------------------------------------------------# Guarded decoding — stops on a balanced [...] JSON block# ---------------------------------------------------------------------------class JSONStateTracker: def __init__(self): self.depth_sq = 0 self.depth_curly = 0 self.in_string = False self.escape_next = False self.started = False self.completed = False self.buffer = ""
def feed(self, text): for ch in text: self.buffer += ch if self.escape_next: self.escape_next = False continue if ch == "\\" and self.in_string: self.escape_next = True continue if ch == '"': self.in_string = not self.in_string continue if self.in_string: continue if ch == "[": self.depth_sq += 1 self.started = True elif ch == "]": self.depth_sq -= 1 elif ch == "{": self.depth_curly += 1 elif ch == "}": self.depth_curly -= 1 if self.started and self.depth_sq == 0 and self.depth_curly == 0: self.completed = True return True return False
# ---------------------------------------------------------------------------# ONNX model — forward logits only# ---------------------------------------------------------------------------class SamgOnnx: def __init__(self, onnx_path, max_seq_len=1024): import onnxruntime as ort if not os.path.exists(onnx_path): raise FileNotFoundError(f"ONNX file not found: {onnx_path}") data_path = onnx_path + ".data" if not os.path.exists(data_path): raise FileNotFoundError( f"ONNX weights file not found: {data_path} " "(keep the .onnx and .onnx.data files together)") self.sess = ort.InferenceSession( onnx_path, providers=["CPUExecutionProvider"]) self.max_seq_len = max_seq_len
def logits(self, ids): arr = np.array([ids], dtype=np.int64) return self.sess.run(["logits"], {"idx": arr})[0]
def generate(self, tokenizer, prompt, max_new_tokens=384, temperature=0.7, top_k=1): ids = tokenizer.encode(prompt) tracker = JSONStateTracker() for _ in range(max_new_tokens): ctx = ids[-self.max_seq_len:] logits = self.logits(ctx)[0, -1, :].astype(np.float64) logits = logits / max(temperature, 1e-6) if top_k > 0: thresh = np.sort(logits)[-min(top_k, logits.size)] logits[logits < thresh] = -np.inf probs = np.exp(logits - logits.max()) probs = probs / probs.sum() nxt = int(np.random.choice(len(probs), p=probs)) ids.append(nxt) if nxt == tokenizer.eos_id: break if tracker.feed(tokenizer.decode([nxt])): break out_ids = ids[len(tokenizer.encode(prompt)):] if tokenizer.eos_id in out_ids: out_ids = out_ids[:out_ids.index(tokenizer.eos_id)] raw = tokenizer.decode(out_ids).strip() if "[" in raw and "]" in raw: raw = raw[raw.index("["):raw.rindex("]") + 1] return raw
def build_prompt(task, observation=None): if observation is not None: obs = observation if isinstance(observation, str) else json.dumps( observation, separators=(",", ":")) return f"{task} | {obs} [ACTION]" return f"{task} [ACTION]"
def main(): parser = argparse.ArgumentParser(description="SAM-G ONNX runner") parser.add_argument("--onnx", required=True) parser.add_argument("--tokenizer", required=True) parser.add_argument("--task", required=True) parser.add_argument("--observation", default=None) parser.add_argument("--max-new-tokens", type=int, default=384) parser.add_argument("--temperature", type=float, default=0.7) parser.add_argument("--top-k", type=int, default=1) args = parser.parse_args()
tok = Tokenizer(args.tokenizer) model = SamgOnnx(args.onnx) obs = None if args.observation: try: obs = json.loads(args.observation) except Exception: obs = args.observation prompt = build_prompt(args.task, obs) t0 = time.time() raw = model.generate(tok, prompt, args.max_new_tokens, args.temperature, args.top_k) latency_ms = round((time.time() - t0) * 1000, 1) ops, valid = None, False try: ops = json.loads(raw) valid = True except Exception: pass print(json.dumps({"ops": ops, "valid": valid, "latency_ms": latency_ms, "raw": raw, "prompt": prompt}, indent=2, ensure_ascii=False))
if __name__ == "__main__": main()run_samg_onnx.pyAdded+188