# quant_time **Repository Path**: sukibean/quant_time ## Basic Information - **Project Name**: quant_time - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-11-12 - **Last Updated**: 2026-11-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Qwen3 时间表达式微调 + Q4 量化 基于用户提供的 CSV 标注与本地 `/home/johu/model/Qwen3-0.6B`,用 LLaMA-Factory 完成中文日期描述到目标时间表达式 DSL 的监督微调,并导出适合手机端部署的 GGUF `Q4_K_M` 模型。 原始 CSV 与基座模型全程只读,未被修改。 ## 仓库内容与未包含内容 本仓库只提交代码、配置、文档和**评测证据**(各后端逐样本结果、量化掉点报告、模型校验值)。以下内容按 `.gitignore` 排除,需要在本机重新生成: | 未包含内容 | 原因 | 重建方式 | |---|---|---| | `data/processed/` | 由原始 CSV 派生,且原始 CSV 属用户数据未入库 | `scripts/prepare_dataset.py` | | `outputs/lora/`、`outputs/merged_bf16/` | 模型权重(合计约 1.6 GB) | 训练与合并步骤 | | `outputs/final/gguf/*.gguf` | 量化模型(BF16 1.2 GB、Q4 397 MB) | `scripts/export_gguf.sh` | | `tools/llama.cpp/`、`tools/llama-cpp-venv/` | 第三方源码与虚拟环境 | `scripts/setup_llama_cpp.sh` | 因此**完整复现需要原始标注 CSV**。若没有该文件,仍可使用已交付的评测证据核对本报告结论。模型的 SHA-256 见 `outputs/final/gguf/sha256sums.txt` 与 `outputs/manifest.json`。 ## 目录结构 ``` configs/ 训练、合并、数据集与工具版本配置 scripts/ 数据准备、评测、量化、报告与服务启动脚本 service/ FastAPI 部署服务与 Web 前端 data/README.md 数据契约说明(processed/ 不入库) outputs/ evaluations/ 各后端评测结果与量化对比(入库) manifest.json 交付物清单与校验值(入库) docs/ 设计规格、实施计划、模型卡、评测报告、服务与部署说明 tests/ 数据与提示词一致性测试 ``` ## 复现步骤 配置中的路径均为相对路径,在仓库根目录执行即可;若基座模型不在默认位置,修改 `configs/train_lora.yaml` 的 `model_name_or_path`(测试可用环境变量 `BASE_MODEL_PATH` 覆盖)。 ```bash cd /home/johu/quant_time # 1. 数据:去重 + 按日期描述分组隔离切分(需要原始 CSV) python3 scripts/prepare_dataset.py --csv "<原始 CSV 路径>" python3 -m unittest discover -s tests -v # 2. 训练(BF16 LoRA,单卡) llamafactory-cli train configs/train_lora.yaml # 3. 按验证集选择 checkpoint python3 scripts/select_checkpoint.py \ --runs-dir outputs/lora \ --model /home/johu/model/Qwen3-0.6B \ --dataset data/processed/validation.json \ --output outputs/evaluations/checkpoint_selection.json # 4. 合并(把 adapter 指向选中的 checkpoint) llamafactory-cli export configs/merge_lora_selected.yaml # 5. 导出 GGUF 并量化 bash scripts/setup_llama_cpp.sh bash scripts/export_gguf.sh outputs/merged_bf16 outputs/final Q4_K_M # 6. 三方同集评测 python3 scripts/evaluate_hf.py --model outputs/merged_bf16 \ --dataset data/processed/test.json --output outputs/evaluations/merged_bf16_hf_test.json \ --model-label merged_bf16_hf python3 scripts/evaluate_gguf.py --model outputs/final/gguf/merged_bf16-bf16.gguf \ --dataset data/processed/test.json --output outputs/evaluations/merged_bf16_gguf_test.json \ --model-label merged_bf16_gguf python3 scripts/evaluate_gguf.py --model outputs/final/gguf/merged_bf16-Q4_K_M.gguf \ --dataset data/processed/test.json --output outputs/evaluations/merged_q4_gguf_test.json \ --model-label merged_q4_gguf # 7. 量化掉点判定 python3 scripts/report_metrics.py \ --baseline outputs/evaluations/merged_bf16_gguf_test.json \ --quantized outputs/evaluations/merged_q4_gguf_test.json \ --tolerance-pp 5 --output outputs/evaluations/quantization_report.json ``` ## 关键约束 - **数据隔离**:训练/验证/测试按 `日期描述` 分组切分,同一描述不跨集合;测试集不参与训练、checkpoint 选择与量化校准。 - **提示词一致**:训练、Transformers 评测、llama.cpp 评测共用 `scripts/time_dsl.py` 的唯一 prompt 构造;已验证 LLaMA-Factory `template: qwen3` + `enable_thinking: false` 与 tokenizer jinja 渲染在全部 5,748 条上逐字节一致。 - **不执行模型输出**:仅作文本/AST 比较,禁止 `eval` / `exec`。 - **量化基准**:以同后端 BF16 GGUF 为基准,避免把推理后端差异误判为量化损失。 ## 部署服务(Web 测试) ```bash bash scripts/run_service.sh start # 就绪后打开 http://127.0.0.1:8100 bash scripts/run_service.sh stop bash scripts/run_service.sh status ``` 架构:浏览器 → FastAPI(8100) → llama.cpp server(8101) → Q4_K_M GGUF。模型常驻内存,与量化评测同一条推理路径。服务自动注入当前公历时间、星期与农历日期(格式与训练数据一致),输出可直接与标注答案对照。详见 [服务说明](docs/service.md)。 ## 文档 - [设计规格](docs/aegis/specs/2026-11-12-qwen3-time-q4-design.md) - [实施计划](docs/aegis/plans/2026-11-12-qwen3-time-q4.md) - [模型卡](docs/model-card.md) - [评测报告](docs/evaluation.md) - [服务说明](docs/service.md) - [Android 部署说明](docs/android-deployment.md)