跳到主要内容
极客日志极客日志面向AI+效率的开发者社区
首页博客我的书AI学习GitHub 精选镜像AI 生图工具UI配色美学关于
搜索内容 / 工具 / 仓库 / 镜像...⌘K搜索
注册
博客列表
PythonAI算法

Llama3 微调工具介绍及在 Ollama 中运行方法

四种主流的 Llama3 微调工具:MLX-LM、PyReft、LitGPT 和 LLaMA-Factory,详细说明了各工具的安装、配置、数据准备及训练步骤。同时讲解了如何将微调后的模型转换为 GGML 格式并在 Ollama 中部署运行,涵盖了从环境搭建到模型推理的完整流程,适用于希望本地化部署和优化大语言模型的技术人员。

云间漫步发布于 2025/2/7更新于 2026/9/1090 浏览
Llama3 微调工具介绍及在 Ollama 中运行方法

Llama3 是 Meta 提供的一个开源大模型,包含 8B 和 70B 两种参数规模,涵盖预训练和指令调优的变体。这个开源模型推出已经有一段时间,并且在许多标准测试中展示了其卓越的性能。特别是 Llama3 8B,其具备小尺寸和高质量的输出使其成为边缘设备或者移动设备上实现 LLM 的完美选择。但是 Llama3 也还有许多缺陷,因此,在场景应用中,有时候还需要对其进行微调,以提升中文能力、场景应用的专业度等。

目前有许多团队在做微调工具,他们的贡献提高了我们的效率、减少失误。比较优秀的例如:

  • MLX-LM
  • PyReft
  • litgpt
  • LLaMA-Factory

本文主要介绍如何使用这几个工具进行微调,以及如何在 Ollama 中安装运行微调后的模型。

01 MLX-LM

MLX 团队一直在不懈地努力改进 MLX-LM 库在模型微调工具方面的能力。使用 MLX-LM 微调 llama3 十分简单。

可以参考相关例子: https://github.com/ml-explore/mlx-examples/tree/main/llms/llama

大致步骤如下:

(1)准备训练数据

glaiveai/glaive-function-calling-v2 是一个专门用于训练大语言模型处理函数调用方面的数据集。我们可以下载这个数据集,并将数据转换为适合 Llama3 对话的格式,并保存到"/data"目录下。

数据下载地址: https://huggingface.co/datasets/glaiveai/glaive-function-calling-v2

数据格式转换的脚本如下:

from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, BitsAndBytesConfig
from datasets import load_dataset
import json

model_name = "meta-llama/Meta-Llama-3-8B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)

dataset = load_dataset("glaiveai/glaive-function-calling-v2", split="train")

def cleanup(input_string):
    arguments_index = input_string.find('"arguments"')
    if arguments_index == -1:
        return input_string
    start_quote = input_string.find("'", arguments_index)
    if start_quote == -1:
        return input_string
    end_quote = input_string.rfind("'")
    if end_quote == -  end_quote <= start_quote:
         input_string
    arguments_value = input_string[start_quote+:end_quote]
    output_string = input_string[:start_quote] + arguments_value + input_string[end_quote+:]
     output_string

 ():
    output_texts = []
     i  ((example[])):
        messages = [
            {
                : ,
                : example[][i][():].strip(),
            },
        ]
        conversations = example[][i].split()
         message  conversations:
            continue_outer = 
            message = message.strip()
             message:
                   message:
                    user_content = message.split()[].strip()
                    messages.append({: , : user_content[:].strip()})
                       message:
                        assistant_content = message.split()[].strip()
                           assistant_content:
                            text = assistant_content.replace(,).strip()
                            json_str = cleanup(text)
                            :
                                data = json.loads(json_str)
                             json.JSONDecodeError  e:
                                ()
                                continue_outer = 
                                
                            new_func_text = + json_str
                            messages.append({: , : new_func_text})
                        :
                            messages.append({: , : assistant_content})
                 message.startswith():
                    function_response = message[:].strip()
                       function_response:
                        function_content, assistant_content = function_response.split()
                        :
                            data = json.loads(function_content.strip())
                         json.JSONDecodeError  e:
                            ()
                            continue_outer = 
                            
                        messages.append({: , : function_content.strip()})
                        messages.append({: , : assistant_content.strip()})
                    :
                        :
                            data = json.loads(function_response.strip())
                         json.JSONDecodeError  e:
                            ()
                            continue_outer = 
                            
                        messages.append({: , : function_response.strip()})
                 message.startswith():
                    assistant_content = message.split()[].strip()
                       assistant_content:
                        text = assistant_content.replace(,).strip()
                        json_str = cleanup(text)
                        :
                            data = json.loads(json_str)
                         json.JSONDecodeError  e:
                            ()
                            continue_outer = 
                            
                        new_func_text = + json_str
                        messages.append({: , : new_func_text})
         continue_outer:
            
        text = tokenizer.apply_chat_template(messages, tokenize=, add_generation_prompt=)
        output_texts.append(text)
     example[]
     example[]
     {: output_texts}

dataset = dataset.(formatting_prompts_func, batched=)
1
or
return
1
1
return
def
formatting_prompts_func
example
for
in
range
len
'system'
"role"
"system"
"content"
'system'
len
"SYSTEM:"
'chat'
"<|endoftext|>"
for
in
False
if
if
"USER:"
in
"ASSISTANT:"
0
"role"
"user"
"content"
5
if
"ASSISTANT:"
in
"ASSISTANT:"
1
if
"<functioncall>"
in
"<functioncall>"
""
try
except
as
print
f"0 - Failed to decode JSON: {json_str} - {assistant_content}"
True
break
"<functioncall> "
"role"
"assistant"
"content"
else
"role"
"assistant"
"content"
elif
"FUNCTION RESPONSE:"
18
if
"ASSISTANT:"
in
"ASSISTANT:"
try
except
as
print
f"1 - Failed to decode JSON: {function_content}"
True
break
"role"
"user"
"content"
"role"
"assistant"
"content"
else
try
except
as
print
f"2 - Failed to decode JSON: {function_response}"
True
break
"role"
"user"
"content"
elif
"ASSISTANT:"
"ASSISTANT:"
1
if
"<functioncall>"
in
"<functioncall>"
""
try
except
as
print
f"3 - Failed to decode JSON: {json_str} - {assistant_content}"
True
break
"<functioncall> "
"role"
"assistant"
"content"
if
continue
False
False
del
'system'
del
'chat'
return
"text"
map
True

(2)安装 mlx-lm 包

pip install mlx-lm

这个库为微调 LLM 提供了一个友好的用户交互方式,省去了许多麻烦,并实现更好的效果。

(3)创建 LoRA 配置

通过配置 LoRA 来微调 Llama3 8B 模型。更改一些关键参数以优化性能:

使用 fp16 代替 qlora,以避免由于量化和解量化而导致的潜在性能下降。

将 lora_layers 设置为 32,并使用全线性层,以获得与全微调相媲美的结果。

以下是 lora_config.yaml 文件的示例:

# The path to the local model directory or Hugging Face repo.
model: "meta-llama/Meta-Llama-3-8B-Instruct"
# Whether or not to train (boolean)
train: true
   
# Directory with {train, valid, test}.jsonl files
data: "data"
   
# The PRNG seed
seed: 0
   
# Number of layers to fine-tune
lora_layers: 32
# Minibatch size.
batch_size: 1
# Iterations to train for.
iters: 6000
# Number of validation batches, -1 uses the entire validation set.
val_batches: 25
# Adam learning rate.
learning_rate: 1e-6
# Number of training steps between loss reporting.
steps_per_report: 10
# Number of training steps between validations.
steps_per_eval: 200
# Load path to resume training with the given adapter weights.
resume_adapter_file: null
# Save/load path for the trained adapter weights.
adapter_path: "adapters"
# Save the model every N iterations.
save_every: 1000
# Evaluate on the test set after training
test: false
# Number of test set batches, -1 uses the entire test set.
test_batches: 100
# Maximum sequence length.
max_seq_length: 8192
# Use gradient checkpointing to reduce memory use.
grad_checkpoint: true
# LoRA parameters can only be specified in a config file
lora_parameters:
  # The layer keys to apply LoRA to.
  # These will be applied for the last lora_layers
  keys: ['mlp.gate_proj', 'mlp.down_proj', 'self_attn.q_proj', 'mlp.up_proj', 'self_attn.o_proj','self_attn.v_proj', 'self_attn.k_proj']
  rank: 128
  alpha: 256
  scale: 10.0
  dropout: 0.05
   
