模型概述
模型特點
模型能力
使用案例
🚀 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。同時,請遵循模型的許可證和使用規範。



