Skip to content

di-osc/osc-llm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OSC-LLM

PyTorch Lightning

简介

osc-llm是一款轻量级别的模型推理框架, 专注于延迟和易用性。

特点

  • ✅ 模型编译:torch.compile
  • ✅ 模型量化:WeightOnlyInt8,WeightOnlyInt4
  • ✅ 推测性解码:(Speculative decoding)
  • ✅ 极少的依赖:核心仅pytorch
  • ❎ 更高效的kvcache管理:(PageAttention、TokenAttention)

文档地址:

安装

快速开始

命令行

# 下面以llama3为例演示如何转换为osc-llm格式,并进行聊天。
# 假设你已经下载好huggingface的llama3模型在checkpoints/meta-llama目录下
# 聊天(使用编译功能加速推理速度,需要等待几分钟编译时间)
llm chat --checkpoint_dir checkpoints/meta-llama/Meta-Llama-3-8B-Instruct --compile true
# 部署
llm serve --checkpoint_dir checkpoints/meta-llama/Meta-Llama-3-8B-Instruct --compile true

使用LLM

from osc_llm import LLM

llm = LLM(checkpoint_dir="checkpoints/meta-llama/Meta-Llama-3-8B-Instruct", compile=True)
llm.warmup()  # 编译后的模型第一次运行会比较慢,所以要预热模型。
for token in llm.generate(prompt="介绍一下你自己"):
    print(token)

模型支持

以下huggingface中的模型结构(查看config.json)已经支持转换为osc-llm格式:

  • LlamaForCausalLM: llama2, llama3, chinese-alpaca2等。
  • Qwen2ForCausalLM: qwen1.5, qwen2等。
  • Qwen2MoeForCausalLM: qwen2-moe系列(目前无法完成编译,推理速度很慢)。

致敬

本项目参考了大量的开源项目,特别是以下项目:

About

轻量级大模型推理引擎

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages