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

深入解析 Loss 减少方式:mean和sum的区别及其在大语言模型中的应用 (中英双语)

深入解析 Loss 减少方式:meansum 的区别及其在大语言模型中的应用

在训练大语言模型(Large Language Models, LLM)时,损失函数(Loss Function)的处理方式对模型的性能和优化过程有显著影响。本文以 reduce_loss 参数为例,详细探讨 meansum 两种方式的定义、适用场景及其对对话模型性能的潜在提升原因,并通过代码实例加深理解。


1. 什么是 reduce_loss

reduce_loss 决定了在每个 batch 中,如何对 token-level 的损失进行归一化或累加处理。常见的选项是:

  • mean: 取每个 token 损失的平均值。
  • sum: 将每个 token 损失直接累加。

参数定义示例(在代码中通过 dataclass 定义):参考来源:https://github.com/allenai/open-instruct

from dataclasses import dataclass, field@dataclass
class TrainingArguments:reduce_loss: str = field(default="mean",metadata={"help": ("How to reduce loss over tokens. Options are 'mean' or 'sum'.""Using 'sum' can improve chat model performance.")},)

2. meansum 的定义

2.1 mean 模式
  • 定义:将 batch 中所有 token 的损失值取平均。
  • 公式
    Loss mean = ∑ i = 1 N Loss i N \text{Loss}_{\text{mean}} = \frac{\sum_{i=1}^{N} \text{Loss}_i}{N} Lossmean=Ni=1NLossi
    其中 ( N N N) 是当前 batch 中的 token 总数。
  • 特性:每个 token 的损失对最终的 loss 贡献相等,损失值与 batch 中的 token 数无关。
2.2 sum 模式
  • 定义:将 batch 中所有 token 的损失值直接累加。
  • 公式
    Loss sum = ∑ i = 1 N Loss i \text{Loss}_{\text{sum}} = \sum_{i=1}^{N} \text{Loss}_i Losssum=i=1NLossi
  • 特性:长序列(更多 token)的损失对总 loss 的贡献更大,损失值直接与 token 数成正比。

3. meansum 的区别

模式特点优点缺点
mean损失对 token 数归一化,独立于 batch size。稳定性强,适用于 token 数差异大的批次。长序列与短序列对损失的贡献相同,可能弱化长序列的重要性。
sum损失值与 token 总数成正比,长序列贡献更大。在注重长序列表现的任务中效果更好(如对话生成)。损失值随 batch size 变化波动,需要动态调整学习率。

4. 适用场景分析

4.1 mean
  • 适用任务:大多数语言建模任务,如 GPT 或 BERT 的预训练。
  • 适用场景:当训练数据中序列长度差异较大时,mean 可以避免因长序列的损失值过大而导致梯度更新不均衡。
4.2 sum
  • 适用任务:对长序列表现要求较高的任务,如对话生成(Chat Models)和长文本生成。
  • 适用场景:长序列的损失占比更高,从而使优化过程更加关注全局上下文的建模。

5. 为什么 sum 能提升对话模型性能?

对话模型(Chat Models)的训练中,长序列往往包含丰富的上下文信息,而短序列则可能无法体现模型的上下文理解能力。在 sum 模式下:

  1. 长序列的重要性增加:长序列的损失对总损失的贡献更大,这促使模型更关注上下文的建模。
  2. 对全局一致性更敏感sum 模式下,模型的优化方向更倾向于全序列的一致性,特别适合需要长距离依赖的任务。

示例
假设一个 batch 包含以下两个样本:

  • 样本 A: 长度为 10,损失总和为 5。
  • 样本 B: 长度为 50,损失总和为 25。

计算损失贡献:

  • mean 模式
    Loss mean = 5 + 25 10 + 50 = 0.5 \text{Loss}_{\text{mean}} = \frac{5 + 25}{10 + 50} = 0.5 Lossmean=10+505+25=0.5
    样本 A 和 B 的贡献权重相同。
  • sum 模式
    Loss sum = 5 + 25 = 30 \text{Loss}_{\text{sum}} = 5 + 25 = 30 Losssum=5+25=30
    样本 B 的贡献权重显著增加,优化更关注长序列。

6. 实战代码

以下是一个完整的训练脚本,展示如何在 Hugging Face 的 transformers 框架中使用 reduce_loss 参数。

from transformers import AutoModelForCausalLM, AutoTokenizer
from datasets import load_dataset
from torch.utils.data import DataLoader
import torch# 模型和数据集
model_name = "meta-llama/Llama-3.1-8B"
dataset_name = "allenai/tulu-3-sft-mixture"model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)dataset = load_dataset(dataset_name)
tokenized_dataset = dataset.map(lambda x: tokenizer(x['text'], truncation=True, padding="max_length"), batched=True)
train_loader = DataLoader(tokenized_dataset["train"], batch_size=2, shuffle=True)# 训练设置
reduce_loss = "sum"  # 改为 "mean" 可对比效果
optimizer = torch.optim.AdamW(model.parameters(), lr=5e-6)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)# 训练循环
for epoch in range(2):for batch in train_loader:inputs = torch.tensor(batch["input_ids"]).to(device)labels = inputs.clone()outputs = model(inputs, labels=labels)if reduce_loss == "sum":loss = outputs.loss.sum()else:  # 默认 "mean"loss = outputs.loss.mean()loss.backward()optimizer.step()optimizer.zero_grad()print(f"Epoch: {epoch}, Loss: {loss.item()}")

7. 注意事项与优化建议

  1. 动态调整学习率

    • 使用 sum 时,由于损失值放大,建议适配学习率,如降低到 mean 模式的 ( 1 / N 1/N 1/N )。
    • 配合学习率调度器(如 linear)优化训练。
  2. 对长短序列的平衡

    • 若长序列权重过大导致模型性能退化,可结合 curriculum learning 或混合训练策略(如对长短序列按比例采样)。
  3. 性能评估

    • 在验证集上,关注长序列和短序列的生成性能对比。

8. 总结

reduce_loss 的选择对模型性能有直接影响:

  • mean 更通用,适合大多数语言建模任务。
  • sum 在对话生成等长序列敏感任务中表现更优。

希望本文能为 LLM 研究人员提供思路和参考,在具体任务中灵活选择合适的损失归一化方式,从而提升模型性能。

Understanding the Difference Between mean and sum Loss Reduction in LLM Training

When training large language models (LLMs), the way token-level loss is reduced across a batch can significantly impact optimization and model performance. This article delves into the reduce_loss parameter, exploring the differences between mean and sum reduction modes, their definitions, use cases, and why sum might improve the performance of chat-oriented models. Practical code examples are also provided for clarity.


1. What is reduce_loss?

The reduce_loss parameter determines how the token-level loss values in a batch are aggregated. The two most common options are:

  • mean: Averages the loss over all tokens in a batch.
  • sum: Sums the loss of all tokens in a batch.

Example definition (from the codebase using Python dataclass):

from dataclasses import dataclass, field@dataclass
class TrainingArguments:reduce_loss: str = field(default="mean",metadata={"help": ("How to reduce loss over tokens. Options are 'mean' or 'sum'.""Using 'sum' can improve chat model performance.")},)

2. Definitions of mean and sum

2.1 mean
  • Definition: Averages the loss across all tokens in a batch.
  • Formula:
    Loss mean = ∑ i = 1 N Loss i N \text{Loss}_{\text{mean}} = \frac{\sum_{i=1}^{N} \text{Loss}_i}{N} Lossmean=Ni=1NLossi
    where ( N N N ) is the total number of tokens in the batch.
  • Characteristics: The contribution of each token to the final loss is normalized, making the loss independent of the batch’s token count.