# Schedule can only be specified in a config file, uncomment to use.
# lr_schedule:
#  name: cosine_decay
#  warmup: 100 # 0 for no warmup
#  warmup_init: 1e-7 # 0 if not specified
#  arguments: [1e-6, 1000, 1e-7] # passed to scheduler

(4)执行微调

在数据准备和 LoRA 配置就绪后,就可以开始微调 Llama3 8B 了,只需要运行以下命令。

mlx_lm.lora --config lora_config.yaml

(5)模型融合发布

LoRa 模型是无法单独完成推理的,需要和原生 Llama 结合才能运行。因为它 freeze 了原来的模型,单独加了一些层,后续的训练都在这些层上做,所以需要进行模型融合。

可以使用 mlx_lm.fuse 将训练过的适配器与原始的 Llama3 8B 模型以 HF 格式融合:

mlx_lm.fuse --model meta-llama/Meta-Llama-3-8B-Instruct

02 PyReft

项目源码: https://github.com/stanfordnlp/pyreft

ReFT 方法的出发点是基于干预模型可解释性的概念,该概念强调改变表示而不是权重。这个概念基于线性表示假设,该假设指出概念被编码在神经网络的线性子空间中。

PyReft 是一个基于 ReFT 方法的库,支持通过可训练的干预来调整内部语言模型的表示。PyReft 具有更少的微调参数和更强的鲁棒性,可以提高微调效率、降低微调成本,同时也为研究自适应参数的可解释性打开了大门。

PyReft 支持:

  • 微调发布在 HuggingFace 上任何预训练大模型
  • 可配置 ReFT 超参数
  • 轻松将微调后的结果分享到 HuggingFace

(1)安装依赖库

使用 Pip 安装最新版本的 transformers 以支持 llama3。此外,还需要安装 bitsandbytes 库。

!pip install -q git+https://github.com/huggingface/transformers
!pip install -q bitsandbytes

(2)安装或导入 pyreft

安装 Pyreft 库。如果已经安装则将导入 pyreft。

try:
    import pyreft
except ModuleNotFoundError:
    !pip install git+https://github.com/stanfordnlp/pyreft.git

(3)加载模型

在加载模型之前需要确保登陆到 huggingface,以便于访问 Llama3 模型,可以使用下面的代码片段:

from huggingface_hub import notebook_login
notebook_login()

接下来就是设置用于训练的提示词模板。由于我们将使用基础模型,因此需要添加特殊的标记,以便模型能够学会停止并且不继续生成文本。下面的代码片段用于执行加载模型和标记器。

import torch, transformers, pyreft
device = "cuda"

prompt_no_input_template = """<|begin_of_text|><|start_header_id|>user<|end_header_id|>%s<|eot_id|><|start_header_id|>assistant<|end_header_id|>"""

model_name_or_path = "meta-llama/Meta-Llama-3-8B"
model = transformers.AutoModelForCausalLM.from_pretrained(
    model_name_or_path, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)

# # get tokenizer
tokenizer = transformers.AutoTokenizer.from_pretrained(
    model_name_or_path, model_max_length=2048,
    padding_side="right", use_fast=False)
tokenizer.pad_token = tokenizer.eos_token

接着,设置 pyreft 配置,然后使用 pyreft.get_reft_model() 方法准备好模型。

# get reft model
reft_config = pyreft.ReftConfig(representations={
    "layer": 8, "component": "block_output",
    "low_rank_dimension": 4,
    "intervention": pyreft.LoreftIntervention(embed_dim=model.config.hidden_size,
    low_rank_dimension=4)})
reft_model = pyreft.get_reft_model(model, reft_config)
reft_model.set_device("cuda")
reft_model.print_trainable_parameters()

