# Granite
## 论文
暂无
## 模型简介
Granite-4.0-H-Small是一款基于Granite-4.0-H-Small-Base精调的320亿参数长上下文指令模型,采用开源指令数据集与企业内部合成数据集相结合的方式进行训练。该模型通过结构化对话格式,综合运用了监督微调(SFT)、基于强化学习的模型对齐(RL Alignment)以及模型融合(Model Merging)等多种技术进行开发。Granite 4.0 指令系列模型具备更优的指令跟随(Instruction Following)能力和工具调用(Tool Calling)功能,从而显著提升了其在企业级应用场景中的效能。
在许多智能体工作流中,指令不仅需要被可靠执行,更需要精准转换为有效的工具调用,这一点至关重要。为此,Granite-4.0-H-Small 在伯克利函数调用榜单第三版(BFCLv3)的评测中,能够与体量更大、无论开源或闭源的模型保持同等性能水准。更重要的是,它在这一竞争组别中实现了无可匹敌的成本优势。
## 环境依赖
| 软件 | 版本 |
| :------: | :------: |
| DTK | 25.04.2 |
| python | 3.10 |
| transformers | 4.57.3 |
| pytorch | 2.7.1+das.opt1.dtk25042 |
推荐使用镜像:
- 挂载地址`-v`,`{docker_name}`和 `{docker_image_name}`根据实际模型情况修改
```bash
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.7.1-ubuntu22.04-dtk25.04.2-py3.10-alpha
docker run -it --shm-size 200g --network=host --name {docker_name} --privileged --device=/dev/kfd --device=/dev/dri --device=/dev/mkfd --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -u root -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal/:/opt/hyhal/:ro {imageID} bash
cd /your_code_path/granite_pytorch
pip install transformers
pip install accelerate
```
更多镜像可前往[光源](https://sourcefind.cn/#/service-list)下载使用。
关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.sourcefind.cn/tool/)开发者社区下载安装
## 数据集
暂无
## 训练
暂无
## 推理
### transformers
#### 单机推理
```bash
export HIP_VISIBLE_DEVICES=0,1,2,3
python granite.py
```
## 效果展示
### 精度
DCU与GPU精度一致,推理框架:pytorch。
## 预训练权重
| 模型名称 | 权重大小 | DCU型号 | 最低卡数需求 |下载地址|
|:-----:|:----------:|:----------:|:---------------------:|:----------:|
| granite-4.0-h-small | 32B | K100AI | 4 | [下载地址](https://huggingface.co/ibm-granite/granite-4.0-h-small) |
## 源码仓库及问题反馈
- https://developer.sourcefind.cn/codes/modelzoo/granite_pytorch
## 参考资料
- https://github.com/ibm-granite/granite-4.0-language-models
- https://www.ibm.com/new/announcements/ibm-granite-4-0-hyper-efficient-high-performance-hybrid-models