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

【速写】SFT案例实操(以Qwen2.5-instruct-0.5B)

参考资料:

  • https://openbayes.com/console/bbruceyuan/containers/OPg9Oo99ET6
  • https://www.bilibili.com/video/BV1NM1tY3Eu5

LoRA微调案例

首先还是要安装:

!pip install -q accelerate peft bitsandbytes transformers sentencepiece
!pip install trl==0.12.0

配置环境变量:

import os
os.environ["HF_HOME"] = "/openbayes/home/huggingface"

读取数据集(这是一个将文言文翻译成现代文的数据集)

from transformers import AutoTokenizer
from datasets import load_dataset
# 加载一个 tokenizer 来使用它的聊天模板
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct")
def format_prompt(example):chat = [{"role": "system", "content": "你是一个非常棒的人工智能助手,是UP主 “用代码打点酱油的chaofa” 开发的"},{"role": "user", "content": example["input"]},{"role": "assistant", "content": example["target"]}]prompt = tokenizer.apply_chat_template(chat, tokenize=False)return {"text": prompt}
# Load and format the data using the template TinyLLama is using
dataset = load_dataset("YeungNLP/firefly-train-1.1M", split="train[:500]") 
dataset = dataset.map(format_prompt)

这里要顺便用模型的tokenizer来apply一下prompt_template

获得的dataset形如:

Dataset({features: ['kind', 'input', 'target', 'text'],num_rows: 500
})

然后可以查看一个format好的prompt:

# Example of formatted prompt
print(dataset["text"][100])Output:
<|im_start|>system
你是一个非常棒的人工智能助手,是UP主 “用代码打点酱油的chaofa” 开发的<|im_end|>
<|im_start|>user
我当时在三司,访求太祖、仁宗的手书敕令没有见到,然而人人能传诵那些话,禁止私盐的建议也最终被搁置。
翻译成文言文:<|im_end|>
<|im_start|>assistant
余时在三司,求访两朝墨敕不获,然人人能诵其言,议亦竟寝。<|im_end|>

接下来开始加载模型,我们使用量化来节约显存:

# 量化,为了省显存
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfigmodel_name = "Qwen/Qwen2.5-0.5B-Instruct"# 4-bit quantization configuration - Q in QLoRA
bnb_config = BitsAndBytesConfig(load_in_4bit=True,  # Use 4-bit precision model loadingbnb_4bit_quant_type="nf4",  # Quantization typebnb_4bit_compute_dtype="float16",  # Compute dtypebnb_4bit_use_double_quant=True,  # Apply nested quantization
)
# Load the model to train on the GPU
model = AutoModelForCausalLM.from_pretrained(model_name,device_map="auto",# Leave this out for regular SFTquantization_config=bnb_config,
)
model.config.use_cache = False
model.config.pretraining_tp = 1  # 上面这两个配置,只有在 k-bit 量化的时候需要设置
# Load LLaMA tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
# tokenizer.pad_token = "<PAD>"  # qwen2 的 pad token 不是 <pad>,所以用 <im_end>,因此需要注释掉
tokenizer.padding_side = "left"   # 训练不重要,推理比较重要

然后配置LoraConfig:

from peft import LoraConfig, prepare_model_for_kbit_training, get_peft_model# Prepare LoRA Configuration
peft_config = LoraConfig(lora_alpha=32,  # LoRA Scalinglora_dropout=0.1,  # Dropout for LoRA Layersr=64,  # Rank,可训练数据越多,设置越大bias="none",task_type="CAUSAL_LM",target_modules=  ['k_proj', 'v_proj', 'q_proj']# Layers to target#  ['k_proj', 'gate_proj', 'v_proj', 'up_proj', 'q_proj', 'o_proj', 'down_proj']
)# prepare model for training
model = prepare_model_for_kbit_training(model)
# 如果没有 prepare_model_for_kbit_training,
# 且 training args 中配置了 gradient_checkpointing=True (这个其实也是为了省显存,其实不重要)
# 那么需要设置 model.enable_input_require_grads()
# model.enable_input_require_grads()
model = get_peft_model(model, peft_config)

一些训练的配置

from transformers import TrainingArgumentsoutput_dir = "./results"# Training arguments
training_arguments = TrainingArguments(output_dir=output_dir,per_device_train_batch_size=2,gradient_accumulation_steps=4,optim="adamw_torch",learning_rate=2e-4,lr_scheduler_type="cosine",num_train_epochs=1,logging_steps=10,fp16=True,gradient_checkpointing=True
)

就绪之后就是直接跑trl.SFTTrainer即可:

from trl import SFTTrainer
# Set supervised fine-tuning parameters
trainer = SFTTrainer(model=model,train_dataset=dataset,dataset_text_field="text",   # 注意 dataset 中的 text 字段tokenizer=tokenizer,args=training_arguments,max_seq_length=512,# Leave this out for regular SFTpeft_config=peft_config,
)
# Train model
trainer.train()
# Save QLoRA weights
trainer.model.save_pretrained("qwen2.5-0.5b-instruct-chaofa")

微调后需要做什么?

Merge Adapter (LoRA 和 base model 合并)

from peft import AutoPeftModelForCausalLM
model = AutoPeftModelForCausalLM.from_pretrained("qwen2.5-0.5b-instruct-chaofa",low_cpu_mem_usage=True,device_map="auto",
)
# Merge LoRA and base model
merged_model = model.merge_and_unload()
from transformers import pipeline
pipe = pipeline(task="text-generation", model=merged_model, tokenizer=tokenizer)
prompt_example = """<|im_start|>system
你是一个非常棒的人工智能助手,是UP主 “用代码打点酱油的chaofa” 开发的。<|im_end|>
<|im_start|>user
天气太热了,所以我今天没有学习一点。
翻译成文言文:<|im_end|>
<|im_start|>assistant
"""
print(pipe(prompt_example, max_new_tokens=50)[0]["generated_text"])

输出结果:

<|im_start|>system
你是一个非常棒的人工智能助手,是UP主 “用代码打点酱油的chaofa” 开发的。<|im_end|>
<|im_start|>user
天气太热了,所以我今天没有学习一点。
翻译成文言文:<|im_end|>
<|im_start|>assistant
天气甚热,故今日无学一息。

其他微调方法

PPO / DPO(以Llama为例)

依然是先加载数据集

from datasets import load_dataset
def format_prompt(example):"""Format the prompt to using the <|user|> template TinyLLama is using"""# Format answerssystem = "<|system|>\n" + example['system'] + "</s>\n"prompt = "<|user|>\n" + example['input'] + "</s>\n<|assistant|>\n"chosen = example['chosen'] + "</s>\n"rejected = example['rejected'] + "</s>\n"return {"prompt": system + prompt,"chosen": chosen,"rejected": rejected,}# Apply formatting to the dataset and select relatively short answers
dpo_dataset = load_dataset("argilla/distilabel-intel-orca-dpo-pairs", split="train")
dpo_dataset = dpo_dataset.filter(lambda r:r["status"] != "tie" andr["chosen_score"] >= 8 andnot r["in_gsm8k_train"]
)
dpo_dataset = dpo_dataset.map(format_prompt, remove_columns=dpo_dataset.column_names)
dpo_dataset
"""
Dataset({features: ['chosen', 'rejected', 'prompt'],num_rows: 5922
})
"""

然后同样的加载模型(使用量化节约显存)

from peft import AutoPeftModelForCausalLM
from transformers import BitsAndBytesConfig, AutoTokenizer# 4-bit quantization configuration - Q in QLoRA
bnb_config = BitsAndBytesConfig(load_in_4bit=True,  # Use 4-bit precision model loadingbnb_4bit_quant_type="nf4",  # Quantization typebnb_4bit_compute_dtype="float16",  # Compute dtypebnb_4bit_use_double_quant=True,  # Apply nested quantization
)# Merge LoRA and base model
model = AutoPeftModelForCausalLM.from_pretrained("TinyLlama-1.1B-qlora",low_cpu_mem_usage=True,device_map="auto",quantization_config=bnb_config,
)
merged_model = model.merge_and_unload()# Load LLaMA tokenizer
model_name = "TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
tokenizer.pad_token = "<PAD>"
tokenizer.padding_side = "left"

这里使用的是TinyLlama-1.1B-qlora

接着还是先配置LoRA的Config:

from peft import LoraConfig, prepare_model_for_kbit_training, get_peft_model# Prepare LoRA Configuration
peft_config = LoraConfig(lora_alpha=32,  # LoRA Scalinglora_dropout=0.1,  # Dropout for LoRA Layersr=64,  # Rankbias="none",task_type="CAUSAL_LM",target_modules=  # Layers to target['k_proj', 'gate_proj', 'v_proj', 'up_proj', 'q_proj', 'o_proj', 'down_proj']
)# prepare model for training
model = prepare_model_for_kbit_training(model)
model = get_peft_model(model, peft_config)

然后在训练参数设置时,可以使用DPO策略进行训练微调:

from trl import DPOConfigoutput_dir = "./results"# Training arguments
training_arguments = DPOConfig(output_dir=output_dir,per_device_train_batch_size=2,gradient_accumulation_steps=4,optim="paged_adamw_32bit",learning_rate=1e-5,lr_scheduler_type="cosine",max_steps=200,logging_steps=10,fp16=True,gradient_checkpointing=True,warmup_ratio=0.1
)

如法炮制,开干:

from trl import DPOTrainer# Create DPO trainer
dpo_trainer = DPOTrainer(model,args=training_arguments,train_dataset=dpo_dataset,tokenizer=tokenizer,peft_config=peft_config,beta=0.1,max_prompt_length=512,max_length=512,
)

同理最后需要合并Adapters

from peft import PeftModel# Merge LoRA and base model
model = AutoPeftModelForCausalLM.from_pretrained("TinyLlama-1.1B-qlora",low_cpu_mem_usage=True,device_map="auto",
)
sft_model = model.merge_and_unload()# Merge DPO LoRA and SFT model
dpo_model = PeftModel.from_pretrained(sft_model,"TinyLlama-1.1B-dpo-qlora",device_map="auto",
)
dpo_model = dpo_model.merge_and_unload()

微调好的模型,直接使用transformers的pipeline调用

from transformers import pipeline
# Use our predefined prompt template
prompt = """<|user|>
Tell me something about Large Language Models.</s>
<|assistant|>
"""
# Run our instruction-tuned model
pipe = pipeline(task="text-generation", model=dpo_model, tokenizer=tokenizer)
print(pipe(prompt)[0]["generated_text"])

输出结果:

<|user|>
Tell me something about Large Language Models.</s>
<|assistant|>
Large Language Models (LLMs) are a type of artificial intelligence (AI) that can generate human-like language. They are trained on large amounts of data, including text, audio, and video, and are capable of generating complex and nuanced language.LLMs are used in a variety of applications, including natural language processing (NLP), machine translation, and chatbots. They can be used to generate text, speech, or images, and can be trained to understand different languages and dialects.One of the most significant applications of LLMs is in the field of natural language generation (NLG). LLMs can be used to generate text in a variety of languages, including English, French, and German. They can also be used to generate speech, such as in chatbots or voice assistants.LLMs have the potential to revolutionize the way we communicate and interact with each other. They can help us create more engaging and personalized content, and they can also help us understand each other better.

相关文章:

【速写】SFT案例实操(以Qwen2.5-instruct-0.5B)

参考资料&#xff1a; https://openbayes.com/console/bbruceyuan/containers/OPg9Oo99ET6https://www.bilibili.com/video/BV1NM1tY3Eu5 LoRA微调案例 首先还是要安装&#xff1a; !pip install -q accelerate peft bitsandbytes transformers sentencepiece !pip install…...

springboot457-库存管理系统(源码+数据库+纯前后端分离+部署讲解等)

&#x1f495;&#x1f495;作者&#xff1a; 爱笑学姐 &#x1f495;&#x1f495;个人简介&#xff1a;十年Java&#xff0c;Python美女程序员一枚&#xff0c;精通计算机专业前后端各类框架。 &#x1f495;&#x1f495;各类成品Java毕设 。javaweb&#xff0c;ssm&#xf…...

Node.js中间件的分类

目录 Node.js 中间件的分类与详细介绍 1. 目录结构 2. Express 中间件的主要分类 3. 代码实现 1. 应用级中间件&#xff08;作用于整个应用&#xff09; 示例&#xff1a;日志记录中间件 2. 路由级中间件&#xff08;仅作用于特定路由&#xff09; 示例&#xff1a;身份…...

棒球规则快速入门·棒球1号位

棒球规则快速入门&#xff1a; 得分方式 进攻方击球后&#xff0c;依次跑过一、二、三垒并返回本垒得1分。若击球直接飞出外场围栏&#xff08;全垒打&#xff09;&#xff0c;击球员和已上垒的跑垒员均可得分。 比赛结构 共9局&#xff0c;每局分上下半场&#xff0c;双方各…...

【深度学习】通过colab将本地的数据集上传到drive

本地数据集上传到colab很慢&#xff0c;而且断开后就没了&#xff0c;因此通过colab将本地的数据集上传到drive&#xff0c;即使断开连接&#xff0c;第二次连接后挂载drive后即可直接使用数据集。 步骤一、将本地数据集上传到colab的临时文件夹中&#xff0c;由于将文件夹上传…...

MYSQL 存储引擎 和 日志

存储引擎 InnoDB 支持行级别的锁粒度&#xff0c;MyISAM 不支持&#xff0c;只支持表级别的锁粒度。MyISAM 不提供事务支持。InnoDB 提供事务支持&#xff0c;实现了 SQL 标准定义了四个隔离级别。MyISAM 不支持外键&#xff0c;而 InnoDB 支持。MyISAM 不支持 MVCC&#xff0c…...

【2022】【论文笔记】太赫兹量子阱——

前言 类型 太赫兹 + 量子阱 太赫兹 + 量子阱 太赫兹+量子阱 期刊 红外与毫米波学报 红外与毫米波学报 红外与毫米波学报 作者 张真真 ,...

【NLP 面经 7、常见transformer面试题】

目录 1. 为何使用多头注意力机制&#xff1f; 2. Q和K使用不同权重矩阵的原因 3. 选择点乘而非加法的原因 4. Attention进行scaled的原因 5. 对padding做mask操作 6. 多头注意力降维原因 7. Transformer Encoder模块简介 8. 乘以embedding size的开方的意义 9. 位置编码 10. 其…...

在js中数组相关用法讲解

数组 uniqueArray 简单数组去重 /*** 简单数组去重* param arr* returns*/ export const uniqueArray <T>(arr: T[]) > [...new Set(arr)];const arr1 [1,1,1,1 2, 3];uniqueArray(arr); // [1,2,3]uniqueArrayByKey 根据 key 数组去重 /*** 根据key数组去重* …...

第四章 react-redux,@reduxjs/toolkit依赖,学习

redux系列文章目录 第一章 简单学习redux,单个reducer 第二章 简单学习redux,多个reducer 第三章 redux和react-redux&#xff0c;reduxjs/toolkit依赖结合使用 第五章 两张图告诉你redux常使用的api有哪些 前言 本章将使用react-redux&#xff0c;reduxjs/toolkit依赖创…...

雅思7分听说读写专项书籍推荐

对于目标 7分以上的雅思考生&#xff08;中高级水平&#xff09;&#xff0c;选对资料真的事半功倍。 下面按照 听力、阅读、写作、口语、综合书籍 五大类来分别列举高分推荐书籍&#xff0c;每本书包括&#xff1a;适合人群、核心内容、推荐理由&#xff0c;并贴合7分目标。 …...

C++容器使用说明

C标准库提供了多种容器&#xff0c;分为序列容器、关联容器、无序关联容器、容器适配器及其他相关类型。以下是所有标准容器的分类及简要说明&#xff1a; 1. 序列容器&#xff08;Sequence Containers&#xff09; 按线性顺序存储元素&#xff0c;支持随机或顺序访问。 vecto…...

Python-函数

1. 函数基础 1.1 定义函数 在Python中&#xff0c;使用def关键字来定义函数&#xff1a; def greet():"""简单的问候函数"""print("Hello, World!")1.2 调用函数 定义函数后&#xff0c;可以通过函数名加括号来调用&#xff1a; …...

【Redis】数据的淘汰策略

目录 淘汰策略方案&#xff08;8种&#xff09; LRU和LFU策略的区别 使用建议 手搓LRU算法 方式一 方式二 大家好&#xff0c;我是jstart千语。今天和大家回来聊一下redis&#xff0c;这次要讲的是它的淘汰策略。为什么需要淘汰策略呢&#xff0c;就是当redis里面的内存占…...

第七章:从类库到服务的分布式基石_《凤凰架构:构建可靠的大型分布式系统》

第七章&#xff1a;从类库到服务的分布式基石 一、服务发现&#xff08;Service Discovery&#xff09; 核心目标&#xff1a;解决分布式系统中服务实例动态变化时如何定位可用服务的问题。 1. 服务发现的意义 动态环境挑战&#xff1a; 微服务架构中&#xff0c;服务实例的…...

spring-ai-alibaba第九章使用Milvus构建大模型RAG应用

1、pom文件 <dependencies><dependency><groupId>com.alibaba.cloud.ai</groupId><artifactId>spring-ai-alibaba-starter</artifactId><version>${spring-ai-alibaba.version}</version></dependency><dependency&g…...

手撕LLM(一):从源码出发,探索LLM推理全流程

2025年&#xff0c;大模型爆发元年&#xff0c;各种各样的大模型、框架、工具层出不穷&#xff0c;不断刷新人们应用大模型的门槛&#xff0c;短短10行代码&#xff0c;就能完成“加载模型加载数据集推理强化学习”的全流程训练&#xff0c;但其底层的运行机制也被高度抽象的接…...

讯飞语音听写(流式版)开发指南

语音交互大模型的功能越来越受到重视。讯飞语音听写&#xff08;流式版&#xff09;为开发者提供了一种高效、准确的语音识别解决方案。本文将基于 Home.vue、iat_xfyun.js 和 sparkChat.js 这三个文档&#xff0c;详细阐述讯飞语音听写&#xff08;流式版&#xff09;的开发逻…...

P3654 First Step (ファーストステップ)

题目描述 可是……这个篮球场&#xff0c;好像很久没有使用过的样子啊…… 里面堆满了学校的各种杂物呢…… 我们 Aqours 的成员要怎么在里面列队站下呢&#xff1f; 我们浦之星女子学院的篮球场是一个 R 行 C 列的矩阵&#xff0c;其中堆满了各种学校的杂物 (用 # 表示)&a…...

MySQL篇(六)MySQL 分库分表:应对数据增长挑战的有效策略

MySQL篇&#xff08;六&#xff09;MySQL 分库分表&#xff1a;应对数据增长挑战的有效策略 MySQL篇&#xff08;六&#xff09;MySQL 分库分表&#xff1a;应对数据增长挑战的有效策略一、引言二、为什么需要分库分表2.1 性能瓶颈2.2 存储瓶颈2.3 高并发压力 三、分库分表的方…...

SonarQube 配置SQL Server 数据库遇到的问题

