Text Generation
Transformers
Chinese
English
character-level
chinese
gru
mamba
Mixture of Experts
titans
Instructions to use masterofthestars/tianxuan with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use masterofthestars/tianxuan with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="masterofthestars/tianxuan")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("masterofthestars/tianxuan", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use masterofthestars/tianxuan with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "masterofthestars/tianxuan" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "masterofthestars/tianxuan", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/masterofthestars/tianxuan
- SGLang
How to use masterofthestars/tianxuan 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 "masterofthestars/tianxuan" \ --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": "masterofthestars/tianxuan", "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 "masterofthestars/tianxuan" \ --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": "masterofthestars/tianxuan", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use masterofthestars/tianxuan with Docker Model Runner:
docker model run hf.co/masterofthestars/tianxuan
File size: 12,367 Bytes
db7bc06 | 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 | import { AuditLog } from "./audit";
import { Blackboard } from "./blackboard";
import { HealthMonitor } from "./health";
import { OnDemandEconomics } from "./economics";
import { CollaborationProbe } from "./probe";
import { Registry } from "./registry";
import { Task, TaskResult, ForwardState } from "./types";
export interface ExecutorOptions {
/** 置信度低于该值,在预算内继续扩深 */
cascadeThreshold?: number;
/** 中央神经点火低于该值(且样本数≥warmup) → 预算转向跳过该深度 */
coldThreshold?: number;
/** 点火评估暖机样本数 */
warmup?: number;
/** 最大执行深度 (默认4) */
maxDepth?: number;
/** 是否启用审计 (默认true) */
enableAudit?: boolean;
/** 是否启用探针 (默认true) */
enableProbe?: boolean;
}
/** 默认配置 */
export const DEFAULT_EXECUTOR_OPTIONS: ExecutorOptions = {
cascadeThreshold: 0.6,
coldThreshold: 0.15,
warmup: 8,
maxDepth: 4,
enableAudit: true,
enableProbe: true,
};
/**
* MoD(Mixture-of-Depths)式执行器
* 共享同一模型: 按任务复杂度决定初始深度,置信不足则在预算内扩展深度
* 不做"小网/大网"两套网络,路径裁剪替代网络复制(依据 DeepMind MoD 论文)
*/
export class Executor {
private readonly cascadeThreshold: number;
private readonly coldThreshold: number;
private readonly warmup: number;
private readonly maxDepth: number;
private readonly enableAudit: boolean;
private readonly enableProbe: boolean;
/** 健康监控 (宪章第4条): 心跳/NaN 降级, 默认自建 */
readonly health: HealthMonitor;
/** 按需调用经济性探针 (宪章第8条): 真实调用成本/置信度增量记录 */
readonly economics: OnDemandEconomics;
constructor(
private readonly registry: Registry,
private readonly blackboard: Blackboard,
private readonly audit: AuditLog,
private readonly probe: CollaborationProbe,
options: ExecutorOptions = {},
health?: HealthMonitor,
economics?: OnDemandEconomics,
) {
this.cascadeThreshold = options.cascadeThreshold ?? DEFAULT_EXECUTOR_OPTIONS.cascadeThreshold!;
this.coldThreshold = options.coldThreshold ?? DEFAULT_EXECUTOR_OPTIONS.coldThreshold!;
this.warmup = options.warmup ?? DEFAULT_EXECUTOR_OPTIONS.warmup!;
this.maxDepth = options.maxDepth ?? DEFAULT_EXECUTOR_OPTIONS.maxDepth!;
this.enableAudit = options.enableAudit ?? DEFAULT_EXECUTOR_OPTIONS.enableAudit!;
this.enableProbe = options.enableProbe ?? DEFAULT_EXECUTOR_OPTIONS.enableProbe!;
this.health = health ?? new HealthMonitor(registry, audit);
this.economics = economics ?? new OnDemandEconomics();
}
async execute(task: Task): Promise<TaskResult> {
const state = this.blackboard.worldState();
const fullCost = this.registry.computeUnits(task.type).reduce((s, u) => s + u.cost, 0);
// L0 — 记忆直出
// [P0-B 修复 2026-10-08 第一性审核] 命中键绑定「上下文指纹」而非任务序号 —
// 旧键 `mem:${task.id}` 在 generate() 入口从 m0 重编号, 黑板不清空 → 服务器常驻进程
// 必然用上一请求残留键制造假命中 (审核实测 m1/m2 本轮零召回却报 L0 命中)。
// 新键 `mem:<ctxFp>` 仅当「相同上下文」时命中, 不同上下文的残留键天然失效。
// ctxFp 由 engine.generate 在 task.id 中编码 (`${i}:${ctxFp}`), executor 据此读键。
const memKey = `mem:${task.id.includes(":") ? task.id.split(":").slice(1).join(":") : task.id}`;
const hit = this.blackboard.read(memKey);
if (this.registry.get("titans")?.enabled && hit !== undefined) {
// 2026-10-08 第一性审核: L0 置信度不再写死 1.0 — 由命中来源写入的点火强度推导
// (z:l0:act: titans=命中槽占比, vector/repeat 缓存=深链曾以≥0.3置信出过该字的 0.5 标记,
// engine 在命中时写入; 无写入 → 0, 冷启动不伪造满置信, 宪章第 1/7 条)
const ignition = Number(this.blackboard.read("z:l0:act") ?? 0);
const conf = Math.min(1, ignition * 2); // 点火 0.5+ → 满置信, 线性归一
this.audit.route({ taskId: task.id, depth: 0, units: [], confidence: conf, memoryHit: true });
this.economics.recordTask({
taskId: task.id, complexity: task.complexity, budget: task.budget,
actualCost: 0, fullCost, finalConf: conf, unitsRun: 0, forwards: 0, realForwards: 0, earlyStopped: false, memoryHit: true,
});
return { taskId: task.id, depth: 0, output: hit, confidence: conf, units: [], memoryHit: true };
}
const units = this.registry.computeUnits(task.type);
if (units.length === 0) {
this.audit.route({ taskId: task.id, depth: 0, units: [], confidence: 0, memoryHit: false });
this.economics.recordTask({
taskId: task.id, complexity: task.complexity, budget: task.budget,
actualCost: 0, fullCost: 0, finalConf: 0, unitsRun: 0, forwards: 0, realForwards: 0, earlyStopped: false, memoryHit: false,
});
return { taskId: task.id, depth: 0, output: undefined, confidence: 0, units: [], memoryHit: false };
}
const maxDepth = this.maxDepth;
const budget = Math.max(1, Math.min(task.budget || maxDepth, maxDepth));
let targetDepth = Math.min(maxDepth, Math.max(1, Math.round(task.complexity * maxDepth)));
const ranUnits: string[] = [];
let lastConfidence = 0;
let taskCost = 0; // 本任务实际执行单元成本之和 (按需经济性)
let taskForwards = 0; // [P1-I] 单元前向次数 (每单元 forward 含 1 次骨干前向, titans:depth0=0)
let taskRealForwards = 0; // [R1-B1] 真实 model.step = 单元前向 + 推进 advance + L0 探针 deepTop1At
const finishTask = (earlyStopped: boolean): TaskResult => {
const res = this.result(task, ranUnits, units, lastConfidence, state);
// [R1-B1] 真实 model.step = 单元前向 + 推进 advance (L0 命中步与非 L0 步都推进 1 次)
// + L0 一致性探针 deepTop1At (engine 侧当 L0 召回且探针开时 +1; executor 侧按
// memoryHit + blackboard mem 键存在近似)。旧实现 realForwards 恒 0 (未接) → 节省率失真。
const advanceCount = 1; // 每个任务收尾前必推进真实状态 1 次 (L0 命中步由 engine P0-A 分支推进)
const probeCount = res.memoryHit ? 1 : 0; // L0 命中步 engine 跑 deepTop1At 记探针 (非命中不跑)
taskRealForwards = taskForwards + advanceCount + probeCount;
this.economics.recordTask({
taskId: task.id, complexity: task.complexity, budget,
actualCost: taskCost, fullCost, finalConf: lastConfidence,
unitsRun: ranUnits.length, forwards: taskForwards, realForwards: taskRealForwards, earlyStopped, memoryHit: res.memoryHit,
});
return res;
};
for (let used = 0; used < budget && targetDepth <= maxDepth; used++) {
let next = units.find((unit) => {
if (unit.depth > targetDepth || ranUnits.includes(unit.unitId)) return false;
// [P2 修复 2026-10-13 第一性审核] 健康监控按 unitId 键控 — 旧实现按 kind 键控,
// 多单元共用 kind (gru:shallow + GRU L2) 时 NaN 计数被混算稀释。现: 精确到单元。
return !this.health.shouldSkip(unit.unitId);
});
if (!next) {
targetDepth += 1; // 该深度无单元: 预算内扩一层
used -= 1;
continue;
}
// [P1-K 修复 2026-10-08 第一性审核] sys/confBefore 在 forward 之前声明 (冷中央判定用),
// forward 之后重读当次点火值 (z:act 由单元 forward 写入, 旧实现在 forward 之前读
// 记到上一任务陈旧值/占位 0 → 首样本恒 0, 审核 P1-J/P1-K)。
const unitKind = this.registry.unitSystem(next.unitId)?.kind;
const sys = unitKind ? this.registry.get(unitKind) : undefined;
const confBefore = lastConfidence;
// 预算转向(根据多神经实际点火调整): 中央神经长期不点火 → 该深度让路, 预算留给他神经
if (sys?.roleTag === "central" && this.enableProbe && this.probe.sampleCount(next.unitId) >= this.warmup && this.probe.ignitionAvg(next.unitId, 32) < this.coldThreshold) {
if (this.enableAudit) {
this.audit.route({
taskId: task.id,
depth: next.depth,
units: [...ranUnits, next.unitId],
confidence: 0,
memoryHit: false,
note: "cold-central",
});
}
targetDepth = Math.min(maxDepth, next.depth + 1); // 让路: 跳到该深度之后
continue;
}
// 点火探针: 先 forward, 再读当次 z:act (前向写入的点火值), 保证探针记录的是本任务真实值
// [P0-A 修复 2026-10-08 第一性审核] ranUnits.push 旧实现完全缺失 — 已执行单元从不记录
// → result() 的 depth 恒 0 / units 恒空 / economics.unitsRun 恒 0 (审计记"零算力"而真实
// 跑 N 次前向, 审核 P0-A/P1-I 根因)。
// [P1-I] 每个非 L0 单元 forward 含 1 次完整骨干前向 (peekLogits)。
// titans:depth0 cost=0 但本处是「单元 forward 是否跑了深链」计数, L0 直出步
// 根本进不到单元循环 (早停返回), 故只计实际执行的单元。
taskForwards += next.cost === 0 ? 0 : 1; // 零成本单元 (titans:depth0) 不计前向
ranUnits.push(next.unitId);
const confidence = await next.forward(task, state);
lastConfidence = confidence;
// [P1-K] forward 后读取点火值 (z:act:<unitId> 由单元 forward 写入, 当次值非陈旧)
const ignition = Number(this.blackboard.read(`z:act:${next.unitId}`) ?? confBefore);
if (this.enableProbe) {
this.probe.record(task.id, next.unitId, sys?.kind ?? "?", ignition);
}
// 按需经济性: 本次调用的真实成本 + 置信度增量 (宪章第8条: 按需调用可量化)
taskCost += next.cost;
this.economics.recordUnit(task.id, next.unitId, next.cost, confBefore, confidence);
// 健康监控: 单元心跳 + NaN 降级 (宪章第4条); 非有限置信度 → 不刷新 (不降级假健康, P0-F)
// [P2 修复 2026-10-13 第一性审核] 按 unitId 刷新 — 旧按 kind, 多单元混算
if (Number.isFinite(confidence)) this.health.refresh(next.unitId, confidence);
if (this.enableAudit) {
this.audit.route({
taskId: task.id,
depth: next.depth,
units: [...ranUnits],
confidence: Number.isFinite(confidence) ? confidence : 0,
memoryHit: false,
note: Number.isFinite(confidence) ? undefined : "nan-output",
});
}
// [P0-F] 非有限置信度 → 不触发提前停止, 也不扩深 (本单元结果不可信, 交给下一层兜底)
if (Number.isFinite(confidence) && confidence >= this.cascadeThreshold) {
return finishTask(true); // 置信达标: 未耗完预算即停 (按需直接证据)
}
targetDepth = Math.min(maxDepth, next.depth + 1); // 置信不足/非有限 → 预算内扩到下一层
}
return finishTask(false);
}
/**
* [P0-A 修复 2026-10-08 第一性审核] result() 须返回「实际执行到的最大深度」
* (宪章第2条 MoD 式分级: depth=1/2/3/4 由路由实际推进, 非写死 0)。
* 旧实现 ranUnits 为空时恒 depth=0 → 所有深链任务审计记 depth=0/零算力,
* 而真实输出是 4 次完整前向 (审核 P0-A: "L0 直出在真实路径上产生输出字,
* 但审计记 depth=0/units=[]" 的同一根因)。现: 用实际推进的 targetDepth。
*/
private result(task: Task, ranUnits: string[], allUnits: { depth: number; unitId: string }[], confidence: number, state: ForwardState): TaskResult {
// 实际执行到的最大深度: ranUnits 非空 → 已执行单元的最大 depth;
// 空 (零单元, 全早停/预算 0) → 0 (真实零算力, 审计记 0 正确)
const executedDepth = ranUnits.length === 0 ? 0 : Math.max(...allUnits.filter((u) => ranUnits.includes(u.unitId)).map((u) => u.depth));
return {
taskId: task.id,
depth: executedDepth,
output: this.blackboard.read(`o:${task.id}`) ?? null,
confidence,
units: ranUnits,
memoryHit: false,
};
}
}
|