当前位置: 首页 > article >正文

【个人开发】deepspeed+Llama-factory 本地数据多卡Lora微调【完整教程】

文章目录

  • 1.背景
  • 2.微调方式
    • 2.1 关键环境版本信息
    • 2.2 步骤
    • 2.2.1 下载llama-factory
    • 2.2.2 准备数据集
    • 2.2.3 微调模式
      • 2.2.3.1 zero-1微调
      • 2.2.3.2 zero-2微调
      • 2.2.3.3 zero-3微调
      • 2.2.3.4 单卡Lora微调
    • 2.2.4 实验
      • 2.2.4.1 实验1:多GPU微调-zero1
      • 2.2.4.2 实验2:多GPU微调-zero2
      • 2.2.4.3 实验3:多GPU微调-zero3
      • 2.2.4.4 实验4:Lora单卡微调
    • 2.2.5 合并大模型并启动
      • 2.2.5.1 方法一:Llama-factory合并,并使用ollama调用大模型
      • 2.2.5.2 方法二:Llama-factory合并,并使用vllm启动模型服务
  • 3 踩坑经验
    • 3.1 微调踩坑
      • 3.1.1 问题一:ValueError: Undefined dataset xxxx in dataset_info.json.
      • 3.1.2 问题二: ValueError: Target modules {'c_attn'} not found in the base model. Please check the target modules and try again.
      • 3.1.3 问题三: RuntimeError: The size of tensor a (1060864) must match the size of tensor b (315392) at non-singleton dimension 0。
      • 3.1.4 问题四: 训练效率问题

1.背景

上一篇文章写到,【个人开发】macbook m1 Lora微调qwen大模型

该微调方式,同样适用于GPU,只不过在train.py脚本中,针对device,调整为cuda即可。

如果数据量过大的话,单卡微调会存在瓶颈,因此考虑多GPU进行微调。

网上搜罗了一圈,多卡微调的常用方案:deepspeed+Llama-factory

本文主要记录该方式的微调情况,仅为个人学习记录

2.微调方式

2.1 关键环境版本信息

模块版本
python3.10
CUDA12.6
torch2.5.1
peft0.12.0
transformers4.46.2
accelerate1.1.1
trl0.9.6
deepspeed0.15.4

2.2 步骤

2.2.1 下载llama-factory

git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip install -e ".[torch,metrics]"

2.2.2 准备数据集

数据集采用网上流传的《甄嬛传》。

数据源地址:huanhuan.json

数据集结构如下。

// 文件命名:huanhuan.json
[{"instruction": "小姐,别的秀女都在求中选,唯有咱们小姐想被撂牌子,菩萨一定记得真真儿的——","input": "","output": "嘘——都说许愿说破是不灵的。"},...
]

其次,还得准备数据集信息【dataset_info.json】,因为是本地微调,所以微调时现访问dataset_info,再指定到具体的数据集中。

{"identity": {"file_name": "test_data.json"}
}

注意文本的数据集的格式必须为,json,不然会报错。

2.2.3 微调模式

2.2.3.1 zero-1微调

配置参考zero-3的配置,修改了一下zero_optimization.stage的参数。

// 文件命名:ds_config_zero1.json
{"fp16": {"enabled": "auto","loss_scale": 0,"loss_scale_window": 1000,"initial_scale_power": 16,"hysteresis": 2,"min_loss_scale": 1},"bf16": {"enabled": "auto"},"optimizer": {"type": "AdamW","params": {"lr": "auto","betas": "auto","eps": "auto","weight_decay": "auto"}},"scheduler": {"type": "WarmupLR","params": {"warmup_min_lr": "auto","warmup_max_lr": "auto","warmup_num_steps": "auto"}},"zero_optimization": {"stage": 1,"offload_optimizer": {"device": "none","pin_memory": true},"offload_param": {"device": "none","pin_memory": true},"overlap_comm": true,"contiguous_gradients": true,"sub_group_size": 1e9,"reduce_bucket_size": "auto","stage3_prefetch_bucket_size": "auto","stage3_param_persistence_threshold": "auto","stage3_max_live_parameters": 1e9,"stage3_max_reuse_distance": 1e9,"stage3_gather_16bit_weights_on_model_save": true},"gradient_accumulation_steps": 4,"gradient_clipping": "auto","steps_per_print": 100,"train_batch_size": "auto","train_micro_batch_size_per_gpu": "auto","wall_clock_breakdown": false
}

微调脚本

# run_train_bash_zero_1.sh
#!/bin/bash
# 记录开始时间
START=$(date +%s.%N)CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 accelerate launch  src/train.py \--deepspeed ds_config_zero1.json \--stage sft \--do_train True \--model_name_or_path /root/ai_project/fine-tuning-by-lora/models/model/qwen/Qwen2___5-7B-Instruct \--finetuning_type lora \--template qwen \--dataset_dir /root/ai_project/fine-tuning-by-lora/dataset/ \--dataset identity \--cutoff_len 1024 \--num_train_epochs 30 \--max_samples 100000 \--learning_rate 5e-05 \--lr_scheduler_type cosine \--warmup_steps 10 \--per_device_train_batch_size 4 \--gradient_accumulation_steps 4 \--max_grad_norm 1.0 \--logging_steps 10 \--save_steps 100 \--neftune_noise_alpha 0 \--lora_rank 8 \--lora_dropout 0.1 \--lora_alpha 32 \--lora_target q_proj,v_proj,k_proj,gate_proj,up_proj,o_proj,down_proj \--output_dir ./output/qwen_7b_ft/zero1/ \--bf16 True \--plot_loss True# 记录结束时间
END=$(date +%s.%N)# 计算运行时间
DUR=$(echo "$END - $START" | bc)# 输出运行时间
printf "Execution time: %.6f seconds\n" $DUR

2.2.3.2 zero-2微调

zero-2下述的配置中,调度器使用了AdamW,学习率在训练时候可以逐步下降。

// 文件命名:ds_config_zero2.json
{"fp16": {"enabled": "auto","loss_scale": 0,"loss_scale_window": 1000,"initial_scale_power": 16,"hysteresis": 2,"min_loss_scale": 1},"bf16": {"enabled": "auto"},"optimizer": {"type": "AdamW","params": {"lr": "auto","betas": "auto","eps": "auto","weight_decay": "auto"}},"zero_optimization": {"stage": 2,"offload_optimizer": {"device": "cpu","pin_memory": true}},"gradient_accumulation_steps": 4,"gradient_clipping": "auto","steps_per_print": 100,"train_batch_size": "auto","train_micro_batch_size_per_gpu": "auto","wall_clock_breakdown": false
}

2.2.3.3 zero-3微调

本次微调采用zero-3的方式,因此在LLaMa-Factory目录下,新增配置文件。
相关配置可参考Llama-Factory提供的文件样例[./LLaMA-Factory/examples/deepspeed/]

在这里插入图片描述

// 文件命名:ds_config_zero3.json
{"fp16": {"enabled": "auto","loss_scale": 0,"loss_scale_window": 1000,"initial_scale_power": 16,"hysteresis": 2,"min_loss_scale": 1},"bf16": {"enabled": "auto"},"optimizer": {"type": "AdamW","params": {"lr": "auto","betas": "auto","eps": "auto","weight_decay": "auto"}},"scheduler": {"type": "WarmupLR","params": {"warmup_min_lr": "auto","warmup_max_lr": "auto","warmup_num_steps": "auto"}},"zero_optimization": {"stage": 3,"offload_optimizer": {"device": "none","pin_memory": true},"offload_param": {"device": "none","pin_memory": true},"overlap_comm": true,"contiguous_gradients": true,"sub_group_size": 1e9,"reduce_bucket_size": "auto","stage3_prefetch_bucket_size": "auto","stage3_param_persistence_threshold": "auto","stage3_max_live_parameters": 1e9,"stage3_max_reuse_distance": 1e9,"stage3_gather_16bit_weights_on_model_save": true},"gradient_accumulation_steps": "auto","gradient_clipping": "auto","steps_per_print": 100,"train_batch_size": "auto","train_micro_batch_size_per_gpu": "auto","wall_clock_breakdown": false
}

微调脚本

# run_train_bash.sh 
#!/bin/bash
# 记录开始时间
START=$(date +%s.%N)
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 accelerate launch  src/train.py \--deepspeed ds_config_zero3.json \--stage sft \--do_train True \--model_name_or_path /root/ai_project/fine-tuning-by-lora/models/model/qwen/Qwen2___5-7B-Instruct \--finetuning_type lora \--template qwen \--dataset_dir /root/ai_project/fine-tuning-by-lora/dataset/ \--dataset identity \--cutoff_len 1024 \--num_train_epochs 5 \--max_samples 100000 \--per_device_train_batch_size 4 \--gradient_accumulation_steps 4 \--lr_scheduler_type cosine \--learning_rate 5e-04 \--lr_scheduler_type cosine \--max_grad_norm 1.0 \--logging_steps 5 \--save_steps 100 \--neftune_noise_alpha 0 \--lora_rank 8 \--lora_dropout 0.1 \--lora_alpha 32 \--lora_target q_proj,v_proj,k_proj,gate_proj,up_proj,o_proj,down_proj \--output_dir ./output/qwen_7b_ds/train_2025_02_13 \--bf16 True \--plot_loss True# 记录结束时间
END=$(date +%s.%N)
# 计算运行时间
DUR=$(echo "$END - $START" | bc)
# 输出运行时间
printf "Execution time: %.6f seconds\n" $DUR