2.2 sum
  • Definition: Sums up the loss across all tokens in a batch.
  • Formula:
    Loss sum = ∑ i = 1 N Loss i \text{Loss}_{\text{sum}} = \sum_{i=1}^{N} \text{Loss}_i Losssum=i=1NLossi
  • Characteristics: The total loss is proportional to the number of tokens, giving longer sequences more weight in the optimization process.

3. Key Differences Between mean and sum

Reduction ModeCharacteristicsAdvantagesDisadvantages
meanNormalizes the loss by token count.Stable and robust for datasets with variable-length sequences.Long sequences are underweighted relative to short ones.
sumLoss scales with the number of tokens.Places greater emphasis on longer sequences, improving performance in tasks requiring context modeling.Loss values vary with batch size, necessitating dynamic learning rate adjustment.

4. Use Cases for mean and sum

4.1 mean
  • Best Suited For: Pretraining or general language modeling tasks like GPT or BERT.
  • Scenario: When the dataset contains sequences of widely varying lengths, mean ensures that longer sequences do not disproportionately influence gradient updates.
4.2 sum
  • Best Suited For: Tasks requiring high performance on long sequences, such as dialogue generation or document-level text generation.
  • Scenario: Encourages the model to prioritize sequences with richer contexts, as their loss contributes more to the overall optimization.

5. Why Does sum Improve Chat Model Performance?

In chat-oriented models, sequences are typically longer and require the model to understand and generate coherent responses over extended contexts. Using sum mode:

  1. Enhances Long Sequence Weighting: Longer sequences contribute more to the total loss, emphasizing the importance of context modeling.
  2. Encourages Global Consistency: By assigning more weight to longer contexts, the model better captures dependencies across the entire sequence.
  3. Balances Token Importance: Since chat models are often evaluated on dialogue-level coherence, sum ensures that tokens from the context and the response are proportionally weighted.

Example:
Consider a batch with two samples:

  • Sample A: Sequence length = 10, loss = 5.
  • Sample B: Sequence length = 50, loss = 25.

Loss calculations:

  • mean mode:
    Loss mean = 5 + 25 10 + 50 = 0.5 \text{Loss}_{\text{mean}} = \frac{5 + 25}{10 + 50} = 0.5 Lossmean=10+505+25=0.5
    Both samples contribute equally to the loss.
  • sum mode:
    Loss sum = 5 + 25 = 30 \text{Loss}_{\text{sum}} = 5 + 25 = 30 Losssum=5+25=30
    Sample B contributes much more to the total loss, focusing the optimization on longer contexts.

6. Practical Implementation

Here’s a practical training script that demonstrates the use of reduce_loss in both modes.

from transformers import AutoModelForCausalLM, AutoTokenizer
from datasets import load_dataset
from torch.utils.data import DataLoader
import torch# Model and dataset
model_name = "meta-llama/Llama-3.1-8B"
dataset_name = "allenai/tulu-3-sft-mixture"model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)dataset = load_dataset(dataset_name)
tokenized_dataset = dataset.map(lambda x: tokenizer(x['text'], truncation=True, padding="max_length"), batched=True)
train_loader = DataLoader(tokenized_dataset["train"], batch_size=2, shuffle=True)# Training setup
reduce_loss = "sum"  # Change to "mean" to compare effects
optimizer = torch.optim.AdamW(model.parameters(), lr=5e-6)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)# Training loop
for epoch in range(2):for batch in train_loader:inputs = torch.tensor(batch["input_ids"]).to(device)labels = inputs.clone()outputs = model(inputs, labels=labels)if reduce_loss == "sum":loss = outputs.loss.sum()else:  # Default: "mean"loss = outputs.loss.mean()loss.backward()optimizer.step()optimizer.zero_grad()print(f"Epoch: {epoch}, Loss: {loss.item()}")

7. Practical Considerations

  1. Learning Rate Adjustment:

    • When using sum, the loss magnitude increases with batch size, so you may need to adjust the learning rate (e.g., scale it down by ( 1 / N 1/N 1/N )).
  2. Balancing Long and Short Sequences:

    • Overweighting long sequences can sometimes harm generalization. Using curriculum learning or sampling strategies (e.g., proportional sampling) can help mitigate this.
  3. Validation:

    • Evaluate model performance on both short and long sequences to confirm improvements in the intended metrics.

8. Conclusion

The choice between mean and sum loss reduction modes depends on the specific task and dataset:

  • Use mean for general-purpose language modeling tasks where sequence lengths vary significantly.
  • Use sum for tasks that prioritize long-sequence performance, such as chat models or long-text generation.

Understanding and experimenting with these settings can lead to better-optimized models, particularly in the nuanced field of LLM fine-tuning.

后记

2024年12月3日16点04分于上海,在GPT4o大模型辅助下完成。

相关文章:

深入解析 Loss 减少方式:mean和sum的区别及其在大语言模型中的应用 (中英双语)

深入解析 Loss 减少方式:mean 和 sum 的区别及其在大语言模型中的应用 在训练大语言模型(Large Language Models, LLM)时,损失函数(Loss Function)的处理方式对模型的性能和优化过程有显著影响。本文以 re…...

opencv4.8 ubuntu20.04源码编译 安装报错记录

-- IPPICV: Downloading ippicv_2021.8_lnx_intel64_20230330_general.tgz from https://raw.githubusercontent.com/opencv/opencv_3rdparty/1224f78da6684df04397ac0f40c961ed37f79ccb/ippicv/ippicv_2021.8_lnx_intel64_20230330_general.tgz make -j8 到这咋不动了 代理配…...

16-03、JVM系列之:内存与垃圾回收篇(三)

JVM系列之:内存与垃圾回收篇(三) ##本篇内容概述: 1、执行引擎 2、StringTable 3、垃圾回收一、执行引擎 ##一、执行引擎概述 如果想让一个java程序运行起来,执行引擎的任务就是将字节码指令解释/编译为对应平台上的本地机器指令才可以。 简…...

在 Spring Boot 中使用 JPA(Java Persistence API)进行数据库操作

步骤 1: 添加依赖 在 pom.xml 文件中添加相关依赖&#xff1a; <dependencies><!-- Spring Boot Starter Web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><…...

【sqlserver】mssql 批量加载数据文件 bulk copy使用

参考文章&#xff1a; Using bulk copy with the JDBC driver SqlServer数据批量写入 SqlServer批量插入数据方法–SqlBulkCopy sqlserver buld copy需要提供&#xff0c;数据文件的对应表的元数据信息主要的字段的位置、字段的名称、字段的数据类型。 执行bulk load时候不一…...

卷积神经网络(CNN)的层次结构

卷积神经网络&#xff08;CNN&#xff09;是一种以其处理图像和视频数据的能力而闻名的深度学习模型&#xff0c;其基本结构通常包括以下几个层次&#xff0c;每个层次都有其特定的功能和作用&#xff1a; 1. 输入层&#xff08;Input Layer&#xff09;&#xff1a; 卷积神经网…...

使用Excel的COUNTIFS和SUMIFS函数进行高级数据分析

使用Excel的COUNTIFS和SUMIFS函数进行高级数据分析 引言 在处理数据时&#xff0c;Excel 提供了多种内置函数来帮助用户快速获取所需信息。其中&#xff0c;COUNTIFS 和 SUMIFS 是两个非常强大的多条件聚合函数&#xff0c;它们允许你根据一个或多个标准来统计或汇总数据。本…...

上传ssh公钥到目标服务器

创建密钥 ssh-keygen -t rsa -b 4096 -C "xxxx.xx"上传 sudo ssh-copy-id -i /Users/xx/.ssh/id_rsa.pub root127.0.0.1...

在visio2021 中插入MathType公式

首先要确保有着两个软件&#xff0c;且能用。 1、打开visio2021&#xff0c;之后点击“插入”-“对象” 2、打开后&#xff0c;选择MathType&#xff0c;确定 3、确定后就会弹出MathType编辑器...

【计算机视觉】图像的几何变换