(4)准备数据集

下面以 OpenHermes—2.5 数据集为例。由于 Reft Trainer 的数据需要采用特定格式,因此我们使用:

pyreft.make_last_position_supervised_data_module()

来准备数据。

dataset_name = "teknium/OpenHermes-2.5"
from datasets import load_dataset

dataset = load_dataset(dataset_name, split="train")
dataset = dataset.select(range(10_000))

data_module = pyreft.make_last_position_supervised_data_module(
    tokenizer, model, [prompt_no_input_template % row["conversations"][0]["value"] for row in dataset],
    [row["conversations"][1]["value"] for row in dataset])

(5)执行训练

为 pyreft.ReftTrainerForCausalLM() 设置训练参数。可以根据自己的使用情况和计算资源进行更改。下面的代码参数设置只训练 1 个 epoch。

# train
training_args = transformers.TrainingArguments(
    per_device_train_batch_size = 4,
    gradient_accumulation_steps = 8,
    warmup_steps = 100,
    num_train_epochs = 1,
    learning_rate = 5e-4,
    bf16 = True,
    logging_steps = 1,
    optim = "paged_adamw_32bit",
    weight_decay = 0.0,
    lr_scheduler_type = "cosine",
    output_dir = "outputs",
    report_to=[]
)

trainer = pyreft.ReftTrainerForCausalLM(model=reft_model, tokenizer=tokenizer, args=training_args, **data_module)

_ = trainer.train()

训练完成后,将干预块保存到 reft_to_share 目录中。

reft_model.save(
    save_directory="./reft_to_share",
)

(6)发布与推理

模型微调训练完成后要进行推理。需要加载基本模型,并通过合并干预块来准备 reft 模型。然后将 reft 模型转移到 cuda。

import torch, transformers, pyreft
device = "cuda"

model_name_or_path = "meta-llama/Meta-Llama-3-8B"
model = transformers.AutoModelForCausalLM.from_pretrained(
    model_name_or_path, torch_dtype=torch.bfloat16, device_map=device)

reft_model = pyreft.ReftModel.load(
    "Syed-Hasan-8503/Llama-3-openhermes-reft", model, from_huggingface_hub=True
)

reft_model.set_device("cuda")

接着进行推理测试:

instruction = "A rectangular garden has a length of 25 feet and a width of 15 feet. If you want to build a fence around the entire garden, how many feet of fencing will you need?"

# tokenize and prepare the input
prompt = prompt_no_input_template % instruction
prompt = tokenizer(prompt, return_tensors="pt").to(device)

base_unit_location = prompt["input_ids"].shape[-1] - 1  # last position
_, reft_response = reft_model.generate(
    prompt, unit_locations={"sources->base": (None, [[[base_unit_location]]])},
    intervene_on_prompt=True, max_new_tokens=512, do_sample=True,
    eos_token_id=tokenizer.eos_token_id, early_stopping=True
)
print(tokenizer.decode(reft_response[0], skip_special_tokens=True))

03 LitGPT

源代码: https://github.com/Lightning-AI/litgpt

LitGPT 是一个可以用于微调预训练模型的命令行工具,支持 20 多个 LLM 的评估、部署。它为世界上最强大的开源大型语言模型(LLM)提供了高度优化的训练配方。

(1)安装

pip install 'litgpt[all]'

(2)评估测试

选择一个模型并执行:下载、对话、微调、预训练以及部署等。

# ligpt [action] [model]
litgpt  download  meta-llama/Meta-Llama-3-8B-Instruct
litgpt  chat      meta-llama/Meta-Llama-3-8B-Instruct
litgpt  finetune  meta-llama/Meta-Llama-3-8B-Instruct
litgpt  pretrain  meta-llama/Meta-Llama-3-8B-Instruct
litgpt  serve     meta-llama/Meta-Llama-3-8B-Instruct

例如:使用微软的 phi-2 进行对话评估。

# 1) Download a pretrained model
litgpt download --repo_id microsoft/phi-2

# 2) Chat with the model
litgpt chat \
--checkpoint_dir checkpoints/microsoft/phi-2

>> Prompt: What do Llamas eat?

(3)微调模型

下面是在 phi-2 基础上进行微调的命令。

# 1) Download a pretrained model
litgpt download --repo_id microsoft/phi-2

# 2) Finetune the model
curl -L https://huggingface.co/datasets/ksaw008/finance_alpaca/resolve/main/finance_alpaca.json -o my_custom_dataset.json

litgpt finetune \
--checkpoint_dir checkpoints/microsoft/phi-2 \
--data JSON \
--data.json_path my_custom_dataset.json \
--data.val_split_fraction 0.1 \
--out_dir out/custom-model

# 3) Chat with the model
litgpt chat \
--checkpoint_dir out/custom-model/final

除此外,还可以基于自己的数据进行训练。详细参考 GitHub。

(4)部署

通过下面的部署命令,启动模型服务。

# locate the checkpoint to your finetuned or pretrained model and call the `serve` command:
litgpt serve --checkpoint_dir path/to/your/checkpoint/microsoft/phi-2

# Alternative: if you haven't finetuned, download any checkpoint to deploy it:
litgpt download --repo_id microsoft/phi-2
litgpt serve --checkpoint_dir checkpoints/microsoft/phi-2

通过 Http API 访问服务。

# Use the server (in a separate session)
import requests, json
response = requests.post(
     "http://127.0.0.1:8000/predict",
     json={"prompt": "Fix typos in the following sentence: Exampel input"}
)
print(response.json()["output"])

04 LLaMA-Factory

源代码: https://github.com/hiyouga/LLaMA-Factory/

LLaMA-Factory 是一个开源项目,它提供了一套全面的工具和脚本,用于微调、部署和基准测试 LLaMA 模型。

LLaMA-Factory 提供以下功能,使得我们可以轻松地使用 LLaMA 模型:

  • 数据预处理和标记化的脚本
  • 用于微调 LLaMA 模型的训练流程
  • 使用经过训练的模型生成文本的推理脚本
  • 评估模型性能的基准测试工具
  • 用于交互式测试的 Gradio Web UI

使用 LLaMA-Factory 进行微调的步骤如下:

(1)数据准备

LLaMA-Factory 要求训练数据的格式如下:

[
  {
    "instruction": "What is the capital of France?",
    "input": "",
    "output": "Paris is the capital of France."
  },
  ...
]

每个 JSON 对象代表一个训练示例,其中包含以下字段:

  • instruction:任务指令或提示
  • input:任务的附加上下文(可以为空)
  • output:目标完成或响应

(2)下载安装依赖包

git clone https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip install -r requirements.txt

(3)执行微调

支持使用 Python 进行微调也支持图形化界面的方式。

下面是执行 python 脚本进行微调:

python finetune.py \
--model_name llama-7b \
--data_path data/alpaca_data_tokenized.json \
--output_dir output/llama-7b-alpaca \
--num_train_epochs 3 \
--batch_size 128 \
--learning_rate 2e-5 \
--fp16

该脚本将加载预训练的 LLaMA 模型,准备训练数据集,并使用指定的超参数运行微调脚步。微调后的模型检查点将保存在 output_dir。

主要参数设置如下:

  • model_name:要微调的基础 LLaMA 模型,例如 llama-7b
  • data_path:标记数据集的路径
  • output_dir:保存微调模型的目录
  • num_train_epochs:训练周期数
  • batch_size:训练的批次大小
  • learning_rate:优化器的学习率
  • fp16:使用 FP16 混合精度来减少内存使用量

接着使用微调后的结果进行推理测试:

python generate.py \
--model_path output/llama-7b-alpaca \
--prompt "What is the capital of France?"

当然,微调过程也可以在可视化界面上进行。首先需要启动 GUI 界面。

python web_ui.py

(4)基准测试

LLaMA-Factory 包含了基于各种评估数据集进行基准测试的脚本 benchmark.py。

例如:

python benchmark.py \
--model_path output/llama-7b-alpaca \
--benchmark_datasets alpaca,hellaswag

这个 Python 命令将加载经过微调的模型并评估其在指定方面的表现。

benchmark_datasets 参数指明使用哪些数据集进行评估。评估报告包括:准确度、困惑度和 F1 分数等指标。

