(笔记+作业)书生大模型实战营春节卷王班---L1G5000 XTuner 微调个人小助手认知

XTuner 微调个人小助手认知实战 ​ 本次实践是在InternStudio平台上,运用XTuner工具来微调InterLM2-Chat-1.8B模型,实现模型身份认证问题的解决。具体来说,如下图,让模型在回答自身身份问题的时候,加入你想要的信息。 ​ 阅读详情

学员闯关手册:https://aicarrier.feishu.cn/wiki/QtJnweAW1iFl8LkoMKGcsUS9nld
课程视频:https://www.bilibili.com/video/BV13U1VYmEUr/
课程文档:https://github.com/InternLM/Tutorial/tree/camp4/docs/L0/Python
关卡作业:https://github.com/InternLM/Tutorial/blob/camp4/docs/L0/Python/task.md
开发机平台:https://studio.intern-ai.org.cn/
开发机平台介绍:https://aicarrier.feishu.cn/wiki/GQ1Qwxb3UiQuewk8BVLcuyiEnHe
书生浦语官网:https://internlm.intern-ai.org.cn/
github网站:https://github.com/internLM/
XTuner 文档链接:https://xtuner.readthedocs.io/zh-cn/latest/
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

基础任务:完成个人小助手微调

#环境坏了删除环境和文件
conda deactivate
conda env remove --name xtuner-env
# 删除目录
rm -rf /root/.conda/envs/xtuner-env
#并删除文件夹Tutorial、finetune、InternLM
conda env list
#1、环境配置与数据准备
#使用 conda 先构建一个 Python-3.10 的虚拟环境
cd ~
#git clone 本repo,先在我的云盘里删去Tutorial文件夹
git clone https://github.com/InternLM/Tutorial.git -b camp4 #文件夹多了Tutorial
mkdir -p /root/finetune && cd /root/finetune #文件夹多了finetune
conda create -n xtuner-env python=3.10 -y
conda activate xtuner-env

# 安装 XTuner
cd /root/Tutorial/docs/L1/XTuner
pip install -r requirements.txt
#如果报错,换成pip install --trusted-host mirrors.aliyun.com -e '.[deepspeed]' -i https://mirrors.aliyun.com/pypi/simple/
#验证是否安装成功
xtuner list-cfg

#2、修改提供的数据
#2.1、创建一个新的文件夹用于存储微调数据
mkdir -p /root/finetune/data && cd /root/finetune/data   #多一个finetune文件夹
cp -r /root/Tutorial/data/assistant_Tuner.jsonl  /root/finetune/data

# 2.2、创建 `change_script.py` 文件
touch /root/finetune/data/change_script.py
#2.3、编辑change_script.py
# usage:python change_script.py {input_file.jsonl} {output_file.jsonl}
cd ~/finetune/data
python change_script.py ./assistant_Tuner.jsonl ./assistant_Tuner_change.jsonl #assistant_Tuner_change.jsonl 是修改后符合 XTuner 格式的训练数据。
#查看数据cat assistant_Tuner_change.jsonl | head -n 3

#3、复制模型和修改config
#3.1、复制模型
mkdir /root/finetune/models
ln -s /root/share/new_models/Shanghai_AI_Laboratory/internlm2_5-7b-chat /root/finetune/models/internlm2_5-7b-chat
#3.2、修改 Config
# cd {path/to/finetune}
cd /root/finetune
mkdir ./config
cd config
xtuner copy-cfg internlm2_5_chat_7b_qlora_alpaca_e3 ./
#修改 Config,或者本教程已经将改好的 config 放在了 ~/Tutorial/configs/internlm2_5_chat_7b_qlora_alpaca_e3_copy.py 同学们可以直接使用(前置步骤路径一致的情况下)

#4、训练
#4.1、启动微调
cd /root/finetune
conda activate xtuner-env
xtuner train ./config/internlm2_5_chat_7b_qlora_alpaca_e3_copy.py --deepspeed deepspeed_zero2 --work-dir ./work_dirs/assistTuner
#4.2、权重转换
cd /root/finetune/work_dirs/assistTuner
conda activate xtuner-env
# 先获取最后保存的一个pth文件
pth_file=`ls -t /root/finetune/work_dirs/assistTuner/*.pth | head -n 1 | sed 's/:$//'`
export MKL_SERVICE_FORCE_INTEL=1
export MKL_THREADING_LAYER=GNU
#xtuner convert pth_to_hf 命令用于进行模型格式转换。该命令需要三个参数:CONFIG 表示微调的配置文件, PATH_TO_PTH_MODEL 表示微调的模型权重文件路径,即要转换的模型权重, SAVE_PATH_TO_HF_MODEL 表示转换后的 HuggingFace 格式文件的保存路径。
xtuner convert pth_to_hf ./internlm2_5_chat_7b_qlora_alpaca_e3_copy.py ${pth_file} ./hf
#此时,hf 文件夹即为我们平时所理解的所谓 “LoRA 模型文件”,可以简单理解:LoRA 模型文件 = Adapter
#4.3、模型合并
#xtuner convert merge命令用于合并模型。该命令需要三个参数:LLM 表示原模型路径,ADAPTER 表示 Adapter 层的路径, SAVE_PATH 表示合并后的模型最终的保存路径。
cd /root/finetune/work_dirs/assistTuner
conda activate xtuner-env
export MKL_SERVICE_FORCE_INTEL=1
export MKL_THREADING_LAYER=GNU
xtuner convert merge /root/finetune/models/internlm2_5-7b-chat ./hf ./merged --max-shard-size 2GB

#5、模型 WebUI 对话
#5.1、修改xtuner_streamlit_demo.py
cd ~/Tutorial/tools/L1_XTuner_code
# 直接修改脚本文件xtuner_streamlit_demo.py第18行
- model_name_or_path = "Shanghai_AI_Laboratory/internlm2_5-7b-chat"
+ model_name_or_path = "/root/finetune/work_dirs/assistTuner/merged"
#进行ssh端口映射
#ssh -CNg -L 8501:127.0.0.1:8501 root@ssh.intern-ai.org.cn -p 48021
#5.2、直接启动应用
conda activate xtuner-env
pip install streamlit==1.31.0
streamlit run /root/Tutorial/tools/L1_XTuner_code/xtuner_streamlit_demo.py
#浏览器http://127.0.0.1:8501
#2.3、change_script.py
import json
import argparse
from tqdm import tqdm

def process_line(line, old_text, new_text):
    # 解析 JSON 行
    data = json.loads(line)
    
    # 递归函数来处理嵌套的字典和列表
    def replace_text(obj):
        if isinstance(obj, dict):
            return {k: replace_text(v) for k, v in obj.items()}
        elif isinstance(obj, list):
            return [replace_text(item) for item in obj]
        elif isinstance(obj, str):
            return obj.replace(old_text, new_text)
        else:
            return obj
    
    # 处理整个 JSON 对象
    processed_data = replace_text(data)
    
    # 将处理后的对象转回 JSON 字符串
    return json.dumps(processed_data, ensure_ascii=False)

