月度归档:2024年12月

OLLAMA modelfile 设置

https://ollama.com/library/qwen2.5:3b 可以设置为modelfile

modelfile ollama

FROM /Users/may/new_xxxxx.gguf
#导入gguf文件 下面的必须设置

TEMPLATE """{{- if .Messages }}
{{- if or .System .Tools }}<|im_start|>system
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}

# Tools

You may call one or more functions to assist with the user query.

You are provided with function signatures within <tools></tools> XML tags:
<tools>
{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}
{{- end }}
</tools>

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end }}<|im_end|>
{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}<|im_end|>
{{ else if eq .Role "assistant" }}<|im_start|>assistant
{{ if .Content }}{{ .Content }}
{{- else if .ToolCalls }}<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{ end }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
{{ end }}
{{- end }}
{{- else }}
{{- if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}"""

SYSTEM "你是一个友好的人工智能助手,回答问题时要简洁明了。"

LLAMA.CPP转换GGUF

python convert_hf_to_gguf.py /Users/may/mlx/mlx-examples/lora/qwen2.5-0.5B-test_1 --outtype bf16  --outfile ../qwen.gguf

llama.cpp 转safetensors为GGUF,导入LM studio

安装llama.cpp conda下不知道怎么一直安装失败

git clone https://github.com/ggerganov/llama.cpp.git

#或者
git clone https://bgithub.xyz/ggerganov/llama.cpp.git

cd llama.cpp



pip install -r requirements.txt  -i https://mirrors.aliyun.com/pypi/simple/
python convert_hf_to_gguf.py /Users/may/mlx/mlx-examples/lora/qwen2.5-0.5B-test_1 --outtype bf16  --outfile ../tc.gguf


/Users/may/mlx/mlx-examples/lora/qwen2.5-0.5B-test_1 mlx打包好的地址

../tc.gguf 存放的gguf地址

安装LM STUDIO 倒入文件夹可以识别GGUF模型。

可以创建API 也可以直接调用

MLX微调好的模型 加入到ollama运行

git clone https://github.com/ggerganov/llama.cpp

git clone https://bgithub.xyz/ggerganov/llama.cpp

cd llama.cpp
make -j  # 这里使用多线程编译,具体线程数根据你的CPU核心数来定

pip install -r requirements.txt -i 
https://mirrors.aliyun.com/pypi/simple/

Conda 下MLX LORA

安装CONDA

Download Anaconda Distribution | Anaconda

首先安装好,win64 下 960MB

pip install mlx-lm transformers numpy huggingface_hub
#下不了的用阿里的镜像


pip install mlx-lm transformers numpy huggingface_hub -i https://mirrors.aliyun.com/pypi/simple/


export HF_ENDPOINT=https://hf-mirror.com 
#设置镜像
huggingface-cli download --resume-download Qwen/Qwen2.5-0.5B-Instruct --local-dir qwen2.5-0.5B
#下载Qwen2.5 0.5B

#下载MLX example
git clone https://github.com/ml-explore/mlx-examples.git
#若下载失败可以使用
git clone https://bgithub.xyz/ml-explore/mlx-examples.git

#修改其中lora/data/train.jsonl


#微调 lora
mlx_lm.lora --model ../../qwen2.5-0.5B --train --data ./data

#合并
mlx_lm.fuse --model ../../qwen2.5-0.5B --adapter-path adapters --save-path qwen2.5-0.5B-test_1

#调用微调好的模型
mlx_lm.generate --model qwen2.5-0.5B-test_1 --prompt "蓝牙耳机坏了应该看什么科"

#调用原始的数据
mlx_lm.generate --model ../../qwen2.5-0.5B --prompt "蓝牙耳机坏了应该看什么科"

ThinkPHP6 create save

insert , instertGetID

#插入数据库 可以静态调用

$insert['user_id']=cmf_get_current_admin_id();
$insert["date"]=$date;
$insert["time"]=time();
return MeetingModel::insertGetId($insert);
#插入数据库  可以静态调用
return MeetingModel::insertGetId($insert);

create 用于保存 数组

$data = [
    'name' => '用户名',
    'email' => 'user@example.com',
    // ... 其他字段
];

// 使用create方法插入数据
$id = User::create($data);

$id = User->create($data);

save 用于对象保存 save 不可以静态调用

// 创建一个新的模型实例
$user = new User();

// 给模型赋值
$user->name = $data['name'];
$user->email = $data['email'];
// ... 设置其他字段

// 保存数据
$result = $user->save();
#里面空