Transformers
English
Chinese
zero-train
logit-patching
model-editing
mechanistic-interpretability
rank-1-update
Run this model with HF Jobs
Run aifeifei798/ZeroTrain on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/aifeifei798/ZeroTrain. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/aifeifei798/ZeroTrain on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use aifeifei798/ZeroTrain with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use aifeifei798/ZeroTrain with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("aifeifei798/ZeroTrain", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download test_10.py from aifeifei798/ZeroTrain: direct link, hf CLI and curl.
- Browser
- Download file 5.14 kB
-
https://huggingface.co/aifeifei798/ZeroTrain/resolve/main/test_10.py
- Command line
-
hf download hf://aifeifei798/ZeroTrain/test_10.py
-
curl -L -o test_10.py https://huggingface.co/aifeifei798/ZeroTrain/resolve/main/test_10.py
5.14 kB
| import torch | |
| import numpy as np | |
| import pandas as pd | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| import plotly.graph_objects as go | |
| from sklearn.decomposition import TruncatedSVD | |
| # ==================== 配置 ==================== | |
| MODEL_PATH = "./Qwen3-0.6B" | |
| TEST_LIMIT = 10 | |
| DEVICE = "cuda" if torch.cuda.is_available() else "cpu" | |
| DTYPE = torch.bfloat16 | |
| # ============================================= | |
| def main(): | |
| print(f"[*] 正在从 {MODEL_PATH} 载入模型与分词器...") | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, | |
| trust_remote_code=True) | |
| # 使用新版推荐参数 dtype (消掉警告) | |
| model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, | |
| dtype=DTYPE, | |
| device_map=DEVICE, | |
| trust_remote_code=True) | |
| model.eval() | |
| print("[+] 0.6B 纯血模型极速装载完成!") | |
| # 1. 提取前 10 个 Token 进行显卡轰击 | |
| test_ids = torch.arange(TEST_LIMIT, dtype=torch.long) | |
| batch_input = test_ids.unsqueeze(1).to(DEVICE) # Shape: [10, 1] | |
| print(f"[*] 正在测试前 {TEST_LIMIT} 个 Token 的单字基态...") | |
| with torch.no_grad(): | |
| outputs = model(batch_input) | |
| logits = outputs.logits[:, -1, :].float() # Shape: [10, Vocab] | |
| probs = torch.softmax(logits, dim=-1) | |
| log_probs = torch.log_softmax(logits, dim=-1) | |
| entropy = -torch.sum(probs * log_probs, dim=-1).cpu().numpy() | |
| top1_prob, top1_id = torch.max(probs, dim=-1) | |
| top1_prob = top1_prob.cpu().numpy() | |
| top1_id = top1_id.cpu().numpy() | |
| # 2. 字符精准解码 | |
| decoded_inputs = tokenizer.batch_decode([[i] for i in range(TEST_LIMIT)], | |
| skip_special_tokens=False) | |
| decoded_targets = tokenizer.batch_decode([[i] for i in top1_id], | |
| skip_special_tokens=False) | |
| # 3. 终端清晰制表 | |
| data = [] | |
| print("\n" + "=" * 65) | |
| print(f"{'ID':<6} | {'输入字符':<12} | {'强吸引至':<12} | {'置信度':<8} | {'引力熵'}") | |
| print("-" * 65) | |
| for i in range(TEST_LIMIT): | |
| c_in = decoded_inputs[i].replace("\n", "↵").replace("\r", "") | |
| c_out = decoded_targets[i].replace("\n", "↵").replace("\r", "") | |
| if not c_in.strip(): c_in = f"<{i}>" | |
| if not c_out.strip(): c_out = "[空]" | |
| print( | |
| f"{i:<6} | {c_in:<12} | {c_out:<12} | {top1_prob[i]*100:>6.1f}% | {entropy[i]:.4f}" | |
| ) | |
| data.append({ | |
| "token_id": i, | |
| "char": c_in, | |
| "top1_target": c_out, | |
| "top1_prob": top1_prob[i], | |
| "entropy": entropy[i] | |
| }) | |
| print("=" * 65 + "\n") | |
| # 4. 生成带大白话坐标轴的微型星图 | |
| df = pd.DataFrame(data) | |
| with torch.no_grad(): | |
| raw_embeds = model.get_input_embeddings().weight[:TEST_LIMIT].detach( | |
| ).cpu().to(torch.float32).numpy() | |
| svd = TruncatedSVD(n_components=2, random_state=42) | |
| coords = svd.fit_transform(raw_embeds) | |
| df["x"] = coords[:, 0] | |
| df["y"] = coords[:, 1] | |
| hover_texts = [ | |
| f"<b>【输入】: {r.char}</b> (ID: {r.token_id})<br>" | |
| f"➔ 强吸引至: {r.top1_target}<br>" | |
| f"置信度: {r.top1_prob*100:.1f}%<br>熵: {r.entropy:.3f}" | |
| for r in df.itertuples() | |
| ] | |
| fig = go.Figure(data=go.Scatter(x=df["x"], | |
| y=df["y"], | |
| mode="markers+text", | |
| text=df["char"], | |
| textposition="top center", | |
| marker=dict(size=10, | |
| color=df["entropy"], | |
| colorscale="Turbo_r", | |
| showscale=True, | |
| colorbar=dict(title="引力熵")), | |
| textfont=dict(size=12, color="white"), | |
| hovertext=hover_texts, | |
| hoverinfo="text")) | |
| # 👈 中文大白话路标彻底焊死在坐标轴上 | |
| fig.update_layout( | |
| template="plotly_dark", | |
| title="Qwen3-0.6B 初始 10 词试探星图", | |
| xaxis=dict(title=dict( | |
| text="<b>【横轴】语义收敛走向(👈 发散词根/开放语义 ──────── 确定性塌缩/句尾断点 👉)</b>", | |
| font=dict(size=14, color="#00ffcc")), | |
| showgrid=True), | |
| yaxis=dict(title=dict( | |
| text="<b>【纵轴】语言抽象层级(👇 人类自然语言与代码 ──────── 底层未成字碎片字节 👆)</b>", | |
| font=dict(size=14, color="#ff9900")), | |
| showgrid=True)) | |
| fig.write_html("test_10.html") | |
| print("[✓] 大白话路标已归位!重新打开 test_10.html 即可查看!") | |
| if __name__ == "__main__": | |
| main() | |