说明一下上述一些关键参数:

参数版本
–deepspeed指定deepspeed加速微调方式
–model_name_or_path微调模型路径
–finetuning_type微调方式,这里用lora微调
–template训练和推理时构造 prompt 的模板,不同大语言模型的模板不一样,这里用的是qwen
–dataset_dir本地的数据集路径
–dataset指定dataset_info.json中哪个数据集
–lora_target应用 LoRA 方法的模块名称。
–output_dir模型输出路径。

模型微调参数可以参考:Llama-Factory参数介绍

其他参数,其实就是常规使用peft进行lora微调的常见参数,以及常见的微调参数,可以对照如下。

lora_config = LoraConfig(task_type=TaskType.CAUSAL_LM,target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],inference_mode=False,r=8,lora_alpha=32,lora_dropout=0.1
)

2.2.3.4 单卡Lora微调

具体使用可以参考上一篇文章:【个人开发】macbook m1 Lora微调qwen大模型
也可以参考github项目:fine-tuning-by-Lora

微调代码如下。


torch_dtype = torch.halflora_config = LoraConfig(task_type=TaskType.CAUSAL_LM,target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],inference_mode=False,r=8,lora_alpha=32,lora_dropout=0.1
)def train():# 加载模型model_dir = snapshot_download(model_id=model_id, cache_dir=f"{models_dir}/model", revision='master')if model_path != model_dir:raise Exception(f"model_path:{model_path} != model_dir:{model_dir}")model = AutoModelForCausalLM.from_pretrained(model_path,device_map=device, torch_dtype=torch_dtype)model.enable_input_require_grads()  # 开启梯度检查点时,要执行该方法# 加载数据df = pd.read_json(dataset_file)ds = Dataset.from_pandas(df)print(ds[:3])# 处理数据tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=False, trust_remote_code=True)tokenizer.pad_token = tokenizer.eos_tokendef process_func(item):MAX_LENGTH = 384  # Llama分词器会将一个中文字切分为多个token,因此需要放开一些最大长度,保证数据的完整性input_ids, attention_mask, labels = [], [], []instruction = tokenizer(f"<|start_header_id|>user<|end_header_id|>\n\n{item['instruction'] + item['input']}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",add_special_tokens=False)  # add_special_tokens 不在开头加 special_tokensresponse = tokenizer(f"{item['output']}<|eot_id|>", add_special_tokens=False)input_ids = instruction["input_ids"] + response["input_ids"] + [tokenizer.pad_token_id]attention_mask = instruction["attention_mask"] + response["attention_mask"] + [1]  # 因为eos token咱们也是要关注的所以 补充为1labels = [-100] * len(instruction["input_ids"]) + response["input_ids"] + [tokenizer.pad_token_id]if len(input_ids) > MAX_LENGTH:  # 做一个截断input_ids = input_ids[:MAX_LENGTH]attention_mask = attention_mask[:MAX_LENGTH]labels = labels[:MAX_LENGTH]return {"input_ids": input_ids,"attention_mask": attention_mask,"labels": labels}tokenized_id = ds.map(process_func, remove_columns=ds.column_names)tokenizer.decode(list(filter(lambda x: x != -100, tokenized_id[1]["labels"])))# 加载lora权重model = get_peft_model(model, lora_config)# 训练模型training_args = TrainingArguments(output_dir=checkpoint_dir,per_device_train_batch_size=4,gradient_accumulation_steps=4,logging_steps=5,num_train_epochs=30,save_steps=100,learning_rate=5e-04,save_on_each_node=True,gradient_checkpointing=True,)trainer = Trainer(model=model,args=training_args,train_dataset=tokenized_id,data_collator=DataCollatorForSeq2Seq(tokenizer=tokenizer, padding=True),)trainer.train()# 保存模型trainer.model.save_pretrained(lora_dir)tokenizer.save_pretrained(lora_dir)

2.2.4 实验

本次测试使用多GPU微调,测试多GPU微调跟单GPU微调的性能对比。

使用2,030条数据,epoch = 30 ,batch size = 4,Gradient Accumulation steps = 4

实验组实验类别步数耗时最终loss
实验1zero1微调48009:000.0101
实验2zero2微调48009:590.4757
实验3zero3微调4801:49:110.0746
实验4单卡lora微调38101:07:570.0009

初步结论:
1.基于实验1,实验3的对照,使用zero3微调,耗时明显提升的原因还是资源使用不合理【没充分使用GPU】。
2.基于实验1,实验3跟实验2的对照,实验2的损失下降比较慢的一个原因是因为使用的学习率调度器的问题。

2.2.4.1 实验1:多GPU微调-zero1

日志如下

[INFO|trainer.py:2369] 2025-02-18 09:44:50,875 >> ***** Running training *****
[INFO|trainer.py:2370] 2025-02-18 09:44:50,875 >>   Num examples = 2,030
[INFO|trainer.py:2371] 2025-02-18 09:44:50,875 >>   Num Epochs = 30
[INFO|trainer.py:2372] 2025-02-18 09:44:50,875 >>   Instantaneous batch size per device = 4
[INFO|trainer.py:2375] 2025-02-18 09:44:50,875 >>   Total train batch size (w. parallel, distributed & accumulation) = 128
[INFO|trainer.py:2376] 2025-02-18 09:44:50,875 >>   Gradient Accumulation steps = 4
[INFO|trainer.py:2377] 2025-02-18 09:44:50,875 >>   Total optimization steps = 480
[INFO|trainer.py:2378] 2025-02-18 09:44:50,878 >>   Number of trainable parameters = 20,185,088
.....
***** train metrics *****epoch                    =        30.0total_flos               = 234733999GFtrain_loss               =      1.0322train_runtime            =  0:09:00.75train_samples_per_second =     112.619train_steps_per_second   =       0.888
Figure saved at: ./output/qwen_7b_ft/zero1/training_loss.png

GPU使用情况。
在这里插入图片描述
loss下降情况如下:
在这里插入图片描述

2.2.4.2 实验2:多GPU微调-zero2

使用2,030条数据,8卡微调,微调参数如下,总共480步,耗时09:59。

[INFO|trainer.py:2369] 2025-02-17 12:53:54,461 >> ***** Running training *****
[INFO|trainer.py:2370] 2025-02-17 12:53:54,461 >>   Num examples = 2,030
[INFO|trainer.py:2371] 2025-02-17 12:53:54,461 >>   Num Epochs = 30
[INFO|trainer.py:2372] 2025-02-17 12:53:54,461 >>   Instantaneous batch size per device = 4
[INFO|trainer.py:2375] 2025-02-17 12:53:54,461 >>   Total train batch size (w. parallel, distributed & accumulation) = 128
[INFO|trainer.py:2376] 2025-02-17 12:53:54,461 >>   Gradient Accumulation steps = 4
[INFO|trainer.py:2377] 2025-02-17 12:53:54,461 >>   Total optimization steps = 480
[INFO|trainer.py:2378] 2025-02-17 12:53:54,465 >>   Number of trainable parameters = 20,185,088***** train metrics *****epoch                    =        30.0total_flos               = 234733999GFtrain_loss               =      1.6736train_runtime            =  0:09:59.38train_samples_per_second =     101.605train_steps_per_second   =       0.801
Figure saved at: ./output/qwen_7b_ft/zero2/training_loss.png

GPU使用情况如下:
在这里插入图片描述
损失下降情况:
在这里插入图片描述

2.2.4.3 实验3:多GPU微调-zero3

使用2,030条数据,8卡微调,微调参数如下,总共480步,耗时1:49:11。

[INFO|trainer.py:2369] 2025-02-17 13:07:48,438 >> ***** Running training *****
[INFO|trainer.py:2370] 2025-02-17 13:07:48,438 >>   Num examples = 2,030
[INFO|trainer.py:2371] 2025-02-17 13:07:48,438 >>   Num Epochs = 30
[INFO|trainer.py:2372] 2025-02-17 13:07:48,438 >>   Instantaneous batch size per device = 4
[INFO|trainer.py:2375] 2025-02-17 13:07:48,438 >>   Total train batch size (w. parallel, distributed & accumulation) = 128
[INFO|trainer.py:2376] 2025-02-17 13:07:48,438 >>   Gradient Accumulation steps = 4
[INFO|trainer.py:2377] 2025-02-17 13:07:48,438 >>   Total optimization steps = 480
[INFO|trainer.py:2378] 2025-02-17 13:07:48,442 >>   Number of trainable parameters = 20,185,088...***** train metrics *****epoch                    =       30.0total_flos               =   257671GFtrain_loss               =     0.3719train_runtime            = 1:49:11.88train_samples_per_second =      9.295train_steps_per_second   =      0.073
Figure saved at: ./output/qwen_7b_ft/zero3/training_loss.png
[WARNING|2025-02-17 14:57:11] llamafactory.extras.ploting:162 >> No metric eval_loss to plot.
[WARNING|2025-02-17 14:57:11] llamafactory.extras.ploting:162 >> No metric eval_accuracy to plot.
[INFO|modelcard.py:449] 2025-02-17 14:57:11,629 >> Dropping the following result as it does not have all the necessary fields:

GPU使用情况如下:

在这里插入图片描述
损失下降情况:
在这里插入图片描述

2.2.4.4 实验4:Lora单卡微调

单卡微调,总共需要3810步。
在这里插入图片描述

2.2.5 合并大模型并启动

2.2.5.1 方法一:Llama-factory合并,并使用ollama调用大模型

模型合并

利用Llama-factory的框架,配置llama3_lora_sft_qwen.yaml 文件,进行模型合并。

# llama3_lora_sft_qwen.yaml
### model
model_name_or_path: /root/ai_project/fine-tuning-by-lora/models/model/qwen/Qwen2___5-7B-Instruct
adapter_name_or_path: /root/ai_project/LLaMA-Factory/output/qwen_7b_ds/zero2/
template: qwen
trust_remote_code: true### export
export_dir: output/llama3_lora_sft_qwen
export_size: 5
export_device: gpu
export_legacy_format: false
llamafactory-cli export llama3_lora_sft_qwen.yaml

模型打包

合并完成后,会有直接生成Modelfile文件,可以直接打包到ollama中。

在这里插入图片描述

# ollama modelfile auto-generated by llamafactory
FROM .TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ range .Messages }}{{ if eq .Role "user" }}<|im_start|>user
{{ .Content }}<|im_end|>
<|im_start|>assistant
{{ else if eq .Role "assistant" }}{{ .Content }}<|im_end|>
{{ end }}{{ end }}"""SYSTEM """You are a helpful assistant."""PARAMETER stop "<|im_end|>"
PARAMETER num_ctx 4096

模型启动
ollama启动

ollama create llama3_lora_sft_qwen -f Modelfile

参考文章:大模型开发和微调工具Llama-Factory–>LoRA合并

2.2.5.2 方法二:Llama-factory合并,并使用vllm启动模型服务

模型的合并同方法一,之后使用vllm命令启动。

vllm命令启动模型服务

# 内置了vllm的qwen的template。
CUDA_VISIBLE_DEVICES=1,2,3,4 python3 -m vllm.entrypoints.openai.api_server \--model "/root/ai_project/LLaMA-Factory/output/merge/" \--port 6006 \--tensor-parallel-size 4 \--served-model-name Qwen2.5-7B-sft \--max-model-len 8192 \--dtype half \--host 0.0.0.0

模型服务接口调用

import requestsdef chat_with_vllm(prompt, port=6006):url = f"http://localhost:{port}/v1/chat/completions"headers = {"Content-Type": "application/json"}data = {"model": "Qwen2.5-7B-sft",  # 模型名称或路径"messages": [{"role": "user", "content": prompt}],"max_tokens": 512,"temperature": 0.7}response = requests.post(url, headers=headers, json=data)if response.status_code == 200:result = response.json()generated_text = result["choices"][0]["message"]["content"]print(generated_text.strip())else:print("Error:", response.status_code, response.text)# 示例调用
chat_with_vllm("你是谁?", port=6006)

服务日志:
在这里插入图片描述
说明:日志中可以看到template。

调用结果:
在这里插入图片描述

3 踩坑经验

3.1 微调踩坑

3.1.1 问题一:ValueError: Undefined dataset xxxx in dataset_info.json.

如果你脚本的启动参数,–dataset identity。而dataset_info.json中的数据信息,没有“identity”这个key,则会出现这个报错,只要确保你dataset_info.json中存在该key即可。

3.1.2 问题二: ValueError: Target modules {‘c_attn’} not found in the base model. Please check the target modules and try again.

如果你脚本的启动参数,–lora_target参数设为常见的c_attn参数,则会报此错。处理方式还是调整参数,使用Lora微调时的常见参数,q_proj,v_proj,k_proj,gate_proj,up_proj,o_proj,down_proj。注意格式,如果格式不对,还是会报错。

3.1.3 问题三: RuntimeError: The size of tensor a (1060864) must match the size of tensor b (315392) at non-singleton dimension 0。

这种tensor的问题,很可能是模型冲突的问题,比如调到一半,然后重新提调,指到相同的路径。重新指定output路径即可。

3.1.4 问题四: 训练效率问题

在GPU充分的情况下,使用zero_2的训练效率,很明显比zero_3的训练效率更快!

【后续,持续更新。。。】

相关文章:

【个人开发】deepspeed+Llama-factory 本地数据多卡Lora微调【完整教程】

文章目录 1.背景2.微调方式2.1 关键环境版本信息2.2 步骤2.2.1 下载llama-factory2.2.2 准备数据集2.2.3 微调模式2.2.3.1 zero-1微调2.2.3.2 zero-2微调2.2.3.3 zero-3微调2.2.3.4 单卡Lora微调 2.2.4 实验2.2.4.1 实验1&#xff1a;多GPU微调-zero12.2.4.2 实验2&#xff1a;…...

【SpringBoot】数据访问技术spring Data、 JDBC、MyBatis、JSR-303校验

Spring Boot 数据访问技术及特性 目录标题 Spring Boot 数据访问技术及特性摘要1. 引言2. Spring Data架构与原理2.1 Spring Data概述2.2 Spring Data核心组件2.3 Spring Boot与Spring Data的集成机制 3. Spring Boot与JDBC的整合3.1 JDBC整合流程3.2 数据源自动配置3.3 JdbcTe…...

手机放兜里,支付宝“碰一下”被盗刷?

大家好&#xff0c;我是小悟。 近期&#xff0c;网络上关于“支付宝‘碰一下’支付易被盗刷”的传言甚嚣尘上&#xff0c;不少用户对此心生疑虑。 首先&#xff0c;要明确一点&#xff1a;“碰一下”支付并不会像某些传言中所描述的那样容易被隔空盗刷。这一观点已经得到了支付…...

Java Web应用中获取客户端的真实IP地址

Java Web应用中获取客户端的真实IP地址,尤其在存在代理服务器的情况下。 代码示例: public static String getClientIP(HttpServletRequest request) {String ip = parseCommaSeparatedIPs(request.getHeader("X-Forwarded-For"));if (isInvalid(ip)) {ip = pars…...

vue框架后遗症∶被遗忘的dom操作

用多了vue、react等前端框架&#xff0c;不得不说用数据驱动视图来开发真的很香&#xff0c;但是也免不了会有不用这些框架的项目&#xff0c;dom操作还是很有必要的&#xff0c;一开始学习网页设计的时候就教过&#xff0c;后面一直开发项目基本上用框架。虽然有些想不起来了&…...

基于深度学习+NLP豆瓣电影数据爬虫可视化推荐系统

博主介绍&#xff1a;资深开发工程师&#xff0c;从事互联网行业多年&#xff0c;熟悉各种主流语言&#xff0c;精通java、python、php、爬虫、web开发&#xff0c;已经做了多年的设计程序开发&#xff0c;开发过上千套设计程序&#xff0c;没有什么华丽的语言&#xff0c;只有…...

8. 示例:对32位数据总线实现位宽和值域覆盖

文章目录 前言示例一&#xff1a;示例二&#xff1a;示例三&#xff1a;仿真与覆盖率分析覆盖点详细说明覆盖率提升技巧常见错误排查 示例四&#xff1a;仿真步骤 前言 针对32位数据总线实现位宽和值域的覆盖&#xff0c;并且能够用xrun运行&#xff0c;查看日志和波形。cover…...

深度剖析Seata源码:解锁分布式事务处理的核心逻辑

文章目录 写在文章开头如何使用源码(配置转掉)基于AT模式详解Seata全链路流程Seata服务端启动本地服务如何基于GlobalTransaction注解开启事务客户端如何开启分布式事务RM和TC如何协调处理分支事务RM生成回滚日志事务全局提交与回滚小结参考写在文章开头 在当今分布式系统日益…...

快速列出MS Word中所有可用字体

Word中有很多字体&#xff0c;虽然在字体下拉列表中提供了字体的样例&#xff0c;但是并不全面&#xff0c;例如使用Batang字体的话&#xff0c;数字会显示成什么效果&#xff0c;就无法直观的看到。 打开Word应用程序&#xff0c;新建一个空白文档&#xff0c;按AltF11打开VBE…...

SpringDataJPA使用deleteAllInBatch方法逻辑删除失效

概述 在使用Spring Boot JPA时&#xff0c;执行批量删除操作时&#xff0c;遇到逻辑删除失效的问题。具体而言&#xff0c;当使用deleteAllInBatch方法时&#xff0c;数据会被物理删除&#xff0c;而不是进行逻辑删除&#xff1b;但是当使用deleteAll时&#xff0c;逻辑删除操…...

【密码学实战】Java 实现 SM2 国密算法(签名带id、验签及 C1C3C2 加密解密)

前言 SM2是中国国家密码管理局发布的椭圆曲线公钥密码算法标准&#xff08;GB/T 32918&#xff09;&#xff0c;属于国密算法体系。与RSA和ECDSA相比&#xff0c;SM2在相同安全强度下密钥更短、计算效率更高。本文将介绍如何在Java中实现SM2的密钥生成、数字签名、验签、加密及…...

flex布局自定义一行几栏,靠左对齐===grid布局

模板 <div class"content"><div class"item">1222</div><div class"item">1222</div><div class"item">1222</div><div class"item">1222</div><div class"…...

Harmony os next~鸿蒙应用开发入门教程

鸿蒙应用开发入门教程 基础准备与环境搭建 1. 了解鸿蒙系统 1.1 核心理念学习 HarmonyOS&#xff08;鸿蒙系统&#xff09;是华为推出的全场景分布式操作系统&#xff0c;其核心特点如下&#xff1a; 分布式能力 设备协同&#xff1a;手机、平板、智能手表、IoT设备等可无…...

使用 Ansys Discovery 高效创建角焊缝

概括 Ansys Discovery 2024R1 中的焊缝功能是一项重大改进&#xff0c;旨在简化和精简工程模拟中焊缝的分配过程。此功能集成了间歇焊缝等高级工具和功能&#xff0c;以更直观、更高效的方式促进焊缝的准备和分配。 该功能为工程师提供了无缝的工作流程&#xff0c;以准备和分…...

Rk3568驱动开发_新字符设备驱动原理_7

1.申请设备号&#xff1a; 之前用的是register_chrdev(LED_MAJOR, LED_NAME, &led_fops);手动申请很不方便 使用alloc_chrdev_region函数申请设备号&#xff0c;手动申请的话要先查询是否有空余的设备号&#xff0c;很不方便&#xff0c;用此函数内核会自动将将空余设备号…...

ESP32-S3 42引脚 语音控制模块、设备运转展示 GOOUUU TECH 果云科技S3-N16R8 控制舵机 LED开关 直流电机

最近还是想玩了下esp32&#xff0c;基于原来的开发板&#xff0c;看见佬做了一个语音识别的项目&#xff0c;通过这个语音识别可以控制LED开关和直流电机这些&#xff0c;详情可见视频&#xff08;推荐&#xff09;具体硬件就在下方。 信泰微】ESP32-S3 42引脚 语音控制模块、…...

2025年光电科学与智能传感国际学术会议(ICOIS 2025)

重要信息 官网&#xff1a;www.ic-icois.org 时间&#xff1a;2025年3月14-16日 地点&#xff1a;中国-长春 简介 2025年光电科学与智能传感国际学术会议&#xff08;ICOIS 2025&#xff09;将于2025年3月14-16日在中国-长春隆重召开。会议将围绕“光学光电”、“智能传感”…...

高性能PHP框架webman爬虫引擎插件,如何爬取数据

文章精选推荐 1 JetBrains Ai assistant 编程工具让你的工作效率翻倍 2 Extra Icons&#xff1a;JetBrains IDE的图标增强神器 3 IDEA插件推荐-SequenceDiagram&#xff0c;自动生成时序图 4 BashSupport Pro 这个ides插件主要是用来干嘛的 &#xff1f; 5 IDEA必装的插件&…...

三大主流负载均衡器之对比(Comparison of the Three Mainstream Load balancers)

【 Linux 】三大主流软件负载均衡器对比(LVS、Nginx、HAproxy) 三大主流软件负载均衡器对比(LVS、Nginx、HAproxy) &#xff08;资料来自网络&#xff0c;做了部分的补充说明&#xff09; LVS: 1. 抗负载能力强&#xff0c;性能高&#xff0c;能达到F5的60%&#xff0c;对…...

深入探索Python机器学习算法:监督学习(线性回归,逻辑回归,决策树与随机森林,支持向量机,K近邻算法)

文章目录 深入探索Python机器学习算法&#xff1a;监督学习一、线性回归二、逻辑回归三、决策树与随机森林四、支持向量机五、K近邻算法 深入探索Python机器学习算法&#xff1a;监督学习 在机器学习领域&#xff0c;Python凭借其丰富的库和简洁的语法成为了众多数据科学家和机…...

Qt跨线程信号槽调用:为什么信号不能像普通函数那样调用

1. 信号与槽机制的基本原理 在 Qt 中&#xff0c;信号与槽机制是一种事件驱动的通信方式&#xff0c;用于对象之间的解耦交互。其关键特点如下&#xff1a; 信号不能直接调用 信号只是一个声明&#xff0c;并没有实际的函数实现。它们通过 emit 关键字在对象内部被触发&…...

Ubuntu+deepseek+Dify本地部署

1.deepseek本地部署 在Ollama官网下载 需要魔法下载 curl -fsSL https://ollama.com/install.sh | sh 在官网找到需要下载的deepseek模型版本 复制命令到终端 ollama run deepseek-r1:7b 停止ollama服务 sudo systemctl stop ollama # sudo systemctl stop ollama.servi…...

【LLM】DeepSeek开源技术汇总

note 一、FlashMLA&#xff1a;MLA解码内核 二、DeepEP&#xff1a;针对MoE和EP的通信库 三、DeepGEMM&#xff1a;FP8 通用矩阵乘法&#xff08;GEMM&#xff09;库 四、DualPipe、EPLB&#xff1a;双向管道并行算法 五、3FS&#xff1a;一种高性能分布式文件系统 文章目录 n…...

PostgreSQL10 逻辑复制实战:构建高可用数据同步架构!

PostgreSQL10 逻辑复制实战&#xff1a;打造高可用数据同步架构&#xff01; 概述 PostgreSQL 10 引入了逻辑复制&#xff08;Logical Replication&#xff09;&#xff0c;为数据库高可用和数据同步提供了更灵活的选择。PostgreSQL 复制机制主要分为物理复制和逻辑复制两种&…...

springboot之HTML与图片生成

背景 后台需要根据字段动态生成HTML&#xff0c;并生成图片&#xff0c;发送邮件到给定邮箱 依赖 <!-- freemarker模板引擎--> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifa…...

455. 分发饼干(LeetCode)

题目来源&#xff1a; 455. 分发饼干 - 力扣&#xff08;LeetCode&#xff09; 题目内容&#xff1a; 假设你是一位很棒的家长&#xff0c;想要给你的孩子们一些小饼干。但是&#xff0c;每个孩子最多只能给一块饼干。 对每个孩子 i&#xff0c;都有一个胃口值 g[i]&#xf…...

go设计模式

刘&#xff1a;https://www.bilibili.com/video/BV1kG411g7h4 https://www.bilibili.com/video/BV1jyreYKE8z 1. 单例模式 2. 简单工厂模式 代码逻辑&#xff1a; 原始&#xff1a;业务逻辑层 —> 基础类模块工厂&#xff1a;业务逻辑层 —> 工厂模块 —> 基础类模块…...

基于STM32的智能家居能源管理系统

1. 引言 传统家庭能源管理存在能耗监控粗放、设备联动不足等问题&#xff0c;难以适应绿色低碳发展需求。本文设计了一款基于STM32的智能家居能源管理系统&#xff0c;通过多源能耗监测、负荷预测与优化调度技术&#xff0c;实现家庭能源的精细化管理与智能优化&#xff0c;提…...

win11编译pytorchaudio cuda128版本流程

1. 前置条件 本篇续接自 win11编译pytorch cuda128版本流程&#xff0c;阅读前请先参考上一篇配置环境。 访问https://kkgithub.com/pytorch/audio/archive/refs/tags/v2.6.0.tar.gz下载源码&#xff0c;下载后解压&#xff1b; 2. 编译 在visual studio 2022安装目录下查找…...

Rust学习总结之-match

Rust 有一个叫做 match 的极为强大的控制流运算符&#xff0c;它允许我们将一个值与一系列的模式相比较&#xff0c;并根据相匹配的模式执行相应代码。模式可由字面量、变量、通配符和许多其他内容构成。 一&#xff1a;match定义 可以把 match 表达式想象成某种硬币分类器&a…...