最常见的几何变换有仿射变换和单应性变换两种&#xff0c;最常用的仿射变换有缩放、翻转、旋转、平移。 1. 缩放 将图像放大或缩小会得到新的图像&#xff0c;但是多出的像素点如何实现----插值 1.1 插值方法 最近邻插值 双线性插值 cv2.resize() 是 OpenCV 中用于调整图像…...

IS-IS四

目录 点到点中LSP(类似LSA&#xff09;的同步过程 注意LSP只有&#xff08;1类LSA和2类LSA) 查看详细信息&#xff1a;display isis lsdb 0000.0000.0001.00-00 verbose 开摸&#xff1a; ISIS的伪节点LSP&#xff08;类似LSA&#xff09;没有路由信息 L1路由器的路由计算…...

CODA 离线安装及虚幻镜迁移

1、离线安装 1.1 下载Miniconda安装脚本 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh1.2 添加权限 chmod x Miniconda3-latest-Linux-x86_64.sh1.3 执行安装 ./Miniconda3-latest-Linux-x86_64.sh遇到问题&#xff0c;一路回车即可 1.4 …...

【Rive】混合动画

1 混合动画简介 【Rive】动画 中介绍了 Rive 中动画的基础概念和一般动画的制作流程&#xff0c;本文将介绍混合动画的基础概念和一般制作流程。Unity 中混合动画介绍详见→ 【Unity3D】动画混合。 混合动画是指同一时刻多个动画按照一定比例同时执行&#xff0c;这些动画控制的…...

软件体系结构复习-02 软件体系结构定位及构建

软件体系结构复习-02 软件体系结构定位及构建 原文链接&#xff1a;《软件体系结构复习-02 软件体系结构定位及构建》 目录 软件体系结构复习-02 软件体系结构定位及构建 1 什么是软件体系结构 2 软件生命周期中的软件体系结构 2.1 生命周期 2.2 定位与作用 1 规划和需求…...

MySQL-SQL语句

文章目录 一. SQL语句介绍二. SQL语句分类1. 数据定义语言&#xff1a;简称DDL(Data Definition Language)2. 数据操作语言&#xff1a;简称DML(Data Manipulation Language)3. 数据查询语言&#xff1a;简称DQL(Data Query Language)4. 数据控制语言&#xff1a;简称DCL(Data …...

Windows版Docker上不了网怎么办?

1、判断你的config文件、daemon文件的位置。 docker info命令输入&#xff0c; buildx: Docker Buildx (Docker Inc.) Version: v0.17.1-desktop.1 Path: C:\Users\AAA\.docker\cli-plugins\docker-buildx.exe 这个是你电脑这些文件的位置&#xff0c;修改linu…...

Zabbix监控Oracle 19c数据库完整配置指南

Zabbix监控Oracle 19c数据库完整配置指南 本文将详细介绍如何使用Zabbix配置Oracle 19c数据库监控&#xff0c;包括安装、配置、问题排查等全过程。本指南适合新手独立完成配置。 1. 环境准备 1.1 系统要求 Oracle 19c数据库服务器Zabbix服务器&#xff08;版本5.0或更高&a…...

解决 Maven 部署中的 Artifact 覆盖问题:实战经验分享20241204

&#x1f6e0;️ 解决 Maven 部署中的 Artifact 覆盖问题&#xff1a;实战经验分享 &#x1f4cc; 引言 在软件开发过程中&#xff0c;持续集成和持续部署&#xff08;CI/CD&#xff09;是提高开发效率和代码质量的关键手段。Hudson 和 Maven 是两种广泛使用的工具&#xff0…...

mb108里opengl相关

linux/linuxgdi.cpp里CreateWindowExW的 g_signal_connect(self->m_glArea, "render", G_CALLBACK(onRenderGlTextures), self); 绑定了一个渲染事件回调。 另外有 g_signal_connect(self->m_glArea, "realize", G_CALLBACK(onRealizeGlTextures)…...

使用docker让项目持续开发和部署

大多人选择开发时在本地&#xff0c;部署时文件都在容器里&#xff0c;如果没有容器&#xff0c;那就本地开发&#xff0c;没有映射文件&#xff0c;如果部署环境到容器了&#xff0c;容器内部启动时设置执行命令&#xff0c;再将映射的文件进行编译&#xff0c;这就直接能实现…...

数据结构-查找

数据结构——二叉树先序、中序、后序及层次四种遍历&#xff08;C语言版&#xff09;_中序遍历-CSDN博客...

2030. gitLab A仓同步到B仓

文章目录 1 A 仓库备份 到 B 仓库2 B 仓库修改main分支的权限 1 A 仓库备份 到 B 仓库 #!/bin/bash# 定义变量 REPO_DIR"/home/xhome/opt/git_sync/zz_xx_xx" # 替换为你的本地库A的实际路径 REMOTE_ORIGIN"http://192.168.1.66:8181/zzkj_software/zz_xx_xx.…...

Ubuntu防火墙管理(五)——ufw源规则解读与修改

firewalld与nftables 在 /etc/firewalld/firewalld.conf 文件中&#xff0c;FirewallBackend 选项用于指定 Firewalld 使用的防火墙后端实现。具体来说&#xff1a; nftables&#xff1a;这是当前的默认选项&#xff0c;表示 Firewalld 将使用 nftables 作为防火墙后端。nftab…...

Flink+Paimon实时数据湖仓实践分享

随着 Paimon 近两年的推广普及&#xff0c;使用 FlinkPaimon 构建数据湖仓的实践也越来越多。在 Flink 实时数据开发中&#xff0c;对于依赖大量状态 state 的场景&#xff0c;如长周期的累加指标计算、回撤长历史数据并更新等&#xff0c;使用实时数仓作为中间存储来代替 Flin…...

全面解析DApp开发中的智能合约设计

在DApp的开发过程中&#xff0c;智能合约的设计起到了至关重要的作用。智能合约是运行在区块链上的程序&#xff0c;负责处理和执行DApp中的逻辑、交易和数据存储。下面我们将深入探讨智能合约的设计原则、挑战和优化方法&#xff0c;帮助开发者掌握如何设计高效、安全的智能合…...

强化学习新突破:情节记忆与奖励机制引领多智能体协作

简介 本推文介绍了韩国科学技术院发表在人工智能顶会ICLR 2024上的论文《Efficient Episodic Memory Utilization of Cooperative Multi-Agent Reinforcement Learning》。该论文提出创新性高效情节记忆利用&#xff08;Efficient Episodic Memory Utilization&#xff0c;EMU…...

VUE3学习二

教程视频 【尚硅谷Vue3入门到实战&#xff0c;最新版vue3TypeScript前端开发教程】https://www.bilibili.com/video/BV1Za4y1r7KE?p67&vd_sourcef1bd3b5218c30adf0a002c8c937e0a27 零 环境搭建 学习环境 windows10node 18vue3 创建项目 npm create vuelatest 选项中…...

MySQL Group Replication

参考文档&#xff1a; https://dev.mysql.com/doc/refman/8.4/en/group-replication-configuring-instances.html MySQL版本&#xff1a; mysql> select version(); ----------- | version() | ----------- | 8.4.3 | ----------- 1 row in set (0.00 sec)mysql> …...

设计模式学习思路二

设计模式的学习思路_设计模式必须按顺序进行吗-CSDN博客 以下是一些方法和思路可以帮助你更清晰地识别使用了哪种设计模式。 1. 确定模式时的思考步骤 以下是分析代码时&#xff0c;你可以遵循的一些思路和步骤&#xff0c;帮助你识别可能使用的设计模式&#xff1a; a. 识别…...

MySql 笔记

drop database if exists school; create database school default charset utf8; -- 切换到数据库school use school; -- 创建学生表 drop table if exists tb_student; create table tb_student ( stuid int not null comment 学号, stuname varchar(20) not null comment 姓…...

【Qt】QTableView选中行发生变化时触发的信号

问题 QTableView选中的行发生变化时&#xff0c;使用的信号是QTableView的selectionModel()里的currentChanged信号&#xff0c;界面点击行来回切换&#xff0c;发现怎么也触发不了&#xff1f; 原因 信号槽连接放在了QTableView数据初始化前面&#xff0c;这时候QTableView…...

qt图像合成模式分析

文章目录 定义含义示例分析CompositionMode_ClearCompositionMode_SourceCompositionMode_DestinationCompositionMode_SourceOverCompositionMode_DestinationOverCompositionMode_SourceInCompositionMode_DestinationInCompositionMode_SourceOutCompositionMode_Destinatio…...

http与https的区别

加密方式&#xff1a; 加密技术是对信息进行编码和解码的技术&#xff0c;编码是把原来可读信息&#xff08;又称明文&#xff09;译成代码形式&#xff08;又称密文&#xff09;&#xff0c;其逆过程就是解码&#xff08;解密&#xff09;&#xff0c;加密技术的要点是加密算…...

Pyside6 --Qt Designer--Qt设计师--了解+运行ui_demo_1.py

目录 一、打开Qt设计师1.1 Terminal终端1.2 打开env&#xff0c;GUI虚拟环境下的scripts文件1.3 不常用文件介绍&#xff08;Scripts下面&#xff09; 二、了解Qt设计师的各个控件作用2.1 点击widget看看效果&#xff01;2.2 点击Main Window看看效果 三、编写一个简易的UI代码…...

11.17【大数据】Hadoop【DEBUG】

列出hdfs文件系统所有的目录和文件 主节点上 子结点 是一样的 *为什么能登进 slave 02 的主机,但是 master 当中依然显示 slave 02 为 DeadNode?* hadoop坏死节点的重启_hadoop3 子节点重启-CSDN博客 注意hadoop-daemon.sh 实际上位于 Hadoop 的 sbin 目录中&#xff0c;而不…...

MQ:kafka-消费者的三种语义

文章目录 前言(一) 创建topic(二) 生产者&#xff08;三&#xff09;消费者1. At-most-once Kafka Consumer2. At-least-once kafka consumer3. 使用subscribe实现Exactly-once4. 使用assign实现Exactly-once 前言 本文主要是以kafka 09的client为例子&#xff0c;详解kafka c…...

QT 线程锁

在 Qt 中&#xff0c;线程锁是用来同步多线程访问共享资源的机制&#xff0c;防止数据竞争和线程安全问题。Qt 提供了几种线程锁和同步工具&#xff0c;主要包括以下几种&#xff1a; 1. QMutex 功能&#xff1a;QMutex 是 Qt 中最常用的互斥锁&#xff08;mutex&#xff09;…...

C++中protobuf Message与JSON的互相转换

C中protobuf Message与JSON的互相转换 环境&#xff1a; protobuf: v27.3(2024-08-01) abseil: 20240722.0文章目录 C中protobuf Message与JSON的互相转换前言1. 编写通讯录addressbook.proto2. 编译3. C中测试protobuf与json的转换4. 结果 前言 PB转JSON&#xff1a;Protoc…...

Milvus向量数据库03-搜索理论

Milvus向量数据库03-搜索理论 1-ANN搜索 通过 k-最近邻&#xff08;kNN&#xff09;搜索可以找到一个查询向量的 k 个最近向量。kNN 算法将查询向量与向量空间中的每个向量进行比较&#xff0c;直到出现 k 个完全匹配的结果。尽管 kNN 搜索可以确保准确性&#xff0c;但十分耗…...

qt QCryptographicHash详解

1、概述 QCryptographicHash是Qt框架中提供的一个类&#xff0c;用于实现加密散列函数&#xff0c;即哈希函数。哈希函数能够将任意长度的数据转换为固定长度的哈希值&#xff0c;也称为散列值或数据指纹。这个哈希值通常用于数据的完整性校验、密码存储等场景。QCryptographi…...

【论文阅读】具身人工智能(Embodied AI)综述:连接数字与物理世界的桥梁

摘要 具身人工智能&#xff08;Embodied AI&#xff09;对于实现通用人工智能&#xff08;AGI&#xff09;至关重要&#xff0c;是连接数字世界与物理世界的各类应用的基础。近年来&#xff0c;多模态大模型&#xff08;MLMs&#xff09;和世界模型&#xff08;WMs&#xff09…...

使用el-row和el-col混合table设计栅格化,实现表头自适应宽度,表格高度占位

演示效果&#xff1a; 如上图,由于地址信息很长,需要占多个格子,所以需要错开,若想实现这种混合效果,可以这样搭建: 页面效果&#xff1a; 代码分析: 上面使用el-row和el-col搭建表单显示 第一排三个8,第二排8和16 下面混合table实现&#xff0c;并使用border来自适应宽度…...

MQ的基本概念

1 MQ的基本概念 RabbitMQ是一个开源的消息代理和队列服务器&#xff0c;它使用Erlang语言编写并运行在多种操作系统上&#xff0c;如Linux、Windows等。RabbitMQ可以接收、存储和转发消息&#xff08;也称为“事件”&#xff09;到连接的客户端。它适用于多种场景&#xff0c;…...

基于协同过滤的图书推荐系统 爬虫分析可视化【源码+文档】

【1】系统介绍 研究背景 随着互联网的普及和电子商务的发展&#xff0c;用户可以在线获取大量的图书资源。然而&#xff0c;面对海量的信息&#xff0c;用户往往难以找到自己真正感兴趣的书籍。同时&#xff0c;对于在线书店或图书馆等提供图书服务的平台来说&#xff0c;如何…...

Kruskal 算法在特定边权重条件下的性能分析及其实现

引言 Kruskal 算法是一种用于求解最小生成树(Minimum Spanning Tree, MST)的经典算法。它通过逐步添加权重最小的边来构建最小生成树,同时确保不会形成环路。在本文中,我们将探讨在特定边权重条件下 Kruskal 算法的性能,并分别给出伪代码和 C 语言实现。特别是,我们将分…...

【Pandas】pandas from_dummies

Pandas2.2 General Data manipulations 方法描述melt(frame[, id_vars, value_vars, var_name, …])将多个列的值转换为行形式pivot(data, *, columns[, index, values])将长格式的数据转化为宽格式pivot_table(data[, values, index, columns, …])用于创建数据透视表&#…...

【信息系统项目管理师】第8章:项目整合管理过程详解

文章目录 一、制定项目章程1、输入2、工具和技术3、输出 二、制订项目管理计划1、输入2、工具和技术3、输出 三、指导与管理项目工作1、输入2、工具和技术3、输出 四、管理项目知识1、输入2、工具和技术3、输出 五、监控项目工作1、输入2、工具和技术3、输出 六、实施整体变更控…...

从变更到通知:使用Python和MongoDB Change Streams实现即时事件监听

MongoDB提供了一种强大的功能&#xff0c;称为Change Streams&#xff0c;它允许应用程序监听数据库中的变更事件&#xff0c;并在数据发生变化时立即做出响应。这在mysql数据库是不具备没有这个功能的。又如&#xff1a;我们在支付环节想一直监听支付回调的状态&#xff0c;就…...

vue3+elementPlus封装的数据过滤区

目录结构 源码 index.vue <template><el-form class"mb-5" :rules"rules" :model"queryForm" ref"queryDOM" label-width"80"><el-row :gutter"20"><slot></slot><el-col cla…...

PHP RabbitMQ连接超时问题

问题背景 Error: The connection timed out after 3 sec while awaiting incoming data 看到这个报错&#xff0c;我不以为意&#xff0c;认为是我设置的超时时间不够导致的&#xff0c;那就设置长一点 Error: The connection timed out after 300 sec while awaiting incom…...