Instructions to use lastmass/llama3.1-Medical-Assistant with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lastmass/llama3.1-Medical-Assistant with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lastmass/llama3.1-Medical-Assistant") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("lastmass/llama3.1-Medical-Assistant", dtype="auto") - llama-cpp-python
How to use lastmass/llama3.1-Medical-Assistant with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="lastmass/llama3.1-Medical-Assistant", filename="unsloth.Q4_K_M.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use lastmass/llama3.1-Medical-Assistant with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf lastmass/llama3.1-Medical-Assistant:Q4_K_M # Run inference directly in the terminal: llama-cli -hf lastmass/llama3.1-Medical-Assistant:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf lastmass/llama3.1-Medical-Assistant:Q4_K_M # Run inference directly in the terminal: llama-cli -hf lastmass/llama3.1-Medical-Assistant:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf lastmass/llama3.1-Medical-Assistant:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf lastmass/llama3.1-Medical-Assistant:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf lastmass/llama3.1-Medical-Assistant:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf lastmass/llama3.1-Medical-Assistant:Q4_K_M
Use Docker
docker model run hf.co/lastmass/llama3.1-Medical-Assistant:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use lastmass/llama3.1-Medical-Assistant with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lastmass/llama3.1-Medical-Assistant" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lastmass/llama3.1-Medical-Assistant", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/lastmass/llama3.1-Medical-Assistant:Q4_K_M
- SGLang
How to use lastmass/llama3.1-Medical-Assistant with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "lastmass/llama3.1-Medical-Assistant" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lastmass/llama3.1-Medical-Assistant", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "lastmass/llama3.1-Medical-Assistant" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lastmass/llama3.1-Medical-Assistant", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use lastmass/llama3.1-Medical-Assistant with Ollama:
ollama run hf.co/lastmass/llama3.1-Medical-Assistant:Q4_K_M
- Unsloth Studio new
How to use lastmass/llama3.1-Medical-Assistant with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for lastmass/llama3.1-Medical-Assistant to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for lastmass/llama3.1-Medical-Assistant to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for lastmass/llama3.1-Medical-Assistant to start chatting
- Pi new
How to use lastmass/llama3.1-Medical-Assistant with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf lastmass/llama3.1-Medical-Assistant:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "lastmass/llama3.1-Medical-Assistant:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use lastmass/llama3.1-Medical-Assistant with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf lastmass/llama3.1-Medical-Assistant:Q4_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default lastmass/llama3.1-Medical-Assistant:Q4_K_M
Run Hermes
hermes
- Docker Model Runner
How to use lastmass/llama3.1-Medical-Assistant with Docker Model Runner:
docker model run hf.co/lastmass/llama3.1-Medical-Assistant:Q4_K_M
- Lemonade
How to use lastmass/llama3.1-Medical-Assistant with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull lastmass/llama3.1-Medical-Assistant:Q4_K_M
Run and chat with the model
lemonade run user.llama3.1-Medical-Assistant-Q4_K_M
List all available models
lemonade list
基于 Meta-Llama-3.1-8B-Instruct 的中文医疗对话模型
本模型通过在 meta-llama/Llama-3.1-8B 基础模型上,使用 Flmc/DISC-Med-SFT 数据集进行监督微调(SFT)得到。该模型旨在为用户提供医疗相关的对话支持。
使用GRPO训练的医疗推理模型看这里[https://huggingface.co/lastmass/Qwen3_Medical_GRPO]
模型架构
本模型采用了 LoRA (Low-Rank Adaptation) 技术,训练后的 LoRA 适配器权重保存在 adapter_model.safetensors 文件中。
使用方法
1. 使用 peft (不建议,Unsloth 更高效):
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer
model = AutoPeftModelForCausalLM.from_pretrained(
"lora_model", # 您的模型路径
load_in_4bit = load_in_4bit,
)
tokenizer = AutoTokenizer.from_pretrained("lora_model")
2. 推荐使用 Unsloth 库:
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "lora_model", # 您的模型路径
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
)
FastLanguageModel.for_inference(model) # 启用原生 2 倍加速推理
messages = [
{"role": "user", "content": "大夫,请问我最近脊椎靠近腰部的地方经常有疼痛感,请问是什么原因?"},
{"role":"assistant","content":"您好,根据您的症状描述,我怀疑您可能患有腰椎间盘突出症。这个症状常见于中老年人,由于椎间盘损伤或退行性变引起。根据我的经验,您可以考虑进行MRI检查来确认诊断。'"},
{"role": "user", "content": "大夫,我每天需要坐很久,是不是也和这个有关系?保持怎样的坐姿会改善呢?"},
]
inputs = tokenizer.apply_chat_template(
messages,
tokenize = True,
add_generation_prompt = True, # 必须添加以用于生成
return_tensors = "pt",
).to("cuda")
from transformers import TextStreamer
text_streamer = TextStreamer(tokenizer, skip_prompt = True)
_ = model.generate(input_ids = inputs, streamer = text_streamer, max_new_tokens = 128,
use_cache = True, temperature = 1.5, min_p = 0.1)
3. 使用 unsloth.Q4_K_M.gguf (用于 ollama 和 llama.cpp):
将 unsloth.Q4_K_M.gguf 与以下 Modelfile 放置在同一目录:
from unsloth.Q4_K_M.gguf
SYSTEM "你是一名专业的全科医生,回答的语气必须专业而亲切,需要根据患者提出的症状描述来回答问题,清晰专业的回答患者提出的问题。"
TEMPLATE """{{ if .Messages }}
{{- if or .System .Tools }}<|start_header_id|>system<|end_header_id|>
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}
You are a helpful assistant with tool calling capabilities. When you receive a tool call response, use the output to format an answer to the original use question.
{{- end }}
{{- end }}<|eot_id|>
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- if eq .Role "user" }}<|start_header_id|>user<|end_header_id|>
{{- if and $.Tools $last }}
Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.
Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}. Do not use variables.
{{ $.Tools }}
{{- end }}
{{ .Content }}<|eot_id|>{{ if $last }}<|start_header_id|>assistant<|end_header_id|>
{{ end }}
{{- else if eq .Role "assistant" }}<|start_header_id|>assistant<|end_header_id|>
{{- if .ToolCalls }}
{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "parameters": {{ .Function.Arguments }}}{{ end }}
{{- else }}
{{ .Content }}{{ if not $last }}<|eot_id|>{{ end }}
{{- end }}
{{- else if eq .Role "tool" }}<|start_header_id|>ipython<|end_header_id|>
{{ .Content }}<|eot_id|>{{ if $last }}<|start_header_id|>assistant<|end_header_id|>
{{ end }}
{{- end }}
{{- end }}
{{- else }}
{{- if .System }}<|start_header_id|>system<|end_header_id|>
{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>
{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>
{{ end }}{{ .Response }}{{ if .Response }}<|eot_id|>{{ end }}"""
PARAMETER stop "<|start_header_id|>"
PARAMETER stop "<|end_header_id|>"
PARAMETER stop "<|eot_id|>"
PARAMETER stop "<|eom_id|>"
PARAMETER temperature 1.1
PARAMETER min_p 0.1
在安卓termux中使用(感谢snippets:https://gitlab.com/-/snippets/3682973)
Ollama on Termux
Install Dependancies
pkg upgrade
pkg install git cmake golang
Build Ollama from source
git clone --depth 1 https://github.com/ollama/ollama.git
cd ollama
go generate ./...
go build .
./ollama serve &
./ollama run lastmass/llama3.2-chinese
Cleanup
You may want to remove the 'go' folder that was just created in your home directory. If so here is how to do it.
chmod -R 700 ~/go
rm -r ~/go
Currently, termux does not have .local/bin in its PATH (though you can add it if you would prefer). If you would like to move the ollama binary to the bin folder you can do the following.
cp ollama/ollama /data/data/com.termux/files/usr/bin/
Now you can just run ollama in your terminal directly!
注意事项
- 本模型基于公开数据集进行训练,可能存在一定的偏差或不准确性。
- 模型输出的文本仅供参考,不能替代专业的医疗建议或诊断。
- 请务必咨询医生或其他医疗专业人士以获取准确的医疗信息和治疗方案。
- 在医疗场景中使用该模型时,请务必谨慎评估其输出,并结合其他医疗资源进行综合判断。
免责声明
本模型提供的医疗建议和信息仅为参考,不构成任何形式的医疗诊断或治疗建议。请在咨询专业医疗人员后,再进行任何医疗决策。对于因使用本模型所产生的任何后果,本模型提供者不承担任何责任。
- Downloads last month
- 113
4-bit
Model tree for lastmass/llama3.1-Medical-Assistant
Base model
meta-llama/Llama-3.1-8B