之前本机跑了一套SonarQube的社区版&#xff0c;默认使用的是H2数据库&#xff0c;那么我把它练到我机器上的SQL Server数据库了&#xff0c;期间遇到以下两个问题&#xff0c;并在配置过程中解决掉&#xff0c;特将这个过程记录下来。 一、JDBC连接SQL Server问题 1. 问题出…...

23种设计模式-行为型模式-备忘录

文章目录 简介问题解决代码关键实现要点功能扩展方向 总结 简介 备忘录是一种行为设计模式&#xff0c; 允许在不暴露对象实现细节的情况下保存和恢复对象之前的状态。 问题 假如你正在开发一款文字编辑器应用。你想加入撤销功能。你可以采用直接的方式来实现: 程序在执行任…...

IDEA/WebStrom操作之commit前批量清除console.log()与debugger

前言&#xff1a; 在前端开发过程中&#xff0c;往往需要频繁用到console.log()与debugger&#xff0c;来观察数据具体情况以及断点调试。在经历了水生火热的开发动作后&#xff0c;往往会残留一地console.log()和debugger&#xff0c;若开发者还得手动在多个文件中一个个去除…...

每日算法-250405

34. 在排序数组中查找元素的第一个和最后一个位置 题目 思路 本题的核心思路是二分查找。 解题过程 问题分析&#xff1a;在一个升序排列的数组中查找一个目标值 target 的起始和结束位置。这是一个典型的二分查找应用场景。核心转换&#xff1a;题目要求找到 target 的第一个…...

设计模式简述(四)模板方法模式

模板方法模式 描述基本定义使用 描述 当一系列业务的基本流程是相同的&#xff0c;对于不同的业务可以在各自子类实现 所谓模板方法指的就是父类中固定的那部分代码 其实这里的思想和前面设计原则中开闭原则的描述是一致的&#xff0c;父类中的模板代码就是稳定的部分&#x…...

论文修改时有哪些需要注意的问题?

论文修改是学术写作中不可或缺的环节&#xff0c;直接影响成果的专业性和说服力。许多作者因忽略细节或急于定稿&#xff0c;导致论文质量大打折扣。那么&#xff0c;如何修改才能提升论文的严谨性与可读性呢&#xff1f; 一、逻辑结构 论文修改时&#xff0c;先从头到尾通读…...

JAVA阻塞队列

目录 一、什么是阻塞队列&#xff1f;特点是什么&#xff1f; 二、阻塞队列的两种创建方式&#xff1a; 1、使用 ArrayBlockingQueue<>( ) : 2、使用 LinkedBlockingQueue<>( ) &#xff1a; 三、阻塞队列方法的使用&#xff1a; 阻塞队列关键的两个方法&…...

tomcat与spring-web

文章目录 SpringServletContainerInitializerWebApplicationInitializerWebApplicationInitializer接口AbstractContextLoaderInitializer抽象类AbstractDispatcherServletInitializer抽象类AbstractAnnotationConfigDispatcherServletInitializer抽象类 WebApplicationContext…...

将电脑控制手机编写为MCP server

文章目录 电脑控制手机后,截屏代码复习MCP server构建修改MCP的config文件测试效果困惑电脑控制手机后,截屏代码复习 def capture_window(hwnd: int, filename: str = None) -> dict:""&...

[ctfshow web入门]burpsuite的下载与使用

下载 吾爱破解网站工具区下载burpsuite https://www.52pojie.cn/thread-1544866-1-1.html 本博客仅转载下载链接&#xff0c;下载后请按照说明进行学习使用 打开 配置 burpsuite配置 burpsuite代理设置添加127.0.0.1:8080 浏览器配置 如果是谷歌浏览器&#xff0c;打开win…...

文章记单词 | 第25篇(六级)

一&#xff0c;单词释义 mathematical&#xff1a;形容词&#xff0c;意为 “数学的&#xff1b;数学上的&#xff1b;运算能力强的&#xff1b;关于数学的”trigger&#xff1a;名词&#xff0c;意为 “&#xff08;枪的&#xff09;扳机&#xff1b;&#xff08;炸弹的&…...

讯飞语音合成(流式版)语音专业版高质量的分析

一、引言 在现代的 Web 应用开发中&#xff0c;语音合成技术为用户提供了更加便捷和人性化的交互体验。讯飞语音合成&#xff08;流式版&#xff09;以其高效、稳定的性能&#xff0c;成为了众多开发者的首选。本文将详细介绍在 Home.vue 文件中实现讯飞语音合成&#xff08;流…...

【MediaPlayer】基于libvlc+awtk的媒体播放器

基于libvlcawtk的媒体播放器 libvlc下载地址 awtk下载地址 代码实现libvlc相关逻辑接口UI媒体接口实例化媒体播放器注意事项 libvlc 下载地址 可以到https://download.videolan.org/pub/videolan/vlc/去下载一个vlc版本&#xff0c;下载后其实是vlc的windows客户端&#xff0…...

复古未来主义屏幕辉光像素化显示器反乌托邦效果PS(PSD)设计模板样机 Analog Retro-Futuristic Monitor Effect

这款模拟复古未来主义显示器效果直接取材于 90 年代赛博朋克电影中的黑客巢穴&#xff0c;将粗糙的屏幕辉光和像素化的魅力强势回归。它精准地模仿了老式阴极射线管显示器&#xff0c;能将任何图像变成故障频出的监控画面或高风险的指挥中心用户界面。和……在一起 2 个完全可编…...

Kafka 如何保证消息有序性?

Kafka 保证消息顺序性&#xff0c;是基于 Partition&#xff08;分区&#xff09;级别的顺序 来实现的。下面我们详细拆解一下&#xff1a; ✅ 同一个 Partition 内&#xff0c;消息是严格有序的 Kafka 在 同一个分区&#xff08;Partition&#xff09;内&#xff0c;消息是按…...

【积木画】——第十三届蓝桥杯(2022)T7思路解析

题目描述 关键词 递推、dp 思路 显然这是一道递推题。 但是为什么我还要写在这呢&#xff1f;因为我虽然看了题解但是还是没想明白&#xff0c;综合了下面两篇 参考文献我才初步理解这题的精髓。所以还是自己写一遍为好。 我们把最终结果记为F(n)。 情况1 直接以一个竖着…...

Android studio xml布局预览中 Automotive和Autotive Distant Display的区别

在 Android Studio 中&#xff0c;Configure Hardware Profile 设置中的 Device Type 选项有两个不同的设置&#xff1a;Android Automotive 和 Android Automotive Distant Display&#xff0c;它们的含义和用途如下&#xff1a; 1. Android Automotive 含义&#xff1a;这个…...

第十三章:持久化存储_《凤凰架构:构建可靠的大型分布式系统》

第十三章 持久化存储 一、Kubernetes存储设计核心概念 &#xff08;1&#xff09;存储抽象模型 PersistentVolume (PV)&#xff1a;集群级别的存储资源抽象&#xff08;如NFS卷/云存储盘&#xff09;PersistentVolumeClaim (PVC)&#xff1a;用户对存储资源的声明请求&#…...

Nginx 基础使用(2025)

一、Nginx目录结构 [rootlocalhost ~]# tree /usr/local/nginx /usr/local/nginx ├── client_body_temp # POST 大文件暂存目录 ├── conf # Nginx所有配置文件的目录 │ ├── fastcgi.conf # fastcgi相…...

Docker基础1

本篇文章我将从系统的知识体系讲解docker的由来和在linux中的安装下载 随后的文章会介绍下载镜像、启动新容器、登录新容器 如需转载&#xff0c;标记出处 docker的出现就是为了节省资本和服务器资源 当企业需要一个新的应用程序时&#xff0c;需要为它买台全新的服务器。这样…...

