返回全部资讯
蚂蚁 inclusionAI 官方仓库T1·开源与评测

SingProbe 开源冻结基座模型的 token 级探针训练框架

作者:inclusionAI原标题:⭐ inclusionAI/SingProbe (36 stars)
58AI 研判分

inclusionAI 开源 SingProbe,一个基于冻结基座模型(如 Ling-3.0-flash)多层隐藏状态的轻量 token 级探针训练框架。基座模型通过打过 token-probe 补丁的 SGLang 构建做前向推理,实时将指定层逐 token 隐藏状态写入 tmpfs,训练侧以流式方式学习并输出每 token 10 维 logits,基座全程 requires_grad=False。

报道正文

本文目录11 个章节

SingProbe

A lightweight token-level probe training framework built on the multi-layer hidden states of a frozen Base Model (e.g. Ling-3.0-flash). The frozen Base Model is served by a token-probe-patched SGLang build for forward inference, dumping the per-token hidden states of the configured layers to tmpfs in real time; the training-side SingProbe model trains on these hidden states in a streaming fashion and finally outputs 10-dim logits per token.

This repository includes the SGLang inference framework used to extract hidden states and serve trained SingProbe heads. See the token-probe quickstart for supported base models and launch commands.

The Base Model is entirely requires_grad=False and only runs inference to extract hidden states; only the probe model is trained.

Overview

文本
     Base Model (frozen, SGLang token-probe server)
prompt tokens ──► forward with identity token probe
                      │  dumps rmsnorm(hidden_states + residual) per tapped layer
                      ▼
          concat → [batch, seq, hidden_dim × num_layers]
                      │
           ┌──────────┴──────────┐
           ▼                     ▼
       GuardMLP           GuardAttnProbe
      (2-layer MLP)    (causal MQA token probe)
           │                     │
           └──────────┬──────────┘
                      ▼
         per-token logits [batch, seq, 10]

Three tasks (10-dim output, fixed)

DimsTaskNotes
0–6Query risk (multi-label)7 classes (A–G), may co-occur
7Query Safemutually exclusive with 0–6
8Response Safetylogit >0 ⇒ unsafe
9Response Hallucinationtoken level

Each dataset only labels its own dims; the rest is unsupervised (label -100). See data/README.md for the format details.

Two probe architectures (singprobe_model.arch)

archClassFileStructure
"mlp"GuardMLPmodels/guard.py2-layer MLP
"attn"GuardAttnProbemodels/sglang_attn.pyproj_q/k/v (MQA, one shared K/V head) → causal MQA → o_proj → query residual → RMSNorm → per-token linear classifier

Both architectures share the same input contract (the concatenated hidden states); train.py dispatches on arch. See models/README.md for architecture details and self-test commands.


Environment Setup

The scripts in this repo do not install anything — prepare the environment once following this section before running.

1. Python dependencies

Python 3.10+ recommended, with a CUDA environment matching your hardware.

BASH
pip install torch                      # CUDA build matching your hardware
pip install transformers safetensors pyyaml numpy tqdm

2. Token-probe-patched SGLang (required)

For DeepSeek-V4.1-Flash, Ling-3.1-flash, Qwen3.8-Flash-Next, and GLM-5.3-Flash, install the bundled implementation from the SingProbe repository root in a Linux CUDA environment with Python 3.12 and a Rust toolchain.

BASH
python -m pip install ./sglang/python

The Ling-3.0 training examples below use the Ling-3.0 integration branch. To run those examples, install that branch in their training environment:

BASH
python -m pip install "git+https://github.com/jinzhen-lin/sglang.git@token-probe-ling3-flash-main#subdirectory=python"

3. flash-linear-attention (required for Ling-3.0)

Ling-3.0 contains linear-attention layers; the SGLang side needs the fla kernels:

BASH
pip install fla

4. spaCy model (optional)

Only needed when training.use_hallu_assertion_mask: true:

BASH
pip install spacy
# Then prepare the en_core_web_sm model directory, either:
#   export SPACY_MODEL_PATH=path/to/en_core_web_sm   # unzipped model dir
#   export SPACY_MODEL_NAME=en_core_web_sm           # globally-installed package name

Model Preparation

The two configs under configs/all_models/ use the HuggingFace repos inclusionAI/Ling-3.0-flash / inclusionAI/Ling-3.0-tiny: both the SGLang server launch and the tokenizer load auto-download them from the Hub on first use. For offline environments, download the models in advance and point base_model.name at the local path.

Data Preparation

Training needs two dataset types (format details in data/README.md):

  • Safety (JSONL): Query / Response / Query_Label (A–H chars) / Response_Label (Safe|Unsafe) — labels dims 0–8;
  • Hallucination (JSONL): character spans inside the response, mapped to token-level labels — labels dim 9.

Before running, replace the four path/to/... placeholders under data: in the YAML with your real paths; train.py / the pipeline pre-check reports exactly which paths are missing.

Quickstart: Training

BASH
# First edit configs/all_models/ling-3.0-flash.yaml:
#   replace the dataset paths under data: and training.output_dir with your own
bash scripts/all/ling-3.0-flash.sh              # defaults to --ddp 4
bash scripts/all/ling-3.0-flash.sh --ddp 8
bash scripts/all/ling-3.0-tiny.sh

The pipeline scripts/run_train_pipeline.sh runs in order:

  1. [1/3] Start the SGLang hidden-state server in the background (GPUs from sglang_gpus) and wait until it is ready;
  2. [2/3] Launch train.py via torchrun (training GPUs pinned by TRAIN_GPUS, default 0,1,2,3);
  3. [3/3] Convert the final checkpoint into a HuggingFace model directory (written to the checkpoint directory's safetensors/).

On any exit path (success / failure / interruption) the SGLang process group is always torn down so the GPUs release. The SGLang-side and train-side GPU sets must be disjoint.

Handy env-var knobs: TP DP GPUS TRAIN_GPUS SGLANG_PORT SGLANG_SGLOG PROBE_CKPT SAVE_DIR MEM_FRACTION — see the script header (bash scripts/run_train_pipeline.sh --help).

Resuming: bash scripts/all/ling-3.0-flash.sh --resume path/to/checkpoint-N

(注:更多技术实现细节与完整 API 文档请查阅原项目 README)