| Crates.io | hy-mt |
| lib.rs | hy-mt |
| version | 0.1.0 |
| created_at | 2026-01-10 13:17:01.706049+00 |
| updated_at | 2026-01-10 13:17:01.706049+00 |
| description | A lightweight machine translation inference library for Tencent Hunyuan MT models |
| homepage | |
| repository | https://github.com/ximeiorg/hy-mt |
| max_upload_size | |
| id | 2034186 |
| size | 238,123 |
hy-mt 是一个基于 Rust 实现的轻量级机器翻译模型推理库,专门用于加载和运行腾讯混元(Hunyuan)MT系列模型。
⚠️ 注意: 当前版本为实验性实现,模型精度尚未完全对齐,翻译效果和python 版本有一些小差异。
在 Cargo.toml 中添加:
[dependencies]
hy-mt = "0.1.0"
# 克隆项目
git clone https://github.com/ximeiorg/hy-mt
cd hy-mt
# 构建项目
cargo build --release
# 运行测试
cargo test
use candle_core::{Device, Result};
use hy_mt::TextGeneration;
fn main() -> Result<()> {
// 设置设备(优先使用GPU)
let device = Device::cuda_if_available(0)?;
// 加载预训练模型(需要提前下载模型权重)
let model_path = std::path::Path::new("path/to/hunyuan/model");
let mut model = TextGeneration::from_pretrained(model_path, &device)?;
// 生成文本
let prompt = "Translate the following English text to Chinese: Hello, world!";
println!("输入提示: {}", prompt);
println!("生成结果: ");
let result = model.generate(prompt, 512)?;
println!("\n完整结果: {}", result);
Ok(())
}
use hy_mt::{TextGeneration, model::HunYuanDenseV1ForCausalLM};
// 自定义生成参数
let mut model = TextGeneration::new_with_topk(
model, // 加载的模型
tokenizer, // tokenizer
42, // 随机种子
Some(0.7), // temperature
Some(20), // top-k
Some(0.6), // top-p
1.1, // 重复惩罚系数
64, // 重复惩罚窗口大小
&device,
)?;
src/
├── lib.rs # 主库文件,导出公共API
├── config.rs # 模型配置结构
├── model.rs # 模型架构实现
├── tokenizer.rs # Tokenizer封装
├── prompt.rs # 提示模板处理
├── logits_processor.rs # 生成策略实现
├── masking_utils.rs # 注意力掩码工具
└── utils.rs # 工具函数
项目包含完整的文本生成示例:
# 运行文本生成示例
cargo run --example text_generation_example
# 查看CUDA支持示例
cargo run --example cuda
# 运行简单示例
cargo run --example sample
要使用此库,你需要:
tencent/HY-MT1.5-1.8B/ 路径中config.json - 模型配置文件tokenizer.json - Tokenizer文件model.safetensors - 模型权重文件candle-core, candle-nn)欢迎提交 Issue 和 Pull Request!
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。