Text Generation
Transformers
Safetensors
GGUF
lfm3
liquid
depth-loop
training-free
custom_code
conversational
Instructions to use vaultpls/LFM3-1.7B-Looped with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vaultpls/LFM3-1.7B-Looped with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="vaultpls/LFM3-1.7B-Looped", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("vaultpls/LFM3-1.7B-Looped", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("vaultpls/LFM3-1.7B-Looped", trust_remote_code=True, device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use vaultpls/LFM3-1.7B-Looped with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf vaultpls/LFM3-1.7B-Looped:Q8_0 # Run inference directly in the terminal: llama cli -hf vaultpls/LFM3-1.7B-Looped:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf vaultpls/LFM3-1.7B-Looped:Q8_0 # Run inference directly in the terminal: llama cli -hf vaultpls/LFM3-1.7B-Looped:Q8_0
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf vaultpls/LFM3-1.7B-Looped:Q8_0 # Run inference directly in the terminal: ./build/bin/llama cli -hf vaultpls/LFM3-1.7B-Looped:Q8_0
Use Docker
docker model run hf.co/vaultpls/LFM3-1.7B-Looped:Q8_0
- Llama new
- LM Studio
- Jan
- vLLM
How to use vaultpls/LFM3-1.7B-Looped with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "vaultpls/LFM3-1.7B-Looped" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vaultpls/LFM3-1.7B-Looped", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/vaultpls/LFM3-1.7B-Looped:Q8_0
- SGLang
How to use vaultpls/LFM3-1.7B-Looped 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 "vaultpls/LFM3-1.7B-Looped" \ --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": "vaultpls/LFM3-1.7B-Looped", "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 "vaultpls/LFM3-1.7B-Looped" \ --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": "vaultpls/LFM3-1.7B-Looped", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use vaultpls/LFM3-1.7B-Looped with Ollama:
ollama run hf.co/vaultpls/LFM3-1.7B-Looped:Q8_0
- Unsloth Desktop
- Pi
How to use vaultpls/LFM3-1.7B-Looped with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf vaultpls/LFM3-1.7B-Looped:Q8_0
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:9931/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "vaultpls/LFM3-1.7B-Looped:Q8_0" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use vaultpls/LFM3-1.7B-Looped with Docker Model Runner:
docker model run hf.co/vaultpls/LFM3-1.7B-Looped:Q8_0
- Lemonade
How to use vaultpls/LFM3-1.7B-Looped with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull vaultpls/LFM3-1.7B-Looped:Q8_0
Run and chat with the model
lemonade run user.LFM3-1.7B-Looped-Q8_0
List all available models
lemonade list
- Hermes Agent
How to use vaultpls/LFM3-1.7B-Looped with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf vaultpls/LFM3-1.7B-Looped:Q8_0
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:9931/v1 hermes config set model.default vaultpls/LFM3-1.7B-Looped:Q8_0
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use vaultpls/LFM3-1.7B-Looped with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf vaultpls/LFM3-1.7B-Looped:Q8_0
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:9931/v1 \ --custom-model-id "vaultpls/LFM3-1.7B-Looped:Q8_0" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
File size: 7,311 Bytes
830e33a | 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 | #!/usr/bin/env python3
"""Training-free loop, GGUF edition: repeat a mid-stack window `REPS` times with
each application damped by `ALPHA` (default 1/REPS), physically duplicating the
window's tensors.
The damping lives in the sandwich norms (`post_attention_norm`, `post_ffw_norm`):
both HF and llama.cpp apply them as RMSNorm on the branch output before the
residual add, so scaling those f32 vectors scales that application's residual
step by exactly ALPHA.
usage: loop_gguf_k.py SRC.gguf DST.gguf A B REPS [ALPHA]
"""
import os, struct, sys
from collections import OrderedDict
import numpy as np
SRC = sys.argv[1]
DST = sys.argv[2]
A, B = int(sys.argv[3]), int(sys.argv[4])
REPS = int(sys.argv[5]) if len(sys.argv) > 5 else 2
ALPHA = float(sys.argv[6]) if len(sys.argv) > 6 else 1.0 / REPS
T = {0: '<B', 1: '<b', 2: '<H', 3: '<h', 4: '<I', 5: '<i', 6: '<f', 7: '<?', 10: '<Q', 11: '<q', 12: '<d'}
SZ = {'<B': 1, '<b': 1, '<H': 2, '<h': 2, '<I': 4, '<i': 4, '<f': 4, '<?': 1, '<Q': 8, '<q': 8, '<d': 8}
PER_LAYER = ('lfm3.attention.head_count_kv', 'lfm3.attention.sliding_window_pattern')
class R:
def __init__(self, f): self.f = f
def raw(self, n):
b = self.f.read(n)
if len(b) != n: raise EOFError(f"want {n} got {len(b)}")
return b
def u32(self): return struct.unpack('<I', self.raw(4))[0]
def u64(self): return struct.unpack('<Q', self.raw(8))[0]
def s(self):
n = self.u64(); return self.raw(n)
f = open(SRC, 'rb'); r = R(f)
assert r.raw(4) == b'GGUF'
ver = r.u32(); n_tensors = r.u64(); n_kv = r.u64()
def read_kv(r):
key = r.s().decode(); t = r.u32(); et0 = None
if t == 8:
val = r.s()
elif t == 9:
et = r.u32(); n = r.u64(); et0 = et; vals = []
for _ in range(n):
if et == 8: vals.append(r.s())
elif et == 4: vals.append(struct.unpack('<I', r.raw(4))[0])
elif et == 5: vals.append(struct.unpack('<i', r.raw(4))[0])
elif et == 6: vals.append(struct.unpack('<f', r.raw(4))[0])
elif et == 10: vals.append(struct.unpack('<Q', r.raw(8))[0])
elif et == 7: vals.append(struct.unpack('<?', r.raw(1))[0])
else: raise ValueError(f"array elem type {et}")
val = vals
else:
val = struct.unpack(T[t], r.raw(SZ[T[t]]))[0]
return key, t, val, et0
kvs = [read_kv(r) for _ in range(n_kv)]
kvmap = {k: (t, v) for k, t, v, _e in kvs}
n_layer = kvmap['lfm3.block_count'][1]
alignment = kvmap.get('general.alignment', (6, 32))[1]
assert 0 <= A <= B < n_layer
W = B - A + 1
NEW = (REPS - 1) * W
tensors = []
for _ in range(n_tensors):
name = r.s().decode(); nd = r.u32()
dims = [struct.unpack('<Q', r.raw(8))[0] for _ in range(nd)]
tt = r.u32(); off = r.u64()
tensors.append([name, dims, tt, off])
data_start = (f.tell() + alignment - 1) // alignment * alignment
data_len = os.path.getsize(SRC) - data_start
order = sorted(range(len(tensors)), key=lambda i: tensors[i][3])
nbytes = {}
for j, i in enumerate(order):
nxt = tensors[order[j + 1]][3] if j + 1 < len(order) else data_len
nbytes[i] = nxt - tensors[i][3]
# ---- output tensor order: non-block tensors, layers 0..B, window copies, rest
src_idx, out_names, scale = [], [], []
for i, (name, dims, tt, off) in enumerate(tensors):
if not name.startswith('blk.'):
src_idx.append(i); out_names.append(name); scale.append(1.0)
def layer_tensors(il):
return [j for j, t in enumerate(tensors) if t[0].startswith(f'blk.{il}.')]
def shifted(name, k):
p = name.split('.')
if p[0] == 'blk': p[1] = str(int(p[1]) + k)
return '.'.join(p)
def is_norm(name):
return name.endswith('post_attention_norm.weight') or name.endswith('post_ffw_norm.weight')
for il in range(n_layer):
for j in layer_tensors(il):
nm = tensors[j][0]
src_idx.append(j)
out_names.append(nm if il <= B else shifted(nm, NEW))
# damp the original window applications too
scale.append(ALPHA if (A <= il <= B and is_norm(nm)) else 1.0)
if il == B:
for rep in range(REPS - 1):
for lay in range(A, B + 1):
for j in layer_tensors(lay):
nm = tensors[j][0]
src_idx.append(j); out_names.append(shifted(nm, NEW))
scale.append(ALPHA if is_norm(nm) else 1.0)
assert len(src_idx) == len(out_names) == len(scale)
new_kvs = []
for k, t, v, et0 in kvs:
if k == 'lfm3.block_count':
new_kvs.append((k, t, n_layer + NEW, et0))
elif k in PER_LAYER:
assert len(v) == n_layer, (k, len(v), n_layer)
nv = list(v[:B + 1]) + [v[i] for _ in range(REPS - 1) for i in range(A, B + 1)] + list(v[B + 1:])
assert len(nv) == n_layer + NEW, (k, len(nv))
new_kvs.append((k, t, nv, et0))
else:
new_kvs.append((k, t, v, et0))
def enc_s(s):
b = s.encode() if isinstance(s, str) else s
return struct.pack('<Q', len(b)) + b
def enc_kv(k, t, v, et0):
out = enc_s(k) + struct.pack('<I', t)
if t == 8:
out += enc_s(v)
elif t == 9:
et = et0 if et0 is not None else 8
out += struct.pack('<I', et) + struct.pack('<Q', len(v))
for x in v:
if et == 8: out += enc_s(x)
elif et == 4: out += struct.pack('<I', int(x))
elif et == 5: out += struct.pack('<i', int(x))
elif et == 6: out += struct.pack('<f', x)
elif et == 10: out += struct.pack('<Q', int(x))
elif et == 7: out += struct.pack('<?', bool(x))
else:
out += struct.pack(T[t], v)
return out
new_off, cur = [], 0
for j, si in enumerate(src_idx):
cur = (cur + alignment - 1) // alignment * alignment
new_off.append(cur)
cur += nbytes[si]
hdr = bytearray(b'GGUF' + struct.pack('<I', ver))
hdr += struct.pack('<Q', len(src_idx)) + struct.pack('<Q', len(new_kvs))
for k, t, v, et0 in new_kvs:
hdr += enc_kv(k, t, v, et0)
for j, si in enumerate(src_idx):
nm, dm, tt, o2 = tensors[si]
hdr += enc_s(out_names[j]) + struct.pack('<I', len(dm))
for d in dm:
hdr += struct.pack('<Q', d)
hdr += struct.pack('<I', tt) + struct.pack('<Q', new_off[j])
pad = (-len(hdr)) % alignment
print(f"layers {n_layer} -> {n_layer + NEW} window [{A}-{B}] x{REPS} alpha={ALPHA:.4f}")
print(f"tensors {n_tensors} -> {len(src_idx)} data {data_len/1e9:.3f} -> {cur/1e9:.3f} GB")
with open(DST, 'wb') as o:
o.write(hdr); o.write(b'\x00' * pad)
base = o.tell()
assert (base + new_off[0]) % alignment == 0
for j, si in enumerate(src_idx):
want = base + new_off[j]
assert o.tell() <= want
o.write(b'\x00' * (want - o.tell()))
f.seek(data_start + tensors[si][3])
if scale[j] != 1.0:
tt = tensors[si][2]
assert tt == 0, f"damped tensor {out_names[j]} is type {tt}, expected f32"
buf = np.frombuffer(f.read(nbytes[si]), dtype=np.float32) * np.float32(scale[j])
o.write(buf.astype(np.float32).tobytes())
else:
left = nbytes[si]
while left:
chunk = f.read(min(left, 32 << 20))
if not chunk: raise EOFError
o.write(chunk); left -= len(chunk)
print("wrote", DST, os.path.getsize(DST), "bytes")
|