还可以使用 DatasetBuilder 实现一个类并将其注册到基准脚本来添加您自己的评估数据集。

如何在 Ollama 中安装微调后的 Llama3 模型?

Ollama 是一个开源的大模型管理工具,它提供了丰富的功能,包括模型的训练、部署、监控等。通过 Ollama,可以轻松地管理本地的大模型,提高模型的训练速度和部署效率。Ollama 支持多种机器学习框架,如 TensorFlow、PyTorch 等,因此,我们可以根据需要选择合适的框架进行模型训练。

在使用 LLaMA-Factory 进行微调之后,会生成 LoRA 文件,如何在 Ollama 中运行 llama3 和我们训练出来的 LoRA 呢?

步骤如下:

(1)运行 Ollama

直接安装或者通过 Docker 安装运行 Ollama

docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama

(2)GGML 格式转换

按照 Ollama modelfile ADAPTER 的说明,Ollama 支持 ggml 格式的 LoRA,所以我们需要把微调生成的 LoRA 转换成 ggml 格式。为此,我们需要使用到 Llama.cpp 的格式转换脚本:"conver-lora-to-ggml.py"。

例如:

./conver-lora-to-ggml.py /output/llama3_cn_01 llama

执行完命令后,将在 /output/llama3_cn_01 下生成 ggml-adapter-model.bin 文件。这个文件就是 Ollama 所需要的 ggml 格式 LoRA 文件。

(3)在 Ollama 中创建自定义 Llama3 模型

使用 ollama 的 modelfile 来创建自定义 llama3 模型。需要创建一个 modefile 文件。
我们创建一个 llama3.modelfile,其内容如下:
# set the base model
FROM llama3:8b

# set custom parameter values
PARAMETER temperature 1
PARAMETER num_keep 24
PARAMETER stop <|start_header_id|>
PARAMETER stop <|end_header_id|>
PARAMETER stop <|eot_id|>
PARAMETER stop <|reserved_special_token

# set the model template
TEMPLATE """
{{ 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|>
{{ .Response }}<|eot_id|>
"""

# set the system message
SYSTEM You are llama3 from Meta.

# set Chinese lora support
ADAPTER /root/.ollama/models/lora/ggml-adapter-model.bin

接着使用 Ollama 命令以及 modelfile 来创建自定义模型:

ollama create llama3:c01 -f llama3.modelfile

查看模型列表:

ollama list

运行模型:

ollama run llama3:c01

目录

  1. 01 MLX-LM
  2. (1)准备训练数据
  3. (2)安装 mlx-lm 包
  4. (3)创建 LoRA 配置
  5. The path to the local model directory or Hugging Face repo.
  6. Whether or not to train (boolean)
  7. Directory with {train, valid, test}.jsonl files
  8. The PRNG seed
  9. Number of layers to fine-tune
  10. Minibatch size.
  11. Iterations to train for.
  12. Number of validation batches, -1 uses the entire validation set.
  13. Adam learning rate.
  14. Number of training steps between loss reporting.
  15. Number of training steps between validations.
  16. Load path to resume training with the given adapter weights.
  17. Save/load path for the trained adapter weights.
  18. Save the model every N iterations.
  19. Evaluate on the test set after training
  20. Number of test set batches, -1 uses the entire test set.
  21. Maximum sequence length.
  22. Use gradient checkpointing to reduce memory use.
  23. LoRA parameters can only be specified in a config file
  24. The layer keys to apply LoRA to.
  25. These will be applied for the last lora_layers
  26. Schedule can only be specified in a config file, uncomment to use.
  27. lr_schedule:
  28. name: cosine_decay
  29. warmup: 100 # 0 for no warmup
  30. warmup_init: 1e-7 # 0 if not specified
  31. arguments: [1e-6, 1000, 1e-7] # passed to scheduler
  32. (4)执行微调
  33. (5)模型融合发布
  34. 02 PyReft
  35. (1)安装依赖库
  36. (2)安装或导入 pyreft
  37. (3)加载模型
  38. # get tokenizer
  39. get reft model
  40. (4)准备数据集
  41. (5)执行训练
  42. train
  43. (6)发布与推理
  44. tokenize and prepare the input
  45. 03 LitGPT
  46. (1)安装
  47. (2)评估测试
  48. ligpt [action] [model]
  49. 1) Download a pretrained model
  50. 2) Chat with the model
  51. (3)微调模型
  52. 1) Download a pretrained model
  53. 2) Finetune the model
  54. 3) Chat with the model
  55. (4)部署
  56. locate the checkpoint to your finetuned or pretrained model and call the serve command:
  57. Alternative: if you haven't finetuned, download any checkpoint to deploy it:
  58. Use the server (in a separate session)
  59. 04 LLaMA-Factory
  60. (1)数据准备
  61. (2)下载安装依赖包
  62. (3)执行微调
  63. (4)基准测试
  64. 如何在 Ollama 中安装微调后的 Llama3 模型?
  65. (1)运行 Ollama
  66. (2)GGML 格式转换
  67. (3)在 Ollama 中创建自定义 Llama3 模型
  68. 使用 ollama 的 modelfile 来创建自定义 llama3 模型。需要创建一个 modefile 文件。
  69. 我们创建一个 llama3.modelfile,其内容如下:
  70. set the base model
  71. set custom parameter values
  72. set the model template
  73. set the system message
  74. set Chinese lora support

