模型简介
模型特点
模型能力
使用案例
🚀 Meditron 7B - AWQ
本项目提供了EPFL LLM Team的Meditron 7B模型的AWQ量化版本,可用于高效的推理任务。
🚀 快速开始
本仓库包含了 EPFL LLM Team的Meditron 7B 模型的AWQ量化文件。这些文件是在 Massed Compute 提供的硬件上进行量化的。
✨ 主要特性
- 高效量化:AWQ是一种高效、准确且快速的低比特权重量化方法,目前支持4位量化。与GPTQ相比,它在基于Transformer的推理任务中速度更快,且在质量上与最常用的GPTQ设置相当或更优。
- 广泛支持:支持多种推理工具和框架,包括 Text Generation Webui、vLLM、Hugging Face Text Generation Inference (TGI)、Transformers 以及 AutoAWQ。
📦 安装指南
在 text-generation-webui 中使用
请确保你使用的是 text-generation-webui 的最新版本。强烈建议使用一键安装程序,除非你确定自己知道如何手动安装。
- 点击 Model tab。
- 在 Download custom model or LoRA 下输入
TheBloke/meditron-7B-AWQ
。 - 点击 Download。
- 模型将开始下载,下载完成后会显示 "Done"。
- 在左上角,点击 Model 旁边的刷新图标。
- 在 Model 下拉菜单中,选择你刚刚下载的模型:
meditron-7B-AWQ
。 - 选择 Loader: AutoAWQ。
- 点击 Load,模型将加载并准备好使用。
- 如果你需要自定义设置,设置完成后点击 Save settings for this model,然后在右上角点击 Reload the Model。
- 准备好后,点击 Text Generation 标签并输入提示信息即可开始!
使用 vLLM 进行多用户推理服务
安装和使用 vLLM 的文档 可以在这里找到。
- 请确保你使用的是 vLLM 0.2 或更高版本。
- 使用 vLLM 作为服务器时,请传递
--quantization awq
参数。
例如:
python3 -m vllm.entrypoints.api_server --model TheBloke/meditron-7B-AWQ --quantization awq --dtype auto
在 Python 代码中使用 vLLM 时,同样设置 quantization=awq
。
例如:
from vllm import LLM, SamplingParams
prompts = [
"Tell me about AI",
"Write a story about llamas",
"What is 291 - 150?",
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
]
prompt_template=f'''<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
'''
prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
llm = LLM(model="TheBloke/meditron-7B-AWQ", quantization="awq", dtype="auto")
outputs = llm.generate(prompts, sampling_params)
# 打印输出
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
使用 Hugging Face Text Generation Inference (TGI) 进行多用户推理服务
使用 TGI 1.1.0 或更高版本。官方 Docker 容器为:ghcr.io/huggingface/text-generation-inference:1.1.0
示例 Docker 参数:
--model-id TheBloke/meditron-7B-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
与 TGI 交互的示例 Python 代码(需要 huggingface-hub 0.17.0 或更高版本):
pip3 install huggingface-hub
from huggingface_hub import InferenceClient
endpoint_url = "https://your-endpoint-url-here"
prompt = "Tell me about AI"
prompt_template=f'''<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
'''
client = InferenceClient(endpoint_url)
response = client.text_generation(prompt,
max_new_tokens=128,
do_sample=True,
temperature=0.7,
top_p=0.95,
top_k=40,
repetition_penalty=1.1)
print(f"Model output: ", response)
使用 Transformers 从 Python 代码进行推理
安装必要的包
- 需要 Transformers 4.35.0 或更高版本。
- 需要 AutoAWQ 0.1.6 或更高版本。
pip3 install --upgrade "autoawq>=0.1.6" "transformers>=4.35.0"
注意,如果你使用的是 PyTorch 2.0.1,上述 AutoAWQ 命令将自动将你升级到 PyTorch 2.1.0。
如果你使用的是 CUDA 11.8 并希望继续使用 PyTorch 2.0.1,请运行以下命令:
pip3 install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl
如果你在使用预构建的轮子安装 AutoAWQ 时遇到问题,请从源代码安装:
pip3 uninstall -y autoawq
git clone https://github.com/casper-hansen/AutoAWQ
cd AutoAWQ
pip3 install .
Transformers 示例代码(需要 Transformers 4.35.0 及更高版本)
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
model_name_or_path = "TheBloke/meditron-7B-AWQ"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
model = AutoModelForCausalLM.from_pretrained(
model_name_or_path,
low_cpu_mem_usage=True,
device_map="cuda:0"
)
# 使用文本流逐令牌流式输出
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
prompt = "Tell me about AI"
prompt_template=f'''<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
'''
# 将提示转换为令牌
tokens = tokenizer(
prompt_template,
return_tensors='pt'
).input_ids.cuda()
generation_params = {
"do_sample": True,
"temperature": 0.7,
"top_p": 0.95,
"top_k": 40,
"max_new_tokens": 512,
"repetition_penalty": 1.1
}
# 生成流式输出,逐令牌可见
generation_output = model.generate(
tokens,
streamer=streamer,
**generation_params
)
# 不使用流的生成,输出将包含提示
generation_output = model.generate(
tokens,
**generation_params
)
# 从输出中获取令牌,解码并打印
token_output = generation_output[0]
text_output = tokenizer.decode(token_output)
print("model.generate output: ", text_output)
# 也可以通过 Transformers 的管道进行推理
from transformers import pipeline
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
**generation_params
)
pipe_output = pipe(prompt_template)[0]['generated_text']
print("pipeline output: ", pipe_output)
💻 使用示例
基础用法
# 保持原始代码和注释不变
from vllm import LLM, SamplingParams
prompts = [
"Tell me about AI",
"Write a story about llamas",
"What is 291 - 150?",
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
]
prompt_template=f'''<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
'''
prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
llm = LLM(model="TheBloke/meditron-7B-AWQ", quantization="awq", dtype="auto")
outputs = llm.generate(prompts, sampling_params)
# 打印输出
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
高级用法
# 高级场景说明 - 中文
# 这里可以使用更复杂的提示模板和生成参数
from vllm import LLM, SamplingParams
# 自定义提示模板
custom_prompt_template = '''<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
{additional_instructions}
'''
prompts = [
"Tell me about AI",
"Write a story about llamas",
"What is 291 - 150?",
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
]
additional_instructions = "Please provide a detailed and accurate answer."
prompts = [custom_prompt_template.format(prompt=prompt, additional_instructions=additional_instructions) for prompt in prompts]
# 自定义生成参数
custom_sampling_params = SamplingParams(temperature=0.7, top_p=0.9, top_k=50, max_new_tokens=1024)
llm = LLM(model="TheBloke/meditron-7B-AWQ", quantization="awq", dtype="auto")
outputs = llm.generate(prompts, custom_sampling_params)
# 打印输出
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
📚 详细文档
可用的仓库
- 用于 GPU 推理的 AWQ 模型
- 具有多种量化参数选项的用于 GPU 推理的 GPTQ 模型
- 用于 CPU+GPU 推理的 2、3、4、5、6 和 8 位 GGUF 模型
- EPFL LLM Team 原始的未量化的 fp16 格式的 PyTorch 模型,用于 GPU 推理和进一步转换
提示模板:ChatML
<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
提供的文件和 AWQ 参数
目前仅发布 128g GEMM 模型。正在积极考虑添加 group_size 32 模型和 GEMV 内核模型。
模型以分片的 safetensors 文件形式发布。
分支 | 比特数 | GS | AWQ 数据集 | 序列长度 | 大小 |
---|---|---|---|---|---|
main | 4 | 128 | Medical Medaow WikiDoc | 4096 | 3.89 GB |
兼容性
提供的文件经过测试,可与以下工具和框架配合使用:
- text-generation-webui 使用
Loader: AutoAWQ
。 - vLLM 0.2.0 及更高版本。
- Hugging Face Text Generation Inference (TGI) 1.1.0 及更高版本。
- Transformers 4.35.0 及更高版本。
- AutoAWQ 0.1.1 及更高版本。
🔧 技术细节
模型详情
属性 | 详情 |
---|---|
模型类型 | 因果解码器-only 变压器语言模型 |
开发团队 | EPFL LLM Team |
语言 | 主要为英语 |
模型许可证 | LLAMA 2 COMMUNITY LICENSE AGREEMENT |
代码许可证 | APACHE 2.0 LICENSE |
继续预训练的模型 | Llama-2-7B |
上下文长度 | 2K 令牌 |
输入 | 仅文本数据 |
输出 | 模型仅生成文本 |
状态 | 这是一个在离线数据集上训练的静态模型。随着模型性能的提升,未来将发布调优后的版本。 |
知识截止日期 | 2023 年 8 月 |
模型来源
- 仓库:epflLLM/meditron
- 训练器:epflLLM/Megatron-LLM
- 论文:MediTron-70B: Scaling Medical Pretraining for Large Language Models
用途
Meditron-7B 作为一个 AI 助手,可用于进一步的测试和评估,以增强临床决策和提高医疗保健领域对大语言模型的访问。潜在用例可能包括但不限于:
- 医学考试问题回答
- 支持鉴别诊断
- 疾病信息(症状、原因、治疗)查询
- 一般健康信息查询
直接使用
可以使用此模型生成文本,这对于实验和了解其能力很有用。但不应直接用于可能影响人们的生产或工作中。
下游使用
Meditron-7B 是一个基础模型,可以针对特定的下游任务和应用进行微调、指令调优或 RLHF 调优。我们使用此模型的主要方式是针对下游问答任务进行微调,但我们鼓励将此模型用于更多应用。
要提示我们微调后的模型,需要遵循特定的格式,包括 <|im_start|>
、<|im_end|>
标签以及 system
、question
、answer
标识符。
<|im_start|>system
{system_message}<|im_end|>
<|im_start|>question
{prompt}<|im_end|>
<|im_start|>answer
注意 1:运行基础模型(本仓库)不需要上述格式。
注意 2:上述格式只是微调模板的一个示例。如果你使用自己的格式选项对模型进行微调,则此格式不是必需的。
要使用此基础模型进行适当的生成,我们建议使用高吞吐量和内存高效的推理引擎,如 vLLM,并搭配支持聊天和文本生成的 UI,如 BetterChatGPT。
要了解有关模型部署和生成的更多详细信息,请参阅我们的 文档。
超出范围的使用
我们不建议在生产环境中使用此模型进行自然语言生成,无论是否经过微调。
真实性、有用性、风险和偏差
我们对 Meditron 模型的 真实性 与基线模型和消费级医疗模型进行了初步评估。我们使用 TruthfulQA(多项选择)作为主要评估基准。我们仅关注与医学领域相关的类别,包括健康、营养、心理学和科学。
对于 7B 模型,我们进行单样本评估以实现一致的答案生成。对于 70B 模型,评估是在零样本设置下进行的。
以下是每个类别的详细真实性性能报告:
类别 | meditron-70b | llama-2-70b | med42-70b* | meditron-7b | llama-2-7b | PMC-llama-7b |
---|---|---|---|---|---|---|
健康 | 81.8 | 69.1 | 83.6 | 27.3 | 16.4 | 3.6 |
营养 | 77.9 | 68.8 | 62.5 | 31.1 | 12.5 | 6.3 |
心理学 | 47.4 | 36.8 | (原文档此处未完整给出数据) | (原文档此处未完整给出数据) | (原文档此处未完整给出数据) | (原文档此处未完整给出数据) |
📄 许可证
本模型的许可证为 LLAMA 2 COMMUNITY LICENSE AGREEMENT,代码许可证为 APACHE 2.0 LICENSE。
其他信息
Discord
如需进一步的支持,以及讨论这些模型和一般的人工智能话题,请加入我们的 TheBloke AI 的 Discord 服务器。
感谢与贡献
感谢 chirper.ai 团队!感谢来自 gpus.llm-utils.org 的 Clay!
很多人询问是否可以进行贡献。我喜欢提供模型并帮助他人,也希望能够花更多时间做这些事情,同时拓展到新的项目,如微调/训练。
如果你有能力并愿意贡献,我将非常感激,这将帮助我继续提供更多模型,并开始新的人工智能项目。
捐赠者将在任何人工智能/大语言模型/模型问题和请求上获得优先支持,访问私人 Discord 房间,以及其他福利。
- Patreon: https://patreon.com/TheBlokeAI
- Ko-Fi: https://ko-fi.com/TheBlokeAI
特别感谢:Aemon Algiz。
Patreon 特别提及:Brandon Frisco, LangChain4j, Spiking Neurons AB, transmissions 11, Joseph William Delisle, Nitin Borwankar, Willem Michiel, Michael Dempsey, vamX, Jeffrey Morgan, zynix, jjj, Omer Bin Jawed, Sean Connelly, jinyuan sun, Jeromy Smith, Shadi, Pawan Osman, Chadd, Elijah Stavena, Illia Dulskyi, Sebastain Graf, Stephen Murray, terasurfer, Edmond Seymore, Celu Ramasamy, Mandus, Alex, biorpg, Ajan Kanaga, Clay Pascal, Raven Klaugh, 阿明, K, ya boyyy, usrbinkat, Alicia Loh, John Villwock, ReadyPlayerEmma, Chris Smitley, Cap'n Zoog, fincy, GodLy, S_X, sidney chen, Cory Kujawski, OG, Mano Prime, AzureBlack, Pieter, Kalila, Spencer Kim, Tom X Nguyen, Stanislav Ovsiannikov, Michael Levine, Andrey, Trailburnt, Vadim, Enrico Ros, Talal Aujan, Brandon Phillips, Jack West, Eugene Pentland, Michael Davis, Will Dee, webtim, Jonathan Leane, Alps Aficionado, Rooh Singh, Tiffany J. Kim, theTransient, Luke @flexchar, Elle, Caitlyn Gatomon, Ari Malik, subjectnull, Johann-Peter Hartmann, Trenton Dambrowitz, Imad Khwaja, Asp the Wyvern, Emad Mostaque, Rainer Wilmers, Alexandros Triantafyllidis, Nicholas, Pedro Madruga, SuperWojo, Harry Royden McLaughlin, James Bentley, Olakabola, David Ziegler, Ai Maven, Jeff Scroggin, Nikolai Manek, Deo Leter, Matthew Berman, Fen Risland, Ken Nordquist, Manuel Alberto Morcote, Luke Pendergrass, TL, Fred von Graf, Randy H, Dan Guido, NimbleBox.ai, Vitor Caleffi, Gabriel Tamborski, knownsqashed, Lone Striker, Erik Bjäreholt, John Detwiler, Leonard Tan, Iucharbius
感谢所有慷慨的赞助者和捐赠者!再次感谢 a16z 的慷慨资助。
重要提示
⚠️ 重要提示
虽然 Meditron 旨在从高质量证据来源中编码医学知识,但它尚未适应以适当、安全的方式或在专业可操作的约束范围内提供这些知识。我们建议在没有进行广泛的用例对齐以及额外测试(特别是包括在现实世界实践环境中的随机对照试验)的情况下,不要将 Meditron 部署到医疗应用中。
💡 使用建议
要使用此基础模型进行适当的生成,建议使用高吞吐量和内存高效的推理引擎,如 vLLM,并搭配支持聊天和文本生成的 UI,如 BetterChatGPT。同时,请遵循模型的许可证和使用规范。



