Skip to content

Fix: save_pretrained saves tokenizer weights, replace with safetensor…#266

Open
1321213430 wants to merge 1 commit intoshiyu-coder:masterfrom
1321213430:fix/predictor-save-weights
Open

Fix: save_pretrained saves tokenizer weights, replace with safetensor…#266
1321213430 wants to merge 1 commit intoshiyu-coder:masterfrom
1321213430:fix/predictor-save-weights

Conversation

@1321213430
Copy link
Copy Markdown

Issue / 问题

When running train_predictor.py, calling model.module.save_pretrained() saves tokenizer weights (encoder/decoder) instead of the trained Predictor model.

  • Saved checkpoint size: only ~16MB
  • Missing core Predictor weights: transformer.0 ~ transformer.11
  • Trained model cannot be loaded for inference

运行 train_predictor.py 时,调用 model.module.save_pretrained() 保存的并非训练后的预测模型,而是分词器(Tokenizer)权重(encoder/decoder)

  • 保存的模型文件大小仅约 16MB
  • 缺失预测模型核心权重:transformer.0 ~ transformer.11
  • 训练完成的模型无法加载并用于推理

Root Cause / 根本原因

The custom Kronos model's save_pretrained() method incorrectly serializes tokenizer weights instead of the main model weights.

自定义 Kronos 模型的 save_pretrained() 方法存在错误,错误地序列化了分词器权重,而非主模型权重。

Fix / 修复方案

Replace the broken save_pretrained() with direct safetensors state_dict saving to ensure the full Predictor model weights are saved correctly.

替换存在问题的 save_pretrained() 方法,直接通过 safetensors 保存模型权重字典,确保完整、正确地保存预测模型权重。

Changes / 修改内容

  1. Add safetensors.torch import

  2. Replace model saving logic in train_predictor.py

  3. Minimal non-breaking change

  4. 新增 safetensors.torch 导入语句

  5. 替换 train_predictor.py 中的模型保存逻辑

  6. 最小化修改,无破坏性变更

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant