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
File size: 8,937 Bytes
53ce2f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | """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")
|