Text Generation
Transformers
English
multilingual
inkling2_loop
image-text-to-text
prime-quant
2-bit
4-bit precision
Mixture of Experts
inkling-2
inkling-2-mini
looped-transformer
triton
rocm
cuda
quantization
coding
conversational
Instructions to use batteryphil/Inkling-2-Mini-PRIME-Quant with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use batteryphil/Inkling-2-Mini-PRIME-Quant with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="batteryphil/Inkling-2-Mini-PRIME-Quant") 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)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("batteryphil/Inkling-2-Mini-PRIME-Quant") model = AutoModelForMultimodalLM.from_pretrained("batteryphil/Inkling-2-Mini-PRIME-Quant", device_map="auto") 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=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use batteryphil/Inkling-2-Mini-PRIME-Quant with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "batteryphil/Inkling-2-Mini-PRIME-Quant" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "batteryphil/Inkling-2-Mini-PRIME-Quant", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/batteryphil/Inkling-2-Mini-PRIME-Quant
- SGLang
How to use batteryphil/Inkling-2-Mini-PRIME-Quant 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 "batteryphil/Inkling-2-Mini-PRIME-Quant" \ --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": "batteryphil/Inkling-2-Mini-PRIME-Quant", "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 "batteryphil/Inkling-2-Mini-PRIME-Quant" \ --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": "batteryphil/Inkling-2-Mini-PRIME-Quant", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use batteryphil/Inkling-2-Mini-PRIME-Quant with Docker Model Runner:
docker model run hf.co/batteryphil/Inkling-2-Mini-PRIME-Quant
Add model card, Bartsch LICENSE, Apache-2.0 NOTICE, tokenizer, standalone read-only Triton runtime & verified benchmarks
53ce2f5 verified Download benchmarks/formula_parser_looptop8.py from batteryphil/Inkling-2-Mini-PRIME-Quant: direct link, hf CLI and curl.
- Browser
- Download file 8.94 kB
-
https://huggingface.co/batteryphil/Inkling-2-Mini-PRIME-Quant/resolve/main/benchmarks/formula_parser_looptop8.py
- Command line
-
hf download hf://batteryphil/Inkling-2-Mini-PRIME-Quant/benchmarks/formula_parser_looptop8.py
-
curl -L -o formula_parser_looptop8.py https://huggingface.co/batteryphil/Inkling-2-Mini-PRIME-Quant/resolve/main/benchmarks/formula_parser_looptop8.py
8.94 kB
| """formula_parser.py""" | |
| import re | |
| class FormulaError(Exception): pass | |
| class FormulaSyntaxError(Exception): pass | |
| NAMES = {"SUM", "AVG", "MIN", "MAX", "COUNT", "IF"} | |
| CMP_OPS = {"==", "!=", "<", "<=", ">", ">="} | |
| def tokenize(expr): | |
| if not isinstance(expr, str): raise FormulaSyntaxError("expr must be str") | |
| toks = []; i = 0; n = len(expr) | |
| while i < n: | |
| ch = expr[i] | |
| if ch.isspace(): i += 1; continue | |
| if ch.isdigit() or (ch == "." and i + 1 < n and expr[i+1].isdigit()): | |
| j = i | |
| while j < n and expr[j].isdigit(): j += 1 | |
| if j < n and expr[j] == ".": | |
| j += 1 | |
| while j < n and expr[j].isdigit(): j += 1 | |
| toks.append(("num", expr[i:j])); i = j; continue | |
| if ch.isalpha() or ch == "_": | |
| j = i | |
| while j < n and (expr[j].isalnum() or expr[j] == "_"): j += 1 | |
| toks.append(("name", expr[i:j])); i = j; continue | |
| for op in ("<=", ">=", "==", "!=", "<", ">", "+", "-", "*", "/", "^", "(", ")", ",", ":"): | |
| if expr.startswith(op, i): | |
| toks.append(("op", op)); i += len(op); break | |
| else: | |
| raise FormulaSyntaxError(f"invalid token at {i}") | |
| toks.append(("eof", "")) | |
| return toks | |
| def _coord_info(coord): | |
| if not isinstance(coord, str): return None | |
| m = re.fullmatch(r"([A-Za-z]+)([0-9]+)", coord) | |
| if not m: return None | |
| letters = m.group(1).upper(); row = int(m.group(2)) | |
| if row < 1: return None | |
| col = 0 | |
| for ch in letters: col = col * 26 + (ord(ch) - ord("A") + 1) | |
| return letters, row, col | |
| def normalize_coord(coord): | |
| info = _coord_info(coord) | |
| if info is None: raise FormulaSyntaxError("invalid coord") | |
| letters, row, col = info | |
| return f"{letters}{row}" | |
| def _letters(col): | |
| out = "" | |
| while col > 0: | |
| col -= 1 | |
| out = chr(ord("A") + col % 26) + out | |
| col //= 26 | |
| return out | |
| def _expand_range(node): | |
| _, s_row, s_col = _coord_info(normalize_coord(node["start"])) | |
| _, e_row, e_col = _coord_info(normalize_coord(node["end"])) | |
| cols = range(min(s_col, e_col), max(s_col, e_col) + 1) | |
| rows = range(min(s_row, e_row), max(s_row, e_row) + 1) | |
| return [f"{_letters(c)}{r}" for r in rows for c in cols] | |
| class Parser: | |
| def __init__(self, toks): self.toks = toks; self.i = 0 | |
| def peek(self): return self.toks[self.i] | |
| def next(self): | |
| t = self.toks[self.i] | |
| if self.i < len(self.toks) - 1: self.i += 1 | |
| return t | |
| def expect_op(self, op): | |
| t = self.next() | |
| if t != ("op", op): raise FormulaSyntaxError(f"expected {op}") | |
| def parse_comparison(self): | |
| left = self.parse_additive() | |
| t = self.peek() | |
| if t[0] == "op" and t[1] in CMP_OPS: | |
| op = t[1]; self.next() | |
| right = self.parse_additive() | |
| t = self.peek() | |
| if t[0] == "op" and t[1] in CMP_OPS: | |
| raise FormulaSyntaxError("non-chaining") | |
| return {"type": "cmp", "op": op, "left": left, "right": right} | |
| return left | |
| def parse_additive(self): | |
| left = self.parse_multiplicative() | |
| while self.peek() in (("op", "+"), ("op", "-")): | |
| op = self.next()[1] | |
| right = self.parse_multiplicative() | |
| left = {"type": "bin", "op": op, "left": left, "right": right} | |
| return left | |
| def parse_multiplicative(self): | |
| left = self.parse_unary() | |
| while self.peek() in (("op", "*"), ("op", "/")): | |
| op = self.next()[1] | |
| right = self.parse_unary() | |
| left = {"type": "bin", "op": op, "left": left, "right": right} | |
| return left | |
| def parse_unary(self): | |
| if self.peek() in (("op", "+"), ("op", "-")): | |
| op = self.next()[1] | |
| return {"type": "un", "op": op, "operand": self.parse_unary()} | |
| return self.parse_power() | |
| def parse_power(self): | |
| left = self.parse_atom() | |
| if self.peek() == ("op", "^"): | |
| self.next() | |
| right = self.parse_unary() | |
| return {"type": "bin", "op": "^", "left": left, "right": right} | |
| return left | |
| def parse_atom(self): | |
| t = self.next() | |
| if t[0] == "num": | |
| try: return {"type": "num", "value": float(t[1])} | |
| except ValueError: raise FormulaSyntaxError("bad number") | |
| if t == ("op", "("): | |
| node = self.parse_comparison() | |
| self.expect_op(")") | |
| return node | |
| if t[0] == "name": | |
| name = t[1].upper() | |
| if self.peek() == ("op", "("): | |
| if name not in NAMES: raise FormulaSyntaxError("unknown function") | |
| self.next() | |
| args = [] | |
| if self.peek() != ("op", ")"): | |
| args.append(self.parse_comparison()) | |
| while self.peek() == ("op", ","): | |
| self.next() | |
| if self.peek() == ("op", ")"): raise FormulaSyntaxError("trailing comma") | |
| args.append(self.parse_comparison()) | |
| if self.peek() != ("op", ")"): raise FormulaSyntaxError("expected )") | |
| self.next() | |
| if not args: raise FormulaSyntaxError("empty call") | |
| if name == "IF" and len(args) != 3: raise FormulaSyntaxError("IF arity") | |
| return {"type": "call", "name": name, "args": args} | |
| coord = normalize_coord(name) | |
| if self.peek() == ("op", ":"): | |
| self.next() | |
| t2 = self.next() | |
| if t2[0] != "name": raise FormulaSyntaxError("expected coord after :") | |
| end = normalize_coord(t2[1]) | |
| return {"type": "range", "start": coord, "end": end} | |
| return {"type": "cell", "coord": coord} | |
| raise FormulaSyntaxError("bad atom") | |
| def parse_formula(expr): | |
| p = Parser(tokenize(expr)) | |
| node = p.parse_comparison() | |
| if p.peek()[0] != "eof": raise FormulaSyntaxError("unexpected token") | |
| return node | |
| def collect_refs(node): | |
| refs = set() | |
| def visit(n): | |
| t = n.get("type") | |
| if t == "cell": refs.add(normalize_coord(n["coord"])) | |
| elif t == "range": refs.update(_expand_range(n)) | |
| elif t == "un": visit(n["operand"]) | |
| elif t in ("bin", "cmp"): visit(n["left"]); visit(n["right"]) | |
| elif t == "call": | |
| for arg in n["args"]: visit(arg) | |
| visit(node) | |
| return refs | |
| def eval_formula(node, get_val, is_populated): return _eval(node, get_val, is_populated) | |
| def _eval(node, get_val, is_populated): | |
| t = node["type"] | |
| if t == "num": return node["value"] | |
| if t == "cell": return get_val(normalize_coord(node["coord"])) | |
| if t == "range": raise FormulaError("range only valid as function argument") | |
| if t == "un": | |
| v = _eval(node["operand"], get_val, is_populated) | |
| return -v if node["op"] == "-" else v | |
| if t == "bin": | |
| lhs = _eval(node["left"], get_val, is_populated) | |
| rhs = _eval(node["right"], get_val, is_populated) | |
| op = node["op"] | |
| if op == "+": return lhs + rhs | |
| if op == "-": return lhs - rhs | |
| if op == "*": return lhs * rhs | |
| if op == "/": | |
| if rhs == 0: raise FormulaError("div by zero") | |
| return lhs / rhs | |
| if op == "^": return lhs ** rhs | |
| raise FormulaError("bad op") | |
| if t == "cmp": | |
| lhs = _eval(node["left"], get_val, is_populated) | |
| rhs = _eval(node["right"], get_val, is_populated) | |
| op = node["op"] | |
| val = {"==": lhs == rhs, "!=": lhs != rhs, "<": lhs < rhs, "<=": lhs <= rhs, ">": lhs > rhs, ">=": lhs >= rhs}[op] | |
| return 1.0 if val else 0.0 | |
| if t == "call": | |
| name = node["name"].upper() | |
| args = node["args"] | |
| if name == "IF": | |
| if len(args) != 3: raise FormulaSyntaxError("IF arity") | |
| cond = _eval(args[0], get_val, is_populated) | |
| return _eval(args[1] if cond != 0.0 else args[2], get_val, is_populated) | |
| values = [] | |
| for arg in args: | |
| if arg["type"] == "range": | |
| for coord in _expand_range(arg): | |
| if not is_populated(coord): continue | |
| values.append(get_val(coord)) | |
| else: | |
| values.append(_eval(arg, get_val, is_populated)) | |
| if name == "SUM": return sum(values) | |
| if name == "COUNT": return float(len(values)) | |
| if name == "AVG": | |
| if not values: raise FormulaError("AVG over 0 values") | |
| return sum(values) / len(values) | |
| if name == "MIN": | |
| if not values: raise FormulaError("MIN over 0 values") | |
| return min(values) | |
| if name == "MAX": | |
| if not values: raise FormulaError("MAX over 0 values") | |
| return max(values) | |
| raise FormulaSyntaxError("unknown function") | |
| raise FormulaError("unknown node") | |