Views
No views yet
meta-llama/Llama-3.1-8B 基础模型上,使用 Flmc/DISC-Med-SFT 数据集进行监督微调(SFT)得到。该模型旨在为用户提供医疗相关的对话支持。adapter_model.safetensors 文件中。1from peft import AutoPeftModelForCausalLM
2from transformers import AutoTokenizer
3
4model = AutoPeftModelForCausalLM.from_pretrained(
5 "lora_model", # 您的模型路径
6 load_in_4bit = load_in_4bit,
7)
8tokenizer = AutoTokenizer.from_pretrained("lora_model")1from unsloth import FastLanguageModel
2
3model, tokenizer = FastLanguageModel.from_pretrained(
4 model_name = "lora_model", # 您的模型路径
5 max_seq_length = max_seq_length,
6 dtype = dtype,
7 load_in_4bit = load_in_4bit,
8)
9FastLanguageModel.for_inference(model) # 启用原生 2 倍加速推理
10
11messages = [
12 {"role": "user", "content": "大夫,请问我最近脊椎靠近腰部的地方经常有疼痛感,请问是什么原因?"},
13 {"role":"assistant","content":"您好,根据您的症状描述,我怀疑您可能患有腰椎间盘突出症。这个症状常见于中老年人,由于椎间盘损伤或退行性变引起。根据我的经验,您可以考虑进行MRI检查来确认诊断。'"},
14 {"role": "user", "content": "大夫,我每天需要坐很久,是不是也和这个有关系?保持怎样的坐姿会改善呢?"},
15]
16inputs = tokenizer.apply_chat_template(
17 messages,
18 tokenize = True,
19 add_generation_prompt = True, # 必须添加以用于生成
20 return_tensors = "pt",
21).to("cuda")
22
23from transformers import TextStreamer
24text_streamer = TextStreamer(tokenizer, skip_prompt = True)
25_ = model.generate(input_ids = inputs, streamer = text_streamer, max_new_tokens = 128,
26 use_cache = True, temperature = 1.5, min_p = 0.1)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
pkg upgrade
pkg install git cmake golanggit clone --depth 1 https://github.com/ollama/ollama.git
cd ollama
go generate ./...
go build .
./ollama serve &
./ollama run lastmass/llama3.2-chinesechmod -R 700 ~/go
rm -r ~/gocp ollama/ollama /data/data/com.termux/files/usr/bin/ollama in your terminal directly!