Commit ad5cfca1 authored by dengjb's avatar dengjb
Browse files

update code

parents
Pipeline #1380 failed with stages
in 0 seconds
experiments/*
results/*
tb_logger/*
wandb/*
tmp/*
modify_model.py
hat/version.py
*.DS_Store
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# llm-compiler
LLM Compiler: Specializing Code Llama for compiler optimization
## 论文
[Meta Large Language Model Compiler: Foundation Models of Compiler Optimization](https://scontent-sjc3-1.xx.fbcdn.net/v/t39.2365-6/448997590_1496256481254967_2304975057370160015_n.pdf?_nc_cat=106&ccb=1-7&_nc_sid=3c67a6&_nc_ohc=9EBooh-SwxIQ7kNvgHFCHvh&_nc_ht=scontent-sjc3-1.xx&oh=00_AYAZqBNdevNLWa6cuTIuvxhG31CBJRu61vyjmbSLiV9sFg&oe=669C1E0D)
## 模型结构
LLM编译器模型是通过在两个阶段对5460亿个编译器中心数据token进行训练,从Code Llama专业化的。在第一阶段,模型主要对未标记的编译器IR和汇编代码进行训练。在下一阶段,模型经过指令微调,以预测优化的输出和效果。然后,LLM编译器FTD模型在下游标志调整和反汇编任务数据集的1640亿个token上进一步微调,总共进行了7100亿个训练token。
<div align=center>
<img src="./assets/model_framework.png"/>
</div>
## 算法原理
使用GQA模块能够带来更好的速度,使用GQA的head数量不同则会带来速度和性能平衡转换
使用了RoPE位置旋转编码来替代Embedding编码,使得模型获得更好的外推性。
<div align=center>
<img src="./assets/model.png"/>
</div>
## 环境配置
-v 路径、docker_name和imageID根据实际情况修改
### Docker(方法一)
```bash
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-centos7.6-dtk24.04-py310
docker run -it -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal/:/opt/hyhal/:ro --shm-size=80G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash
cd /your_code_path/llm-compiler_pytorch
pip install -r requirements.txt
pip install -U huggingface_hub hf_transfer
export HF_ENDPOINT=https://hf-mirror.com
```
### Dockerfile(方法二)
```bash
cd docker
docker build --no-cache -t llm-compiler:latest .
docker run -it -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal/:/opt/hyhal/:ro --shm-size=80G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name docker_name imageID bash
cd /your_code_path/llm-compiler_pytorch
pip install -r requirements.txt
pip install -U huggingface_hub hf_transfer
export HF_ENDPOINT=https://hf-mirror.com
```
### Anaconda(方法三)
关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.hpccube.com/tool/)开发者社区下载安装。
```
DTK驱动: dtk24.04
python: python3.10
torch: 2.1.0
```
`Tips:以上dtk驱动、python、torch等DCU相关工具版本需要严格一一对应`
其它非深度学习库安装方式如下:
```bash
pip install -r requirements.txt
pip install -U huggingface_hub hf_transfer
export HF_ENDPOINT=https://hf-mirror.com
```
## 数据集
暂无
## 训练
暂无
## 推理
基于Huggingface's Transformers进行推理.<br>
模型下载后 默认需存放至weights文件夹中<br>
也可自行更改 inference.py文件中的 model_name 参数<br>
```python
HIP_VISIBLE_DEVICES=0 python inference.py
```
## Result
prompt:%3 = alloca i32, align 4.<br>
<div align=center>
<img src="./assets/result.png"/>
</div>
### 精度
暂无
## 应用场景
### 算法类别
代码生成
### 热点应用行业
制造,能源,教育
## 预训练权重
- 模型权重快速下载中心:
- [SCNet AIModels](http://113.200.138.88:18080/aimodels)
- 模型快速通道下载地址:
- [数据集快速下载地址](http://113.200.138.88:18080/aimodels?filter=llm-compiler)
- 官方下载通道
- [llm-compiler-7b](https://huggingface.co/facebook/llm-compiler-7b)
模型目录结构如下:
```bash
└── llm-compiler-7b
├── config.json
├── generation_config.json
├── LICENSE.pdf
├── llm_compiler_demo.py
├── pytorch_model-00001-of-00003.bin
├── pytorch_model-00002-of-00003.bin
├── pytorch_model-00003-of-00003.bin
├── pytorch_model.bin.index.json
├── readme
│   ├── autotune.png
│   ├── disassemble.png
│   ├── emulate.png
│   └── training.png
├── README.md
├── special_tokens_map.json
├── tokenizer_config.json
├── tokenizer.json
└── tokenizer.model
```
## 源码仓库及问题反馈
- https://developer.hpccube.com/codes/modelzoo/llm-compiler_pytorch
## 参考资料
- https://huggingface.co/facebook/llm-compiler-7b/blob/main/llm_compiler_demo.py
- https://huggingface.co/facebook/llm-compiler-7b
FROM image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-centos7.6-dtk24.04-py310
\ No newline at end of file
icon.png

62.1 KB

from transformers import AutoTokenizer
import transformers
import torch
model = "facebook/llm-compiler-7b"
tokenizer = AutoTokenizer.from_pretrained(model)
pipeline = transformers.pipeline(
"text-generation",
model=model,
torch_dtype=torch.float16,
device_map="auto",
)
sequences = pipeline(
'%3 = alloca i32, align 4',
do_sample=True,
top_k=10,
temperature=0.1,
top_p=0.95,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id,
max_length=200,
)
for seq in sequences:
print(f"Result: {seq['generated_text']}")
\ No newline at end of file
# 模型唯一标识
modelCode=801
# 模型名称
modelName=llm-compiler_pytorch
# 模型描述
modelDescription=llm-compiler是Meta大型语言模型编译器 (LLM Compiler),这是一套强大的、公开可用的、预先训练的模型,专为代码优化任务而设计。
# 应用场景
appScenario=推理,训练,代码生成,制造,能源,教育
# 框架类型
frameType=pytorch
#torch>=2.0
#tokenizers>=0.14.0
#transformers==4.35.0
#accelerate
#deepspeed==0.12.2
sympy==1.12
pebble
timeout-decorator
accelerate
attrdict
tqdm
datasets
tensorboardX
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment