Mixed-precision计算原理(FP32+FP16)
原文:
https://lightning.ai/pages/community/tutorial/accelerating-large-language-models-with-mixed-precision-techniques/
This approach allows for efficient training while maintaining the accuracy and stability of the neural network.
In more detail, the steps are as follows.
- Convert weights to FP16: In this step, the weights (or parameters) of the neural network, which are initially in FP32 format, are converted to lower-precision FP16 format. This reduces the memory footprint and allows for faster computation, as FP16 operations require less memory and can be processed more quickly by the hardware.
- Compute gradients: The forward and backward passes of the neural network are performed using the lower-precision FP16 weights. This step calculates the gradients (partial derivatives) of the loss function with respect to the network’s weights, which are used to update the weights during the optimization process.
- Convert gradients to FP32: After computing the gradients in FP16, they are converted back to the higher-precision FP32 format. This conversion is essential for maintaining numerical stability and avoiding issues such as vanishing or exploding gradients that can occur when using lower-precision arithmetic.
- Multiply by learning rate and update weights: Now in FP32 format, the gradients are multiplied by a learning rate (a scalar value that determines the step size during optimization).
- The product from step 4 is then used to update the original FP32 neural network weights. The learning rate helps control the convergence of the optimization process and is crucial for achieving good performance.
简而言之:
g * lr + w老 --> w新,这里的g、w老、w新,都是FP32的;
其余计算梯度中的w、activation、gradient等,全部都是FP16的;
训练效果:
耗时缩减为FP32的1/2 ~ 1/3
显存变化不大(因为,增加显存:weight多专一份FP16,减少显存:forward时保存的activation变成FP16了,二者基本抵消)
推理效果:
显存减少一半;耗时缩减为FP32的1/2;
使用FP16后的test accuracy反而上升,解释:(正则效应,带来噪音,帮助模型泛化得更好,减少过拟合)
A likely explanation is that this is due to regularizing effects of using a lower precision. Lower precision may introduce some level of noise in the training process, which can help the model generalize better and reduce overfitting, potentially leading to higher accuracy on the validation and test sets.
bf16,指数位增加,所以能覆盖更大的数值范围,所以能使训练过程更鲁棒,减少overflow和underflow的出现概率;
相关文章:

Mixed-precision计算原理(FP32+FP16)
原文: https://lightning.ai/pages/community/tutorial/accelerating-large-language-models-with-mixed-precision-techniques/ This approach allows for efficient training while maintaining the accuracy and stability of the neural network. In more det…...
Go 控制协程(goroutine)的并发数量
在使用协程并发处理某些任务时, 其并发数量往往因为各种因素的限制不能无限的增大. 例如网络请求、数据库查询等等。 从运行效率角度考虑,在相关服务可以负载的前提下(限制最大并发数),尽可能高的并发。 在Go语言中,…...
web安全渗透测试十大常规项(一):web渗透测试之CSRF跨站请求伪造
渗透测试之CSRF跨站请求伪造 CSRF跨站请求伪造 CSRF跨站请求伪造...

YOLOv10尝鲜测试五分钟极简配置
最近清华大学团队又推出YOLOv10,真是好家伙了。 安装: pip install supervision githttps://github.com/THU-MIG/yolov10.git下载权重:https://github.com/THU-MIG/yolov10/releases/download/v1.0/yolov10n.pt 预测: from ult…...

社交媒体数据恢复:聊天宝
请注意,本教程仅针对聊天宝应用程序,而非其他聊天软件。以下是详细的步骤: 首先,请确保您已经登录了聊天宝应用程序。如果您尚未登录,请使用您的账号登录。 在聊天宝主界面,找到您希望恢复聊天记录的对话框…...

备战秋招—模拟版图面试题来了
随着暑期的脚步逐渐临近,电子工程和集成电路设计领域的毕业生们,也将迎来了另一个求职的黄金期——秋招。我们总说机会是留给有准备的人。对于有志于投身于模拟版图设计的学子们来说,为了在众多求职者中脱颖而出,充分备战模拟版图…...

CAN总线简介
1. CAN总线概述 1.1 CAN定义与历史背景 CAN,全称为Controller Area Network,是一种基于消息广播的串行通信协议。它最初由德国Bosch公司在1983年为汽车行业开发,目的是实现汽车内部电子控制单元(ECUs)之间的可靠通信。…...
【HSQL001】HiveSQL内置函数手册总结(更新中)
1.熟悉、梳理、总结下Hive SQL相关知识体系。 2.日常研发过程中使用较少,随着时间的推移,很快就忘得一干二净,所以梳理总结下,以备日常使用参考 3.欢迎批评指正,跪谢一键三连! 文章目录 1.函数清单 1.函数清…...

Rust面试宝典第14题:旋转数组
题目 给定一个数组,将数组中的元素向右移动k个位置,其中k是非负数。要求如下: (1)尽可能想出更多的解决方案,至少有三种不同的方法可以解决这个问题。 (2)使用时间复杂度为O(n)和空间…...

解决SpringBoot中插入汉字变成?(一秒解决)
在这里url后面加一行配置即可&useUnicodetrue&characterEncodingUTF-8即可 解释 spring.datasource.url: 这里包含了数据库的URL,以及额外的参数如useUnicodetrue用于启用Unicode字符集支持,characterEncodingUTF-8用于指定字符编码为UTF-8&…...

5.26牛客循环结构
1002. 难点: 两层循环条件设置 思路 可以设置三个变量 代码 1003 思路: 与星号双塔差不多,在此基础上加大一点难度 每日练题5.23 (EOF用法)-CSDN博客 代码 1004 代码...

AIGC 004-T2I-adapter另外一种支持多条件组合控制的文生图方案!
AIGC 004-T2I-adapter另外一种支持多条件组合控制的文生图方案! 文章目录 0 论文工作1 论文方法2 效果 0 论文工作 T2I-Adapter 论文提出了一种名为 T2I-Adapter 的轻量级适配器模块,旨在增强文本到图像 (T2I) 扩散模型的语义理解和生成能力。 论文指出…...

详解 Cookies 和 WebStorage
Cookies 和 WebStorage Cookies 和 WebStorageCookies简要介绍操作 Cookies(document.cookie)不足之处 WebStorage简要介绍LocalStorage Vs. SessionStorage操作 WebStorage 三种数据存储方式的对比分析共性差异 REFERENCES Cookies 和 WebStorage Cook…...
BeanFactory、FactroyBean、ApplicationContext
BeanFactory Ioc容器、定义接口规范来管理spring bean的生命周期、依赖、注入,spring中有各种Ioc容器 FactroyBean 定制的工厂Bean,可以通过抽象工厂方式创建的bean,不纳入spring的生命周期、依赖、注入特性,相当于spring给第三…...

【计算机网络】HTTPS 协议原理
加密 1. 加密概念 加密就是把明文 (要传输的信息)进行一系列变换,生成密文。 解密就是把密文再进行一系列变换,还原成明文。 在这个加密和解密的过程中,往往需要⼀个或者多个中间的数据,辅助进行这个过程,这样的数…...
springboot + Vue前后端项目(第十二记)
项目实战第十二记 1.写在前面2. 整合Echarts2.1 vue安装Echarts2.2 使用Echarts2.3 EchartsController编写2.4 Home.vue编写 总结写在最后 1.写在前面 本篇主要讲解系统整合Echarts 2. 整合Echarts 2.1 vue安装Echarts npm i echarts -S2.2 使用Echarts vue中使用echarts的…...

linux 常用命令:find grep ps netstat sudo df du rm
rm 命令 删除 -r 是递归参数(recursive),用于删除目录及其内容。如果不加这个参数,rm 命令无法删除非空目录。-f 是强制参数(force),用于强制删除文件或目录,不会进行任何确认提示…...

SQLiteOpenHelper数据库帮助器
SQLiteOpenHelper数据库帮助器是Android提供的数据库辅助工具。 1、继承SQLiteOpenHelper类,需要重写onCreate和onUpgrade两个方法 案例:实现增删改查 package com.example.databases_text;import android.app.PictureInPictureParams; import androi…...

2024年5月26日 (周日) 叶子游戏新闻
资深开发者:3A游戏当前处于一种尴尬的中间地带游戏行业整体,尤其是3A游戏正处于艰难时期。尽管2023年3A游戏佳作频出,广受好评,但居高不下的游戏开发成本(传闻《漫威蜘蛛侠2》的制作成本高达3亿美元)正严重…...

STM32-10-定时器
STM32-01-认识单片机 STM32-02-基础知识 STM32-03-HAL库 STM32-04-时钟树 STM32-05-SYSTEM文件夹 STM32-06-GPIO STM32-07-外部中断 STM32-08-串口 STM32-09-IWDG和WWDG 文章目录 一、STM32 基础定时器1. 基本定时器简介2. 基本定时器框图3. 基本定时器相关寄存器4. 定时器溢出…...

智慧医疗能源事业线深度画像分析(上)
引言 医疗行业作为现代社会的关键基础设施,其能源消耗与环境影响正日益受到关注。随着全球"双碳"目标的推进和可持续发展理念的深入,智慧医疗能源事业线应运而生,致力于通过创新技术与管理方案,重构医疗领域的能源使用模式。这一事业线融合了能源管理、可持续发…...

Vue3 + Element Plus + TypeScript中el-transfer穿梭框组件使用详解及示例
使用详解 Element Plus 的 el-transfer 组件是一个强大的穿梭框组件,常用于在两个集合之间进行数据转移,如权限分配、数据选择等场景。下面我将详细介绍其用法并提供一个完整示例。 核心特性与用法 基本属性 v-model:绑定右侧列表的值&…...
在rocky linux 9.5上在线安装 docker
前面是指南,后面是日志 sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo dnf install docker-ce docker-ce-cli containerd.io -y docker version sudo systemctl start docker sudo systemctl status docker …...

并发编程 - go版
1.并发编程基础概念 进程和线程 A. 进程是程序在操作系统中的一次执行过程,系统进行资源分配和调度的一个独立单位。B. 线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位。C.一个进程可以创建和撤销多个线程;同一个进程中…...
省略号和可变参数模板
本文主要介绍如何展开可变参数的参数包 1.C语言的va_list展开可变参数 #include <iostream> #include <cstdarg>void printNumbers(int count, ...) {// 声明va_list类型的变量va_list args;// 使用va_start将可变参数写入变量argsva_start(args, count);for (in…...

android RelativeLayout布局
<?xml version"1.0" encoding"utf-8"?> <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"android:layout_height"match_parent"android:gravity&…...
【前端异常】JavaScript错误处理:分析 Uncaught (in promise) error
在前端开发中,JavaScript 异常是不可避免的。随着现代前端应用越来越多地使用异步操作(如 Promise、async/await 等),开发者常常会遇到 Uncaught (in promise) error 错误。这个错误是由于未正确处理 Promise 的拒绝(r…...
go 里面的指针
指针 在 Go 中,指针(pointer)是一个变量的内存地址,就像 C 语言那样: a : 10 p : &a // p 是一个指向 a 的指针 fmt.Println(*p) // 输出 10,通过指针解引用• &a 表示获取变量 a 的地址 p 表示…...

GraphQL 实战篇:Apollo Client 配置与缓存
GraphQL 实战篇:Apollo Client 配置与缓存 上一篇:GraphQL 入门篇:基础查询语法 依旧和上一篇的笔记一样,主实操,没啥过多的细节讲解,代码具体在: https://github.com/GoldenaArcher/graphql…...
CppCon 2015 学习:Time Programming Fundamentals
Civil Time 公历时间 特点: 共 6 个字段: Year(年)Month(月)Day(日)Hour(小时)Minute(分钟)Second(秒) 表示…...