|
Download README.md from KSKOOO/HakuChat-7B-Code: direct link, hf CLI and curl.
- Browser
- Download file 2.47 kB
-
https://huggingface.co/KSKOOO/HakuChat-7B-Code/resolve/main/README.md
- Command line
-
hf download hf://KSKOOO/HakuChat-7B-Code/README.md
-
curl -L -o README.md https://huggingface.co/KSKOOO/HakuChat-7B-Code/resolve/main/README.md
2.47 kB
| # HakuChat-7B-Code | |
| ## 规格 | |
| | 项目 | 值 | | |
| |---|---| | |
| | 参数量 | 7.0051B | | |
| | 架构 | Llama 式,30 层,d_model 1152,FFN 66176,18 头 / 6 KV 头 GQA | | |
| | 上下文 | 4096 | | |
| | 词表 | 32768,ByteLevel BPE | | |
| | 精度 | bfloat16 | | |
| | 训练 | 5B→7B 零初始化扩展 + 代码 LoRA SFT(906 步 / 2 epoch,r=8) | | |
| | 数据 | `codeparrot/codeparrot-clean` 抽取的真实 Python 函数,2500 train / 300 val;40% 工具轨迹 + 身份 replay | | |
| ## 能力与评测 | |
| | 指标 | 7B 基座(扩展后未训练) | 本模型 | | |
| |---|---|---| | |
| | val 代码语法合法 | 0/12 | 11/15 | | |
| | 5 个手写单测 | 0/5 | 1/5 | | |
| | 补全任务输出代码 | — | 5/6 | | |
| | 解释任务保持文字 | — | 3/3 | | |
| | 多位数算术调用 calculator | — | 3/4 | | |
| | 工具/身份/问候回归 | 2/3 | 5/5 | | |
| | 身份在不同 system 提示下稳定 | — | 6/6 | | |
| 支持三类代码任务: | |
| - docstring → 实现 | |
| - 函数体前缀 → 补全 | |
| - 代码 → 中文解释 | |
| 以及工具协议(`web.search` / `web.open` / `calculator` / `fs.list` / `fs.read` / `fs.write`)。 | |
| ## 使用 | |
| ```python | |
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| repo = "KSKOOO/HakuChat-7B-Code" | |
| tok = AutoTokenizer.from_pretrained(repo, trust_remote_code=False) | |
| model = AutoModelForCausalLM.from_pretrained(repo, dtype=torch.bfloat16, device_map="auto").eval() | |
| system = "你是 HakuChat,一个由本地团队训练的、擅长编程的中文助手。写代码时先写「思考:」,再写「答案:」,代码放在 ```python 代码块中。" | |
| user = '请根据下面的函数签名和文档字符串实现函数,只输出完整函数代码。\n\n```python\ndef is_prime(n):\n """判断 n 是否为素数,返回布尔值。"""\n```' | |
| prompt = f"<|system|>{system}<|user|>{user}<|assistant|>" | |
| ids = tok(prompt, return_tensors="pt").to(model.device) | |
| out = model.generate(**ids, max_new_tokens=320, do_sample=False, eos_token_id=tok.eos_token_id, pad_token_id=tok.eos_token_id) | |
| print(tok.decode(out[0, ids["input_ids"].shape[1]:], skip_special_tokens=True)) | |
| ``` | |
| 推理显存:bf16 权重约 14 GB,建议 18 GB 以上。 | |
| `tokenizer_config.json` 已内置 `chat_template`,vLLM / GPUStack / Ollama(导入 GGUF 时需自行写 TEMPLATE)等 OpenAI 兼容服务会按 `<|system|>…<|user|>…<|assistant|>` 正确拼接。更新权重后需要重新下载模型并重建部署,旧部署不会自动重读模板。 | |
| ## 许可 | |
| Apache-2.0。 | |