更多推荐文章

查看全部
  • Llama-3.2-3B 本地部署实战:Ollama 与 Open WebUI 集成指南
  • Qwen3 与 Qwen Agent 智能体开发实战:接入 MCP 工具
  • 基于 Spring Boot 的家庭财务管理系统设计与实现
  • FPGA 设计调试:Vivado ILA 高级触发模式配置
  • 深入理解 HTML5 Web Workers:提升网页性能的关键技术
  • 基于 Java 的无人共享宠物洗澡物联网系统设计与实现
  • 鸿蒙 4.2/4.3 系统安装谷歌服务框架指南
  • VSCode 通义灵码插件安装配置与实战教程
  • 本地运行 Google 开源 AI 大模型 Gemma 完整教程
  • Python 实现 MCP 客户端调用高德地图天气查询示例
  • Gemini 学生计划实战指南:将免费 Pro 权限转化为 AI 求职竞争力
  • OpenClaw 视觉操作实战:AI 直接点按钮操作软件
  • 基于平台化与低代码重构制造业 EDI 系统方案
  • C 语言指针与函数的高级应用与底层原理
  • Java IO 流进阶:字符流与字节流的深度应用
  • 基于 Java + SpringBoot + Vue 的图书大厦管理系统设计与实现
  • AIGC 时代的网络安全威胁与应急响应机制构建
  • Linux 动静态库与 ELF 加载全解析:从制作到底层原理
  • OpenClaw 多机器人协作方案:基于飞书构建智能体团队
  • 通义万相 2.1 视频生成模型部署与架构解析

相关免费在线工具

  • 加密/解密文本

    使用加密算法(如AES、TripleDES、Rabbit或RC4)加密和解密文本明文。 在线工具,加密/解密文本在线工具,online

  • RSA密钥对生成器

    生成新的随机RSA私钥和公钥pem证书。 在线工具,RSA密钥对生成器在线工具,online

  • Mermaid 预览与可视化编辑

    基于 Mermaid.js 实时预览流程图、时序图等图表,支持源码编辑与即时渲染。 在线工具,Mermaid 预览与可视化编辑在线工具,online

  • 随机西班牙地址生成器

    随机生成西班牙地址(支持马德里、加泰罗尼亚、安达卢西亚、瓦伦西亚筛选),支持数量快捷选择、显示全部与下载。 在线工具,随机西班牙地址生成器在线工具,online

  • Gemini 图片去水印

    基于开源反向 Alpha 混合算法去除 Gemini/Nano Banana 图片水印,支持批量处理与下载。 在线工具,Gemini 图片去水印在线工具,online

  • curl 转代码

    解析常见 curl 参数并生成 fetch、axios、PHP curl 或 Python requests 示例代码。 在线工具,curl 转代码在线工具,online