【奇点时刻】GPT4o新图像生成模型底层原理深度洞察报告

个人最近一直在关注openai的新图像生成特性&#xff0c;以下内容基于现阶段社区及研究者们对 GPT-4O 图像生成功能的公开测试、逆向分析与技术推测综合而成&#xff0c;OpenAI 并未正式发布完整的技术报告&#xff0c;因此本文为非官方推断总结。但从多方信息与技术背景出发&am…...

Java的Selenium的特殊元素操作与定位之模态框

Modal Dialogue Box&#xff0c;又叫做模式对话框&#xff0c;是指在用户想要对对话框以外的应用程序进行操作时&#xff0c;必须首先对该对话框进行响应。如单击【确定】或【取消】按钮等将该对话框关闭。 alert&#xff08;警告&#xff09; //访问本地的HTML文件 chromeDr…...

回归预测 | Matlab实现NRBO-Transformer-LSTM多输入单输出回归预测

回归预测 | Matlab实现NRBO-Transformer-LSTM多输入单输出回归预测 目录 回归预测 | Matlab实现NRBO-Transformer-LSTM多输入单输出回归预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.【JCR一区级】Matlab实现NRBO-Transformer-LSTM多输入单输出回归预测&#xf…...

Python菜鸟教程(小程序)

目录 一.简易计算器 二.学生成绩分级 三.密码设置 四.作业选择 点赞收藏,评论支持 一.简易计算器 print(-------使用的运算符-------\n) print(1.加号) print(2.减号) print(3.乘号) print(4.除号) Aint(input(请输入第一个数: )) Bint(input(请输入第二个数: )) Fi…...

类的(多态性、虚函数)基础练习

练习1&#xff1a;&#xff08;简单&#xff09; #include <iostream> using namespace std; class Vehicle { public: virtual void run() const0; }; class Car: public Vehicle { public: void run() const { cout << "run a car. "<<…...

特殊的质数肋骨--dfs+isp

1.dfs全排列组数&#xff0c;an记得还原 2.如果范围确定且只比较质数&#xff0c;isp比线性筛快&#xff0c;主要这个范围太大了 https://www.luogu.com.cn/problem/P1218 #include<bits/stdc.h> using namespace std; #define N 100011 typedef long long ll; typed…...

智能体开发实战指南:提示词设计、开发框架与工作流详解

在大语言模型&#xff08;LLM&#xff09;驱动的智能体&#xff08;Agent&#xff09;快速发展的今天&#xff0c;构建一个实用、智能的Agent已不再遥不可及。无论你是开发法律助手、租房合同分析器&#xff0c;还是通用办公自动化助手&#xff0c;理解提示词工程&#xff08;P…...

jetson orin nano学习(torch+OpenCV+yolov5+)

一&#xff1a;入门第一件事&#xff1a;跟着商家教程配置哈哈 指令&#xff1a;nvidia-smi -h 帮助命令 sudo jtop --查看nvidia的gpu状态 Tip:教程下载的pytorth,cuda,cudnn版本不一定是你项目符合的&#xff0c;要提前想好 1.2 安装虚拟环境包&#xff08;要安…...

client-go如何监听自定义资源

如何使用 client-go 监听自定义资源 在 Kubernetes 中使用 client-go 监听自定义资源&#xff08;Custom Resource&#xff0c;简称 CR&#xff09;需要借助 Dynamic Client 或 Custom Informer&#xff0c;因为 client-go 的标准 Clientset 只支持内置资源&#xff08;如 Pod…...

【51单片机】3-3【定时器/计数器/中断】超声波测距模块测距

1.硬件 51最小系统超声波测距模块 2.软件 #include "reg52.h"//距离小于10cm,D5亮&#xff0c;D6灭&#xff0c;反之相反现象sbit D5 P3^7;//根据原理图&#xff08;电路图&#xff09;&#xff0c;设备变量led1指向P3组IO口的第7口 sbit D6 P3^6;//根据原理图&…...