Text Classification
Transformers
Safetensors
GGUF
English
lfm3_vl
feature-extraction
rag
hallucination-detection
groundedness
faithfulness
ragtruth
verifier
lora
d1
lfm3
decision-model
custom_code
Eval Results (legacy)
conversational
Instructions to use landtml/d1-2B-RAG-Verifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use landtml/d1-2B-RAG-Verifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="landtml/d1-2B-RAG-Verifier", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModel processor = AutoProcessor.from_pretrained("landtml/d1-2B-RAG-Verifier", trust_remote_code=True) model = AutoModel.from_pretrained("landtml/d1-2B-RAG-Verifier", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] 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
- llama.cpp
How to use landtml/d1-2B-RAG-Verifier 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 landtml/d1-2B-RAG-Verifier:Q8_0 # Run inference directly in the terminal: llama cli -hf landtml/d1-2B-RAG-Verifier:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf landtml/d1-2B-RAG-Verifier:Q8_0 # Run inference directly in the terminal: llama cli -hf landtml/d1-2B-RAG-Verifier: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 landtml/d1-2B-RAG-Verifier:Q8_0 # Run inference directly in the terminal: ./build/bin/llama cli -hf landtml/d1-2B-RAG-Verifier:Q8_0
Use Docker
docker model run hf.co/landtml/d1-2B-RAG-Verifier:Q8_0
- Llama new
- LM Studio
- Jan
- Ollama
How to use landtml/d1-2B-RAG-Verifier with Ollama:
ollama run hf.co/landtml/d1-2B-RAG-Verifier:Q8_0
- Unsloth Desktop
- Pi
How to use landtml/d1-2B-RAG-Verifier with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf landtml/d1-2B-RAG-Verifier: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:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "landtml/d1-2B-RAG-Verifier:Q8_0" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use landtml/d1-2B-RAG-Verifier with Docker Model Runner:
docker model run hf.co/landtml/d1-2B-RAG-Verifier:Q8_0
- Lemonade
How to use landtml/d1-2B-RAG-Verifier with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull landtml/d1-2B-RAG-Verifier:Q8_0
Run and chat with the model
lemonade run user.d1-2B-RAG-Verifier-Q8_0
List all available models
lemonade list
- Hermes Agent
How to use landtml/d1-2B-RAG-Verifier with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf landtml/d1-2B-RAG-Verifier: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:8080/v1 hermes config set model.default landtml/d1-2B-RAG-Verifier:Q8_0
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use landtml/d1-2B-RAG-Verifier with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf landtml/d1-2B-RAG-Verifier: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:8080/v1 \ --custom-model-id "landtml/d1-2B-RAG-Verifier: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,700 Bytes
8d9bafb | 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 | """Parameter-free readouts over a row's state positions, with BOS0 for nothing."""
from __future__ import annotations
import math
from bisect import bisect_right
from dataclasses import dataclass
import torch
import torch.nn.functional as F
from .json_spans import json_text, string_paths # torch-free, so code without torch reads spans too
SPAN_CAPS = {"text": 512, "number": 32, "date": 32} # a read's longest span, in tokens
@dataclass(frozen=True)
class StatePositions:
"""Token positions mapped to the caller's rendered state; None means not a text position."""
text: str
offsets: tuple[tuple[int, int] | None, ...]
paths: tuple[tuple[int, int, str], ...] = ()
@property
def valid(self) -> list[bool]:
return [i == 0 or span is not None for i, span in enumerate(self.offsets)]
@property
def pointer_mask(self) -> list[bool]:
"""`valid` up to its last valid position: the keys a read's pointer scores."""
valid = self.valid
return valid[:max(i for i, v in enumerate(valid) if v) + 1]
def read(self, first: int, last: int, max_tokens: int = SPAN_CAPS["text"]) -> dict:
if first == last == 0:
return {"text": None, "span": None}
if not 0 < first <= last < len(self.offsets) or last - first >= max_tokens:
raise ValueError("invalid pointer endpoints")
a, b = self.offsets[first], self.offsets[last]
if a is None or b is None:
raise ValueError("pointer leaves the state text")
span = [a[0], b[1]]
# A token can carry what is around a value: the separating space, or a JSON string's quote (` €",`). Trim
# boundary space and clip to the one string the span starts or ends in; never alter a character inside.
while span[0] < span[1] and self.text[span[0]].isspace():
span[0] += 1
while span[1] > span[0] and self.text[span[1] - 1].isspace():
span[1] -= 1
held = [(start, end, p) for start, end, p in self.paths if start < span[1] and span[0] < end]
if len(held) == 1:
start, end, path = held[0]
span = [max(span[0], start), min(span[1], end)]
# inside one JSON string: the caller's characters, not their escapes
return {"text": json_text(self.text[slice(*span)]), "span": span, "path": path}
return {"text": self.text[slice(*span)], "span": span}
def state_positions(
tokenizer, state, prefix: str, full_text: str, style: str = "json_only", *, encoded=None
) -> StatePositions:
"""Align one unchanged rendered prompt to text tokens; template, picture and question tokens stay invalid."""
from .prompt import plain_offsets, question_header, state_block, state_text
if not full_text.startswith(prefix):
raise ValueError("the tokenized prompt must start with the state prefix")
if state is None:
body, escaped, boundaries = "", "", [0]
start = len(prefix)
else:
body = state_block(state, style)
escaped, boundaries = plain_offsets(tokenizer, body)
tail = escaped + "\n" + question_header(tokenizer, state)
if not prefix.endswith(tail):
raise ValueError("state rendering differs from the prompt prefix")
start = len(prefix) - len(tail)
encoded = (
tokenizer(full_text, add_special_tokens=False, return_offsets_mapping=True) if encoded is None else encoded
)
text = state_text(state, style) if state is not None else "" # the blank line after it is the template's
stop = start + bisect_right(boundaries, len(text)) - 1
offsets = []
for a, b in encoded["offset_mapping"]:
span = None
lo, hi = max(a, start), min(b, stop)
if lo < hi and not full_text[a:lo].strip() and not full_text[hi:b].strip():
left, right = boundaries[lo - start], boundaries[hi - start]
if left < right <= len(text) and text[left:right].strip():
span = (left, right)
offsets.append(span)
if not offsets or offsets[0] is not None:
raise ValueError("position 0 must be a template token for the nothing readout")
paths = (
string_paths(text)
if state is not None and not isinstance(state, str) and style.endswith("_only") and style.startswith("json")
else []
)
return StatePositions(text, tuple(offsets), tuple(paths))
def position_logits(query: torch.Tensor, state: torch.Tensor, valid: torch.Tensor) -> torch.Tensor:
"""[B, slots, D] against [B, T, D], sharing state keys between questions; valid [B, T], boolean, includes BOS0."""
dtype = torch.float64 if query.dtype == state.dtype == torch.float64 else torch.float32
logits = torch.bmm(query.to(dtype), state.to(dtype).transpose(1, 2)) / math.sqrt(query.shape[-1])
return logits.masked_fill(~valid[:, None], -torch.inf)
def read_logits(hidden: torch.Tensor, states: torch.Tensor, plan: dict) -> torch.Tensor:
"""The flat read slots of a mixed batch; queries share each retained state's keys."""
device = hidden.device
query = hidden[plan["queries"].to(device)]
logits = position_logits(query, states, plan["valid"].to(device))
return logits[plan["query_row"].to(device), plan["query_col"].to(device)]
def query_plan(rows: list[int], masks: list[torch.Tensor], slots: list[int], count: int) -> dict:
"""The read slots of a batch of `count` slots, grouped by their row's state: each state's keys shared by its
queries; `code_slots`, the other slots, which the LM head reads."""
unique = sorted(set(rows))
index = {r: i for i, r in enumerate(unique)}
width = max(map(len, masks))
valid = torch.zeros(len(unique), width, dtype=torch.bool)
groups = [[] for _ in unique]
row_index, column_index = [], []
for slot, row, keep in zip(slots, rows, masks):
r = index[row]
if groups[r] and not torch.equal(valid[r, : len(keep)], keep):
raise ValueError("read questions must share their state-position mask")
valid[r, : len(keep)] = keep
row_index.append(r)
column_index.append(len(groups[r]))
groups[r].append(slot)
queries = torch.zeros(len(unique), max(map(len, groups)), dtype=torch.long)
for r, group in enumerate(groups):
queries[r, : len(group)] = torch.tensor(group)
return dict(
rows=torch.tensor(unique),
width=width,
queries=queries,
valid=valid,
query_row=torch.tensor(row_index),
query_col=torch.tensor(column_index),
slots=torch.tensor(slots),
code_slots=torch.tensor(sorted(set(range(count)) - set(slots)), dtype=torch.long),
)
def spans(logits: torch.Tensor, max_tokens: int = SPAN_CAPS["text"]) -> tuple[torch.Tensor, torch.Tensor]:
"""Each read's span from its start and end scores [R, 2, T]: found when P(found) >= 0.5, then the likeliest span
within `max_tokens`; (0, 0) for nothing."""
logp = logits.log_softmax(-1)
start, end = logp.unbind(1)
found = -torch.expm1(start[:, 0])
if logits.shape[2] == 1:
return torch.zeros(logits.shape[0], 2, dtype=torch.long, device=logits.device), found
cap = min(max_tokens, logits.shape[2] - 1)
windows, indices = F.max_pool1d(
F.pad(end[:, None, 1:], (0, cap - 1), value=-torch.inf), cap, stride=1, return_indices=True
)
scores = start[:, 1:] + windows[:, 0]
index = scores.argmax(-1)
first = index + 1
last = indices[:, 0].gather(1, index[:, None])[:, 0] + 1
at = torch.stack((first, last), -1)
nothing = found < 0.5
return torch.where(nothing[:, None], torch.zeros_like(at), at), found
|