def main(input_file, output_file, old_text, new_text):
    with open(input_file, 'r', encoding='utf-8') as infile, \
         open(output_file, 'w', encoding='utf-8') as outfile:
        
        # 计算总行数用于进度条
        total_lines = sum(1 for _ in infile)
        infile.seek(0)  # 重置文件指针到开头
        
        # 使用 tqdm 创建进度条
        for line in tqdm(infile, total=total_lines, desc="Processing"):
            processed_line = process_line(line.strip(), old_text, new_text)
            outfile.write(processed_line + '\n')

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Replace text in a JSONL file.")
    parser.add_argument("input_file", help="Input JSONL file to process")
    parser.add_argument("output_file", help="Output file for processed JSONL")
    parser.add_argument("--old_text", default="尖米", help="Text to be replaced")
    parser.add_argument("--new_text", default="朱娅梅", help="Text to replace with")
    args = parser.parse_args()

    main(args.input_file, args.output_file, args.old_text, args.new_text)
#3.2、修改config
#######################################################################
#                          PART 1  Settings                           #
#######################################################################
- pretrained_model_name_or_path = 'internlm/internlm2_5-7b-chat'
+ pretrained_model_name_or_path = '/root/finetune/models/internlm2_5-7b-chat'

- alpaca_en_path = 'tatsu-lab/alpaca'
+ alpaca_en_path = '/root/finetune/data/assistant_Tuner_change.jsonl'


evaluation_inputs = [
-    '请给我介绍五个上海的景点', 'Please tell me five scenic spots in Shanghai'
+    '请介绍一下你自己', 'Please introduce yourself'
]

#######################################################################
#                      PART 3  Dataset & Dataloader                   #
#######################################################################
alpaca_en = dict(
    type=process_hf_dataset,
-   dataset=dict(type=load_dataset, path=alpaca_en_path),
+   dataset=dict(type=load_dataset, path='json', data_files=dict(train=alpaca_en_path)),
    tokenizer=tokenizer,
    max_length=max_length,
-   dataset_map_fn=alpaca_map_fn,
+   dataset_map_fn=None,
    template_map_fn=dict(
        type=template_map_fn_factory, template=prompt_template),
    remove_unused_columns=True,
    shuffle_before_pack=True,
    pack_to_max_length=pack_to_max_length,
    use_varlen_attn=use_varlen_attn)

在这里插入图片描述

#3.2、修改后的config
# Copyright (c) OpenMMLab. All rights reserved.
import torch
from datasets import load_dataset
from mmengine.dataset import DefaultSampler
from mmengine.hooks import (CheckpointHook, DistSamplerSeedHook, IterTimerHook,
                            LoggerHook, ParamSchedulerHook)
from mmengine.optim import AmpOptimWrapper, CosineAnnealingLR, LinearLR
from peft import LoraConfig
from torch.optim import AdamW
from transformers import (AutoModelForCausalLM, AutoTokenizer,
                          BitsAndBytesConfig)

from xtuner.dataset import process_hf_dataset
from xtuner.dataset.collate_fns import default_collate_fn
from xtuner.dataset.map_fns import alpaca_map_fn, template_map_fn_factory
from xtuner.engine.hooks import (DatasetInfoHook, EvaluateChatHook,
                                 VarlenAttnArgsToMessageHubHook)
from xtuner.engine.runner import TrainLoop
from xtuner.model import SupervisedFinetune
from xtuner.parallel.sequence import SequenceParallelSampler
from xtuner.utils import PROMPT_TEMPLATE, SYSTEM_TEMPLATE

#######################################################################
#                          PART 1  Settings                           #
#######################################################################
# Model
pretrained_model_name_or_path = '/root/finetune/models/internlm2_5-7b-chat'
use_varlen_attn = False

# Data
alpaca_en_path = '/root/finetune/data/assistant_Tuner_change.jsonl'
prompt_template = PROMPT_TEMPLATE.internlm2_chat
max_length = 2048
pack_to_max_length = True

# parallel
sequence_parallel_size = 1

# Scheduler & Optimizer
batch_size = 1  # per_device
accumulative_counts = 1
accumulative_counts *= sequence_parallel_size
dataloader_num_workers = 0
max_epochs = 3
optim_type = AdamW
lr = 2e-4
betas = (0.9, 0.999)
weight_decay = 0
max_norm = 1  # grad clip
warmup_ratio = 0.03

# Save
save_steps = 500
save_total_limit = 2  # Maximum checkpoints to keep (-1 means unlimited)

# Evaluate the generation performance during the training
evaluation_freq = 500
SYSTEM = SYSTEM_TEMPLATE.alpaca
evaluation_inputs = [
    '请介绍一下你自己', 'Please introduce yourself'
]

#######################################################################
#                      PART 2  Model & Tokenizer                      #
#######################################################################
tokenizer = dict(
    type=AutoTokenizer.from_pretrained,
    pretrained_model_name_or_path=pretrained_model_name_or_path,
    trust_remote_code=True,
    padding_side='right')

model = dict(
    type=SupervisedFinetune,
    use_varlen_attn=use_varlen_attn,
    llm=dict(
        type=AutoModelForCausalLM.from_pretrained,
        pretrained_model_name_or_path=pretrained_model_name_or_path,
        trust_remote_code=True,
        torch_dtype=torch.float16,
        quantization_config=dict(
            type=BitsAndBytesConfig,
            load_in_4bit=True,
            load_in_8bit=False,
            llm_int8_threshold=6.0,
            llm_int8_has_fp16_weight=False,
            bnb_4bit_compute_dtype=torch.float16,
            bnb_4bit_use_double_quant=True,
            bnb_4bit_quant_type='nf4')),
    lora=dict(
        type=LoraConfig,
        r=64,
        lora_alpha=16,
        lora_dropout=0.1,
        bias='none',
        task_type='CAUSAL_LM'))

#######################################################################
#                      PART 3  Dataset & Dataloader                   #
#######################################################################
alpaca_en = dict(
    type=process_hf_dataset,
    dataset=dict(type=load_dataset, path='json', data_files=dict(train=alpaca_en_path)),
    tokenizer=tokenizer,
    max_length=max_length,
    dataset_map_fn=None,
    template_map_fn=dict(
        type=template_map_fn_factory, template=prompt_template),
    remove_unused_columns=True,
    shuffle_before_pack=True,
    pack_to_max_length=pack_to_max_length,
    use_varlen_attn=use_varlen_attn)

sampler = SequenceParallelSampler \
    if sequence_parallel_size > 1 else DefaultSampler
train_dataloader = dict(
    batch_size=batch_size,
    num_workers=dataloader_num_workers,
    dataset=alpaca_en,
    sampler=dict(type=sampler, shuffle=True),
    collate_fn=dict(type=default_collate_fn, use_varlen_attn=use_varlen_attn))

#######################################################################
#                    PART 4  Scheduler & Optimizer                    #
#######################################################################
# optimizer
optim_wrapper = dict(
    type=AmpOptimWrapper,
    optimizer=dict(
        type=optim_type, lr=lr, betas=betas, weight_decay=weight_decay),
    clip_grad=dict(max_norm=max_norm, error_if_nonfinite=False),
    accumulative_counts=accumulative_counts,
    loss_scale='dynamic',
    dtype='float16')

# learning policy
# More information: https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/param_scheduler.md  # noqa: E501
param_scheduler = [
    dict(
        type=LinearLR,
        start_factor=1e-5,
        by_epoch=True,
        begin=0,
        end=warmup_ratio * max_epochs,
        convert_to_iter_based=True),
    dict(
        type=CosineAnnealingLR,
        eta_min=0.0,
        by_epoch=True,
        begin=warmup_ratio * max_epochs,
        end=max_epochs,
        convert_to_iter_based=True)
]

# train, val, test setting
train_cfg = dict(type=TrainLoop, max_epochs=max_epochs)

#######################################################################
#                           PART 5  Runtime                           #
#######################################################################
# Log the dialogue periodically during the training process, optional
custom_hooks = [
    dict(type=DatasetInfoHook, tokenizer=tokenizer),
    dict(
        type=EvaluateChatHook,
        tokenizer=tokenizer,
        every_n_iters=evaluation_freq,
        evaluation_inputs=evaluation_inputs,
        system=SYSTEM,
        prompt_template=prompt_template)
]

if use_varlen_attn:
    custom_hooks += [dict(type=VarlenAttnArgsToMessageHubHook)]

# configure default hooks
default_hooks = dict(
    # record the time of every iteration.
    timer=dict(type=IterTimerHook),
    # print log every 10 iterations.
    logger=dict(type=LoggerHook, log_metric_by_epoch=False, interval=10),
    # enable the parameter scheduler.
    param_scheduler=dict(type=ParamSchedulerHook),
    # save checkpoint per `save_steps`.
    checkpoint=dict(
        type=CheckpointHook,
        by_epoch=False,
        interval=save_steps,
        max_keep_ckpts=save_total_limit),
    # set sampler seed in distributed evrionment.
    sampler_seed=dict(type=DistSamplerSeedHook),
)

# configure environment
env_cfg = dict(
    # whether to enable cudnn benchmark
    cudnn_benchmark=False,
    # set multi process parameters
    mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0),
    # set distributed parameters
    dist_cfg=dict(backend='nccl'),
)

# set visualizer
visualizer = None

# set log level
log_level = 'INFO'

# load from which checkpoint
load_from = None

# whether to resume training from the loaded checkpoint
resume = False

# Defaults to use random seed and disable `deterministic`
randomness = dict(seed=None, deterministic=False)

# set log processor
log_processor = dict(by_epoch=False)

4.3、模型合并后文件目录结构
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

#5.1、修改xtuner_streamlit_demo.py
"""This script refers to the dialogue example of streamlit, the interactive
generation code of chatglm2 and transformers.

We mainly modified part of the code logic to adapt to the
generation of our model.
Please refer to these links below for more information:
    1. streamlit chat example:
        https://docs.streamlit.io/knowledge-base/tutorials/build-conversational-apps
    2. chatglm2:
        https://github.com/THUDM/ChatGLM2-6B
    3. transformers:
        https://github.com/huggingface/transformers
Please run with the command `streamlit run path/to/web_demo.py
    --server.address=0.0.0.0 --server.port 7860`.
Using `python path/to/web_demo.py` may cause unknown problems.
"""
# isort: skip_file
import copy
import warnings
from dataclasses import asdict, dataclass
from typing import Callable, List, Optional

import streamlit as st
import torch
from torch import nn
from transformers.generation.utils import (LogitsProcessorList,
                                           StoppingCriteriaList)
from transformers.utils import logging

from transformers import AutoTokenizer, AutoModelForCausalLM  # isort: skip

logger = logging.get_logger(__name__)
model_name_or_path="/root/finetune/work_dirs/assistTuner/merged"

@dataclass
class GenerationConfig:
    # this config is used for chat to provide more diversity
    max_length: int = 32768
    top_p: float = 0.8
    temperature: float = 0.8
    do_sample: bool = True
    repetition_penalty: float = 1.005


@torch.inference_mode()
def generate_interactive(
    model,
    tokenizer,
    prompt,
    generation_config: Optional[GenerationConfig] = None,
    logits_processor: Optional[LogitsProcessorList] = None,
    stopping_criteria: Optional[StoppingCriteriaList] = None,
    prefix_allowed_tokens_fn: Optional[Callable[[int, torch.Tensor],
                                                List[int]]] = None,
    additional_eos_token_id: Optional[int] = None,
    **kwargs,
):
    inputs = tokenizer([prompt], padding=True, return_tensors='pt')
    input_length = len(inputs['input_ids'][0])
    for k, v in inputs.items():
        inputs[k] = v.cuda()
    input_ids = inputs['input_ids']
    _, input_ids_seq_length = input_ids.shape[0], input_ids.shape[-1]
    if generation_config is None:
        generation_config = model.generation_config
    generation_config = copy.deepcopy(generation_config)
    model_kwargs = generation_config.update(**kwargs)
    bos_token_id, eos_token_id = (  # noqa: F841  # pylint: disable=W0612
        generation_config.bos_token_id,
        generation_config.eos_token_id,
    )
    if isinstance(eos_token_id, int):
        eos_token_id = [eos_token_id]
    if additional_eos_token_id is not None:
        eos_token_id.append(additional_eos_token_id)
    has_default_max_length = kwargs.get(
        'max_length') is None and generation_config.max_length is not None
    if has_default_max_length and generation_config.max_new_tokens is None:
        warnings.warn(
            f"Using 'max_length''s default \
                ({repr(generation_config.max_length)}) \
                to control the generation length. "
            'This behaviour is deprecated and will be removed from the \
                config in v5 of Transformers -- we'
            ' recommend using `max_new_tokens` to control the maximum \
                length of the generation.',
            UserWarning,
        )
    elif generation_config.max_new_tokens is not None:
        generation_config.max_length = generation_config.max_new_tokens + \
            input_ids_seq_length
        if not has_default_max_length:
            logger.warn(  # pylint: disable=W4902
                f"Both 'max_new_tokens' (={generation_config.max_new_tokens}) "
                f"and 'max_length'(={generation_config.max_length}) seem to "
                "have been set. 'max_new_tokens' will take precedence. "
                'Please refer to the documentation for more information. '
                '(https://huggingface.co/docs/transformers/main/'
                'en/main_classes/text_generation)',
                UserWarning,
            )

    if input_ids_seq_length >= generation_config.max_length:
        input_ids_string = 'input_ids'
        logger.warning(
            f'Input length of {input_ids_string} is {input_ids_seq_length}, '
            f"but 'max_length' is set to {generation_config.max_length}. "
            'This can lead to unexpected behavior. You should consider'
            " increasing 'max_new_tokens'.")

    # 2. Set generation parameters if not already defined
    logits_processor = logits_processor if logits_processor is not None \
        else LogitsProcessorList()
    stopping_criteria = stopping_criteria if stopping_criteria is not None \
        else StoppingCriteriaList()

    logits_processor = model._get_logits_processor(
        generation_config=generation_config,
        input_ids_seq_length=input_ids_seq_length,
        encoder_input_ids=input_ids,
        prefix_allowed_tokens_fn=prefix_allowed_tokens_fn,
        logits_processor=logits_processor,
    )

    stopping_criteria = model._get_stopping_criteria(
        generation_config=generation_config,
        stopping_criteria=stopping_criteria)
    logits_warper = model._get_logits_warper(generation_config)

    unfinished_sequences = input_ids.new(input_ids.shape[0]).fill_(1)
    scores = None
    while True:
        model_inputs = model.prepare_inputs_for_generation(
            input_ids, **model_kwargs)
        # forward pass to get next token
        outputs = model(
            **model_inputs,
            return_dict=True,
            output_attentions=False,
            output_hidden_states=False,
        )

        next_token_logits = outputs.logits[:, -1, :]

        # pre-process distribution
        next_token_scores = logits_processor(input_ids, next_token_logits)
        next_token_scores = logits_warper(input_ids, next_token_scores)

        # sample
        probs = nn.functional.softmax(next_token_scores, dim=-1)
        if generation_config.do_sample:
            next_tokens = torch.multinomial(probs, num_samples=1).squeeze(1)
        else:
            next_tokens = torch.argmax(probs, dim=-1)

        # update generated ids, model inputs, and length for next step
        input_ids = torch.cat([input_ids, next_tokens[:, None]], dim=-1)
        model_kwargs = model._update_model_kwargs_for_generation(
            outputs, model_kwargs, is_encoder_decoder=False)
        unfinished_sequences = unfinished_sequences.mul(
            (min(next_tokens != i for i in eos_token_id)).long())

        output_token_ids = input_ids[0].cpu().tolist()
        output_token_ids = output_token_ids[input_length:]
        for each_eos_token_id in eos_token_id:
            if output_token_ids[-1] == each_eos_token_id:
                output_token_ids = output_token_ids[:-1]
        response = tokenizer.decode(output_token_ids)

        yield response
        # stop when each sentence is finished
        # or if we exceed the maximum length
        if unfinished_sequences.max() == 0 or stopping_criteria(
                input_ids, scores):
            break


def on_btn_click():
    del st.session_state.messages


@st.cache_resource
def load_model():
    model = (AutoModelForCausalLM.from_pretrained(
        model_name_or_path,
        trust_remote_code=True).to(torch.bfloat16).cuda())
    tokenizer = AutoTokenizer.from_pretrained(model_name_or_path,
                                              trust_remote_code=True)
    return model, tokenizer


def prepare_generation_config():
    with st.sidebar:
        max_length = st.slider('Max Length',
                               min_value=8,
                               max_value=32768,
                               value=32768)
        top_p = st.slider('Top P', 0.0, 1.0, 0.8, step=0.01)
        temperature = st.slider('Temperature', 0.0, 1.0, 0.7, step=0.01)
        st.button('Clear Chat History', on_click=on_btn_click)

    generation_config = GenerationConfig(max_length=max_length,
                                         top_p=top_p,
                                         temperature=temperature)

    return generation_config


user_prompt = '<|im_start|>user\n{user}<|im_end|>\n'
robot_prompt = '<|im_start|>assistant\n{robot}<|im_end|>\n'
cur_query_prompt = '<|im_start|>user\n{user}<|im_end|>\n\
    <|im_start|>assistant\n'


def combine_history(prompt):
    messages = st.session_state.messages
    meta_instruction = ('You are a helpful, honest, '
                        'and harmless AI assistant.')
    total_prompt = f'<s><|im_start|>system\n{meta_instruction}<|im_end|>\n'
    for message in messages:
        cur_content = message['content']
        if message['role'] == 'user':
            cur_prompt = user_prompt.format(user=cur_content)
        elif message['role'] == 'robot':
            cur_prompt = robot_prompt.format(robot=cur_content)
        else:
            raise RuntimeError
        total_prompt += cur_prompt
    total_prompt = total_prompt + cur_query_prompt.format(user=prompt)
    return total_prompt


def main():
    st.title('internlm2_5-7b-chat-assistant')

    # torch.cuda.empty_cache()
    print('load model begin.')
    model, tokenizer = load_model()
    print('load model end.')

    generation_config = prepare_generation_config()

    # Initialize chat history
    if 'messages' not in st.session_state:
        st.session_state.messages = []

    # Display chat messages from history on app rerun
    for message in st.session_state.messages:
        with st.chat_message(message['role'], avatar=message.get('avatar')):
            st.markdown(message['content'])

    # Accept user input
    if prompt := st.chat_input('What is up?'):
        # Display user message in chat message container

        with st.chat_message('user', avatar='user'):

            st.markdown(prompt)
        real_prompt = combine_history(prompt)
        # Add user message to chat history
        st.session_state.messages.append({
            'role': 'user',
            'content': prompt,
            'avatar': 'user'
        })

        with st.chat_message('robot', avatar='assistant'):

            message_placeholder = st.empty()
            for cur_response in generate_interactive(
                    model=model,
                    tokenizer=tokenizer,
                    prompt=real_prompt,
                    additional_eos_token_id=92542,
                    device='cuda:0',
                    **asdict(generation_config),
            ):
                # Display robot response in chat message container
                message_placeholder.markdown(cur_response + '▌')
            message_placeholder.markdown(cur_response)
        # Add robot response to chat history
        st.session_state.messages.append({
            'role': 'robot',
            'content': cur_response,  # pylint: disable=undefined-loop-variable
            'avatar': 'assistant',
        })
        torch.cuda.empty_cache()


if __name__ == '__main__':
    main()

实验效果

环境准备
在这里插入图片描述
Xtuner安装成功
在这里插入图片描述
数据集准备
把已有的个人认知训练数据集中的名字替换为自己的名字。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
模型准备
在这里插入图片描述

在这里插入图片描述
配置文件准备
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
训练报错
在这里插入图片描述
训练报错了
在这里插入图片描述
这个错误提示表明,你在运行命令时,程序无法从 torch.distributed.elastic.agent.server.api 中导入 log 函数,可能是因为 PyTorch 或 xtuner 版本之间的不兼容导致的。具体的错误信息是:

WARNING - WARNING: command error: 'cannot import name 'log' from 'torch.distributed.elastic.agent.server.api' (/root/.conda/envs/xtuner-env/lib/python3.10/site-packages/torch/distributed/elastic/agent/server/api.py)'!

可能的解决方法:

  1. 更新 PyTorch 版本:
    这个错误可能是由于 PyTorch 版本过老,无法找到 log 函数。尝试更新到最新稳定版本的 PyTorch:

    pip install --upgrade torch
    

    更新完成后,再次尝试运行命令。

  2. 检查 xtuner 与 PyTorch 的兼容性:
    确保你正在使用的 xtuner 版本与安装的 PyTorch 版本是兼容的。有时候,不同版本的库会有 breaking changes,导致 API 不兼容。可以查看 xtuner 和 PyTorch 的官方文档,确保它们的版本匹配。

  3. 修改代码(如果可以):
    如果你可以编辑 xtuner 的代码,可以检查导致问题的 import 语句,通常是类似下面的:

    from torch.distributed.elastic.agent.server.api import log
    

    如果 log 函数已经不再提供,可能需要替换为其他的日志记录方式,比如 Python 内置的 logging 模块,或者其他的日志工具。

  4. 使用正确的环境:
    如果环境配置有问题,可能会导致版本不匹配的错误。你可以尝试创建一个新的虚拟环境,安装与 xtuner 和 PyTorch 兼容的版本:

    conda create -n new_xtuner_env python=3.10
    conda activate new_xtuner_env
    pip install torch==<指定版本> xtuner
    
  5. 查阅 xtuner 文档:
    由于 xtuner 是一个特定的工具,查看其文档或 GitHub 上的问题讨论可能会提供更多的信息。有可能是 xtuner 需要更新或修复,或者在配置和使用时有特定的要求。

通过这些步骤,你应该能够解决或绕过这个错误。如果你有对代码进行修改的权限,可以尝试找到更合适的日志记录方式,或者直接解决兼容性问题。

核对操作文档,发现我多加了一句
在这里插入图片描述
在这里插入图片描述
重新安装包,希望不要从头再来一遍,
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
好像开始正常训练了
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
30%的算力,1.5个小时训练完毕
在这里插入图片描述
权重转换与合并
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
模型webUI对话
在这里插入图片描述在这里插入图片描述
SSH端口映射
在这里插入图片描述
端口映射后打不开网页
在这里插入图片描述采用以下ssh端口映射

配置SSH密钥进行SSH远程连接
将本地生成的SSH密钥复制粘贴到远程添加SSH公钥,建立SSH远程连接,优点:完成SSH Key创建以后,重启终端进行远程连接,就会跳过密码输入这一步了。
电脑power shell–》ssh-keygen -t rsa(# 生成RSA密钥对)—》cat ~/.ssh/id_rsa.pub(# 查询生成的公钥)
开发机–》SSH Key配置—》添加SSH Key公钥

在这里插入图片描述

运行python文件后,点击ports的网址
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

自我认知模型上传并部署到 HuggingFace/Modelscope/魔乐平台

HF的spaces创建项目

浏览器https://huggingface.co/spaces
–》Create new Space
–》在创建页面中,输入项目名为/internlm2_5-7b-chat-assistant,并选择 Streamlit应用进行创建,https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant
–》创建成功后会自动跳转到一个默认的HTML页面,编辑好app.py,
–》使用huggingface-cli login命令进行登录,登录过程中需要输入用户的Access Tokens,获取时,需要先验证email,完成验证后,点击create new token,创建一个类型为“Write”的token,并请复制好token后要存储在合适的地方
–》创建好项目后,回到我们的CodeSpace,接着clone项目。

在弹出的页面中,点击【create app.py】,直接编辑app.py,然后提交

#app.py就是5.1、修改xtuner_streamlit_demo.py
#修改模型路径model_name_or_path = "haidizym/internlm2_5-7b-chat-assistant-zymassistant"

git编辑更新项目

未能完成项目:本地 git bash
#1.准备环境
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
git lfs install
pip install huggingface_hub
git config --global credential.helper store
huggingface-cli login #命令进行登录,这时需要输入刚刚的token


#2.上传大模型文件到https://huggingface.co/haidizym/internlm2_5-7b-chat-assistant-zymassistant
huggingface-cli repo internlm2_5-7b-chat-assistant-zymassistant
cd /d
git clone https://huggingface.co/haidizym/internlm2_5-7b-chat-assistant-zymassistant
#把开发机上已经训练好的模型/root/finetune/work_dirs/assistTuner/merged下载到本地,存到刚才克隆下的来的文件夹internlm2_5-7b-chat-assistant-zymassistant里,/root/Tutorial/docs/L1/XTuner/requirements.txt也下载到本地,
cd internlm2_5-7b-chat-assistant-zymassistant
#添提推
git add .
git commit -m "add:internlm2_5-7b-chat-assistant-zymassistant"
git push


#3.部署Streamlit应用到https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant
#在https://huggingface.co/spaces新建好Streamlit应用https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant,并把xtuner_streamlit_demo.py内容粘贴到app.py中,修改模型路径model_name_or_path="/root/finetune/work_dirs/assistTuner/merged"为model_name_or_path = "haidizym/internlm2_5-7b-chat-assistant-zymassistant"
#使用镜像站点模型model_name_or_path = "https://hf-mirror.com/haidizym/internlm2_5-7b-chat-assistant-zymassistant"
#在https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant新建好requirements.txt,
#以上操作在https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant完成后,不再需要以下的操作
#cd d
#git clone https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant
#添提推
#git add .
#git commit -m "update: colearn page"
#git push
#需要输入HF的access token
成功项目:开发机

在开发机上使用huggingface-cli login连接上HF后(环境准备),创建上传大模型文件https://huggingface.co/haidizym/internlm2_5-7b-chat-assistant-zymassistant
(使用镜像export HF_ENDPOINT=https://hf-mirror.com),部署Streamlit应用到https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant

#1.准备环境
conda activate xtuner-env
apt install sudo
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
pip install huggingface_hub
git config --global credential.helper store
huggingface-cli login #命令进行登录,这时需要输入刚刚的token


#2.上传大模型文件到https://huggingface.co/haidizym/internlm2_5-7b-chat-assistant-zymassistant
huggingface-cli repo create internlm2_5-7b-chat-assistant-zymassistant
#加这句好像可以加速export HF_ENDPOINT=https://hf-mirror.com,又或者使用WATT给hugging face加速,不会弄WATT
export HF_ENDPOINT=https://hf-mirror.com
cd /root/finetune/work_dirs/assistTuner
#git clone https://huggingface.co/haidizym/internlm2_5-7b-chat-assistant-zymassistant
git clone https://hf-mirror.com/haidizym/internlm2_5-7b-chat-assistant-zymassistant
#我想把/root/finetune/work_dirs/assistTuner/merged这个文件夹里的全部文件上传到https://huggingface.co/haidizym/internlm2_5-7b-chat-assistant-zymassistant这里,这里克隆仓库以后,应该添一行什么代码,使得/root/finetune/work_dirs/assistTuner/merged这个文件夹里的全部文件在仓库里可以直接上传?
cd internlm2_5-7b-chat-assistant-zymassistant
cp -r /root/finetune/work_dirs/assistTuner/merged/* .
#添提推
git add .
git commit -m "add:internlm2_5-7b-chat-assistant-zymassistant"
git push


#3.部署Streamlit应用到https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant
#3.1 HF创建Streamlit应用https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant
#3.2 app.py编辑:在https://huggingface.co/spaces新建好Streamlit应用https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant,并把xtuner_streamlit_demo.py内容粘贴到app.py中,修改模型路径model_name_or_path="/root/finetune/work_dirs/assistTuner/merged"为model_name_or_path = "haidizym/internlm2_5-7b-chat-assistant-zymassistant"
#3.3 requirements.txt编辑:在https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant新建好requirements.txt,
#以上操作在https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant完成后,不再需要其他git操作

准备环境
在这里插入图片描述
连接HF,huggingface-cli login
在这里插入图片描述
貌似克隆模型仓库要花很久,这里留下两个时间节点
在这里插入图片描述
等了20分钟没反应,在克隆前加了这句export HF_ENDPOINT=https://hf-mirror.com,重新克隆,很快
git clone https://hf-mirror.com/haidizym/internlm2_5-7b-chat-assistant-zymassistant
在这里插入图片描述
在这里插入图片描述
添提推模型文件
在这里插入图片描述
14G模型文件约20分钟上传完
在这里插入图片描述

在这里插入图片描述
镜像上模型好了以后,一会后HF上也有了模型文件,https://huggingface.co/haidizym/internlm2_5-7b-chat-assistant-zymassistant
在这里插入图片描述

app.py文件编辑
在这里插入图片描述

创建环境配置requirements.txt文件
在这里插入图片描述
直接访问应用https://huggingface.co/spaces/haidizym/internlm2_5-7b-chat-assistant,
运行了约2个小时还是这个界面,估计没问题了,可能是HF提供的免费算力不够运行出来
在这里插入图片描述

附录:

环境配置requirements.txt

#cd /root/Tutorial/docs/L1/XTuner
#pip install -r requirements.txt
accelerate==0.27.0
addict==2.4.0
aiohttp==3.9.3
aiosignal==1.3.1
aliyun-python-sdk-core==2.14.0
aliyun-python-sdk-kms==2.16.2
altair==5.2.0
annotated-types==0.6.0
anyio==4.2.0
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
arxiv==2.1.0
asttokens==2.4.1
async-lru==2.0.4
async-timeout==4.0.3
attrs==23.2.0
Babel==2.14.0
beautifulsoup4==4.12.3
bitsandbytes==0.42.0
bleach==6.1.0
blinker==1.7.0
cachetools==5.3.2
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
comm==0.2.1
contourpy==1.2.0
crcmod==1.7
cryptography==42.0.2
cycler==0.12.1
datasets==2.17.0
debugpy==1.8.1
decorator==5.1.1
deepspeed==0.13.1
defusedxml==0.7.1
dill==0.3.8
distro==1.9.0
einops==0.8.0
einx==0.3.0
et-xmlfile==1.1.0
exceptiongroup==1.2.0
executing==2.0.1
fastapi==0.112.0
fastjsonschema==2.19.1
feedparser==6.0.10
filelock==3.14.0
fonttools==4.48.1
fqdn==1.5.1
frozendict==2.4.4
frozenlist==1.4.1
fsspec==2023.10.0
func-timeout==4.3.5
gast==0.5.4
gitdb==4.0.11
GitPython==3.1.41
google-search-results==2.4.2
griffe==0.40.1
h11==0.14.0
hjson==3.1.0
httpcore==1.0.3
httpx==0.26.0
huggingface-hub==0.24.2
idna==3.6
imageio==2.34.2
importlib-metadata==7.0.1
ipykernel==6.29.2
ipython==8.21.0
ipywidgets==8.1.2
isoduration==20.11.0
jedi==0.19.1
Jinja2==3.1.3
jmespath==0.10.0
json5==0.9.14
jsonpointer==2.4
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
kiwisolver==1.4.5
lagent==0.2.1
lazy_loader==0.4
llvmlite==0.43.0
lxml==5.1.0
markdown-it-py==3.0.0
MarkupSafe==2.1.5
matplotlib==3.8.2
matplotlib-inline==0.1.6
mdurl==0.1.2
mistune==3.0.2
mmengine==0.10.3
modelscope==1.12.0
mpi4py_mpich==3.1.5
mpmath==1.3.0
multidict==6.0.5
multiprocess==0.70.16
nbclient==0.9.0
nbconvert==7.16.0
nbformat==5.9.2
nest-asyncio==1.6.0
networkx==3.2.1
ninja==1.11.1.1
notebook==7.0.8
notebook_shim==0.2.3
numba==0.60.0
numpy==1.26.4
nvidia-cublas-cu12==12.1.3.1
nvidia-cuda-cupti-cu12==12.1.105
nvidia-cuda-nvrtc-cu12==12.1.105
nvidia-cuda-runtime-cu12==12.1.105
nvidia-cudnn-cu12==8.9.2.26
nvidia-cufft-cu12==11.0.2.54
nvidia-curand-cu12==10.3.2.106
nvidia-cusolver-cu12==11.4.5.107
nvidia-cusparse-cu12==12.1.0.106
nvidia-nccl-cu12==2.19.3
nvidia-nvjitlink-cu12==12.3.101
nvidia-nvtx-cu12==12.1.105
openai==1.12.0
opencv-python==4.9.0.80
openpyxl==3.1.2
oss2==2.17.0
overrides==7.7.0
packaging==24.1
pandas==2.2.0
pandocfilters==1.5.1
parso==0.8.3
peft==0.8.2
pexpect==4.9.0
phx-class-registry==4.1.0
pillow==10.2.0
platformdirs==4.2.0
prometheus-client==0.19.0
prompt-toolkit==3.0.43
protobuf==4.25.2
psutil==5.9.8
ptyprocess==0.7.0
pure-eval==0.2.2
py-cpuinfo==9.0.0
pyarrow==15.0.0
pyarrow-hotfix==0.6
pybase16384==0.3.7
pycparser==2.21
pycryptodome==3.20.0
pydantic==2.6.1
pydantic_core==2.16.2
pydeck==0.8.1b0
Pygments==2.17.2
pynvml==11.5.0
pyparsing==3.1.1
python-dateutil==2.8.2
python-json-logger==2.0.7
python-pptx==0.6.23
PyYAML==6.0.1
pyzmq==25.1.2
qtconsole==5.5.1
QtPy==2.4.1
referencing==0.33.0
regex==2023.12.25
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rich==13.4.2
rpds-py==0.17.1
safetensors==0.4.2
scikit-image==0.24.0
scipy==1.12.0
seaborn==0.13.2
Send2Trash==1.8.2
sentencepiece==0.1.99
sgmllib3k==1.0.0
simplejson==3.19.2
six==1.16.0
smmap==5.0.1
sniffio==1.3.0
sortedcontainers==2.4.0
soupsieve==2.5
stack-data==0.6.3
starlette==0.37.2
sympy==1.12
tenacity==8.2.3
termcolor==2.4.0
terminado==0.18.0
tifffile==2024.7.24
tiktoken==0.6.0
timeout-decorator==0.5.0
tinycss2==1.2.1
tokenizers==0.15.2
toml==0.10.2
tomli==2.0.1
toolz==0.12.1
torch==2.2.1
torchvision==0.17.1
tornado==6.4
tqdm==4.65.2
traitlets==5.14.1
transformers==4.39.0
transformers-stream-generator==0.0.4
triton==2.2.0
types-python-dateutil==2.8.19.20240106
typing_extensions==4.9.0
tzdata==2024.1
tzlocal==5.2
uri-template==1.3.0
urllib3==1.26.18
uvicorn==0.30.6
validators==0.22.0
watchdog==4.0.0
wcwidth==0.2.13
webcolors==1.13
webencodings==0.5.1
websocket-client==1.7.0
widgetsnbextension==4.0.10
XlsxWriter==3.1.9
xtuner==0.1.23
xxhash==3.4.1
yapf==0.40.2
yarl==1.9.4
zipp==3.17.0

纯电动汽车/飞机动力电池系统解析 如图16所示,先看均衡前,某个模块已达到放电终止电压(下限保护电压),其他模块还有一定的电量,这时不能继续放电;(1)慢充预充电回路,如图20所示:交流充电桩→车载充电机→高压+→预充继电器触点→预充电阻→电池模组→维修开关(内有熔断器)→电池模组→电流传感器→主负继电器触点→高压-→车载充电机→交流充电桩。辅助元器件如图8所示,包括动力电池系统内部的电子电器:主正继电器、预充继电器、预充电阻、主负继电器、高压熔断器、加热继电器、加热熔断器、电流传感器、高压插座、低压插座,还包括密封条、绝缘材料等。 阅读详情

相关推荐

模型算力需求估算

(Billion Parameters,简称B)和训练/推理的计算任务复杂度,结合硬件计算能力(例如每秒浮点运算次数,FLOPS)来估算。以下是详细的方法和公式说明,以及实际的计算示例。算力需求的估算依赖于参数量、模型架构及硬件性能,结合训练/推理场景的特定要求来计算。通过上述公式和示例,我们可以定量分析不同任务的算力需求,并合理配置硬件资源以优化运行效率。结论:推理任务相对较轻,单台H100可以在30秒内完成此任务。推理算力需求一般远低于训练,因为只需要执行前向传播。,可以将训练时间缩短到约。

形上得其象,形下合于数;阴阳自济,玄理自明。 8986

XTuner 低成本微调实战

本文介绍了xtuner的入门和上手教程,包括理论和实战两部分,本文重点在理论部分。在理论部分,详细介绍了微调框架xtuner以及微调的工作流程。

George_han的博客 2783

用LT1166+MOS管打造实验室级恒流源:闭环反馈与推挽驱动的深度调优

本文详细介绍了基于LT1166电流模式控制器与MOS管推挽架构的实验室级恒流源设计方法。通过闭环反馈调优和动态响应优化,实现带宽达100kHz、纹波低于0.1%的高性能恒流输出,适用于精密仪器校准和半导体测试等场景。重点解析了系统架构设计、MOS管选型策略以及频率响应测试等关键技术要点。

weixin_29290379的博客 218

【InternLM】XTuner微调LLM

LLM大模型的参数量以B(10亿)为单位,动辄迁百亿、千亿。如何在已经训练好的、性能优异的底座模型基础上,通过微调的方式,来实现对模型的性能优化、知识注入、领域迁移和风格对齐等调整,是一件非常有使用场景的工作。Xtuner是上海人工智能实验室推出的用于LLM微调的一站式工具,其:1)模型方面:支持InternLM、Qwen、Baichuan、ChatGLM等国内主流开源大模型,以及Llama、Mixtral和Gemma等国外优秀开源大模型;

guofei_fly的博客 2356

从零配置到收益优化:AppLovin MAX与AdMob聚合实战全流程

本文详细介绍了如何从零开始配置AppLovin MAX与AdMob聚合广告,包括SDK集成、双平台控制台设置、代码实现与调试,以及收益优化策略。通过智能竞价和瀑布流优化,开发者可以显著提升广告填充率和eCPM,构建高效的移动应用变现体系。

weixin_28829903的博客 493

Simlink与PX4硬件在环仿真(HIL)实现

Simlink与PX4硬件在环仿真(HIL)实现 介于涉及的知识比较多,这里只是简单的介绍一下,更多内容可以参考阿木实验室《基于matlab模型开发》课程。 硬件在环HIL介绍 simlink与PX4通信实现 硬件在环HIL介绍 为来贯彻万物都可以用数学公式表示,我们以simlink的角度来看我们的无人机,那么UAV可以分为以下的几个模块: 传感器模型 滤波器模块 控制器模...

Zipout的博客 6214

XTuner 微调个人小助手认知任务

XTuner是全链条开源开放的一个高效微调的框架,它适配多种生态,即就是多种微调算法:多种微调&偏好对齐算法,覆盖各类应用场景。适配多种开源生态,支持加载HuggingFace、ModelScope模型或者数据集。自动优化加速即就是开发者无需关注复杂的显存优化与计算加速细节,支持千亿参数+百万上下文训练。适配多种硬件,训练方案覆盖NVIDIA20系列以上所有显卡,最低只需8GB显存即可微调7B模型。二:XTuner个人小助手微调实践。

chasemydreamidea的博客 1366

爆改YOLOv8 | PSA注意力机制融合入YOLOv8

yolov8,PSA注意力,即插即用

weixin_43986124的博客 2501

大模型的开发应用(六):使用 Xtuner QLoRA 微调模型

Xtuner 是大模型微调的另一款重要框架,截止2025年4月,最常用的就两款,LLaMA Factory 与 Xtuner,本篇文章主要介绍 Xtuner 的基本使用。XTuner 是由上海人工智能实验室(InternLM 团队)开发的高效、灵活且功能全面的大语言模型(LLM)和多模态模型(VLM)微调工具库,旨在帮助开发者在有限的硬件资源下轻松完成大模型的微调任务。XTuner 是一个适合需要高效微调大模型的开发者的工具库,尤其适合希望在有限硬件条件下快速迭代模型的团队或个人。文档# 单轮对话},

weixin_44457930的博客 1529

Stm32L0 STM32CUBE中UART和使用LPUART1以及串口不进中断问题解决

/* 开启串口1中断 */ LL_USART_EnableIT_RXNE(LPUART1); /* 开启串口2中断 */ LL_USART_EnableIT_RXNE(USART2);

シ❤゛甜虾的个人博客 7690

WSL Ubuntu20 通过1Panel配置SSH服务的完整避坑指南

本文详细介绍了在WSL Ubuntu20环境下通过1Panel配置SSH服务的完整指南,包括环境准备、SSH服务安装与基础配置、1Panel中的SSH管理技巧以及连接测试与故障排查。特别针对WSL特性提供了避坑建议,如IP动态变化处理、SSH服务初始化配置等关键步骤,帮助用户高效搭建稳定的SSH服务环境。

weixin_29239279的博客 417

大模型微调学习之旅④ — XTuner 大模型单卡低成本微调实战

图解:Alpaca 格式,斯坦福大学开源数据集的格式,也是社区开源项目使用较多的一种格式MOSS 格式,复旦大学开源指令微调数据集的格式,包含多轮对话和工具调用Gunacao 格式,QLoRA 项目中所使用数据集的格式OpenAI 格式,GPT-3.5-Turbo Finetune 接口要求的数据集格式。

HOOK1的博客 4624

GPT Researcher 的win docker安装攻略

github网址是:https://github.com/assafelovic/gpt-researcher/blob/master/README-zh_CN.md。使用 Docker 运行 AI-Researcher 项目的。因为docker安装方法不够清晰,因此写一个使用方法。打开设置——docker engine ,增加代码。如有其他问题,可提供错误截图或日志进一步排查!

weixin_43818488的博客 1130

第四课-——XTuner 微调 LLM:1.8B、多模态、Agent

在本节中主要跑通了 XTuner 的一个完整流程,通过了解数据集和模型的使用方法、配置文件的制作和训练以及最后的转换及整合。那在后面假如我们也有想要微调出自己的一个模型,我们也可以尝试使用同样流程和方法进行进一步的实践!

shafsyjwqt的博客 2360

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

XTuner大模型微调

本文详细介绍了如何使用 XTuner 工具包进行大语言模型的微调训练。超级详细的保姆级教程。XTuner 是一个专注于高效微调的工具,支持多种微调方法(如 LoRA、QLoRA 等),能够在有限的计算资源下实现高性能的模型训练。文章内容包括 XTuner 的核心功能、典型应用场景、安装与使用方法,以及一个完整的训练流程示例。通过本文,读者可以快速掌握如何使用 XTuner 进行大模型的微调,并将其应用于特定领域或任务中。

weixin_41688410的博客 2512

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

书生·浦语大模型——XTuner大模型单卡微调实战

增量预训练微调:让基座模型学习到一些新知识,如某个垂类领域的常识指令跟随微调:让模型学会对话模板,根据人类指令进行对话。

Yogffee的博客 1658

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

XTuner 大模型单卡低成本微调实战

图解:增量预训练是一种微调模式,它通过逐步添加新的层或参数来扩展预训练模型。在增量预训练中,首先使用预训练模型在新任务的数据集上进行初步训练,然后逐层或逐步添加新的层或参数,并继续训练模型。这种微调模式适用于具有相似任务特征的不同数据集,可以有效地利用预训练模型的已有知识,提高模型的泛化能力。使用场景:让基座模型学习到一些新知识,如某个垂类领域的常识训练数据:文章、书籍、代码等

2301_77193447的博客 1123

大模型微调工具库XTuner

是一个高效、灵活且功能全面的大语言模型(LLM)和多模态模型(VLM)微调工具库,由上海人工智能实验室开发。它旨在帮助开发者在有限的资源下轻松微调大模型,支持多种主流模型和灵活的数据处理方式。兼容多种主流大语言模型(如InternLM、Llama2、ChatGLM等)和多模态模型(如LLaVA)。支持多种数据格式(如JSON、CSV)和微调算法(如QLoRA、LoRA、全量参数微调)。仅需8GB显存即可微调7B模型,支持多节点跨设备微调70B+模型。:对多模态模型进行微调,支持图像、文本等多模态数据。

xuweilin的博客 820

Xtuner 大模型训练入门小记:从配置到微调

大模型虽强,但让它适配特定场景总需额外“调教”——传统微调对算力和技术要求之高,常让人望而却步。​Xtuner 的诞生,正是为了解决这一痛点。它用极简的配置文件和自动化流程,将数据清洗、训练优化等复杂步骤“藏”在背后。无论你是想快速验证一个模型能力,还是为业务定制专属AI助手,只需几行命令,即可在有限资源下轻松启动训练。本文抛开冗长理论,专注“最小可行步骤”,助你30分钟内跑通第一个微调实验。Xtuner官方文档。

lucassu的博客 2664

xtuner github官方链接

速度基准🎉 新闻进行和发布!点击详情!system📖 简介XTuner 是一个高效、灵活、功能齐全的大型模型微调工具包。GPU 上的 LLM、VLM 预训练XTuner 能够在单个 8GB GPU70B 的模型的多节点微调Triton 内核等高性能算子,以提高训练吞吐量。ZeRO 优化技术。数据管道,可容纳输出模型可以与部署服务器工具包(大规模评估工具包()无缝集成。🔥 支持。

具身机器人和通用AI 964

XTuner 微调 LLM:1.8B、多模态、Agent——笔记

LLM的下游应用中,增量预训练 和 指令跟随 是经常会用到两种的微调模式。增量预训练微调使用场景:让基座模型学习到一些新知识,如某个垂类领域的常识。训练数据:文章、书籍、代码等。指令跟随微调使用场景:让模型学会对话模板,根据人类指令进行对话。训练数据:高质量的对话、问答数据。可以看到,增量预训练更多的只是将某种知识喂给模型,让模型学会这个知识,但怎么用,模型此时还是不知道的。然后,指令跟随微调就会训练模型,让模型学会对话模板,当想它问出问题的时候,模型就会运用自己的知识来解答。

YYYYbhjbhkv_的博客 1637

使用XTuner 微调大模型

使用XTuner 微调大模型

weixin_45963030的博客 1400

基础5-XTuner 微调个人小助手认知

该命令需要三个参数:CONFIG 表示微调的配置文件, PATH_TO_PTH_MODEL 表示微调的模型权重文件路径,即要转换的模型权重, SAVE_PATH_TO_HF_MODEL 表示转换后的 HuggingFace 格式文件的保存路径。微调完成后,我们可以再次运行 xtuner_streamlit_demo.py 脚本来观察微调后的对话效果,不过在运行之前,我们需要将脚本中的模型路径修改为微调后的模型的路径。在InternStudio开发机中的已经提供了微调模型,可以直接软链接即可。

greygrey_的博客 1088

【 书生·浦语大模型实战营】学习笔记(四):XTuner 微调 LLM:1.8B、多模态、Agent

本篇笔记内容主要为XTuner 微调 LLM。主要对微调概念、XTuner框架等进行详细介绍,并对多模态LLava1.8b进行模型训练微调、模型合并、对话测试实战,欢迎大家交流学习!

专注大数据与人工智能技术分享,欢迎私信加群互相学习! 2006

xtuner微调大模型

使用xtuner微调大模型

weixin_42237033的博客 1629

开源大模型微调工具 XTuner

支持几乎所有 GPU 上对 LLM 预训练或微调,可在 8GB GPU 上微调 7B , Llama3、Mixtral-8x7B、Qwen 等模型, LMDeploy、OpenCompass 集成。支持完整从微调,到部署,评测的一整套工具链。

在网搬砖的日常 1274
上一篇: (笔记+作业)书生大模型实战营春节卷王班---L1G4000 InternLM + LlamaIndex RAG 实践
下一篇: (笔记+作业)书生大模型实战营春节卷王班---L1G6000 OpenCompass 评测书生大模型实践
haidizym
博客等级 码龄7年 383粉丝 87原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址