LoRA 与 QLoRA
LoRA LoRA (Low-Rank Adaptation): 保留原来的权重, 只学习一个由两个小矩阵表示的更新量. 令 $y = W_0x$. Fine-tuning (FT) 时, 将权重 $W_0$ 更新为 $W_0 + \Delta W$, 其中: $$ \Delta W = sBA. $$...
LoRA LoRA (Low-Rank Adaptation): 保留原来的权重, 只学习一个由两个小矩阵表示的更新量. 令 $y = W_0x$. Fine-tuning (FT) 时, 将权重 $W_0$ 更新为 $W_0 + \Delta W$, 其中: $$ \Delta W = sBA. $$...
并行理论的黑称 Vertical Split: 竖切, PP Horizontal Split: 横切, TP 消耗显存的模块分类 Part Category Included Items Description 1 Model states optimizer states, gradients, parameters For large models, the majority of the memory is occupied by model states. 2 Residual states activation, temporary buffers, unusable fragmented memory The remaining memory is consumed by residual states. Model State 不足分析 + ZeRO-DP 性能 Parallelism Method Why Compute Efficiency Is High / Low Why Memory Efficiency Is High / Low Core Mechanism Main Problem Data Parallelism (DP) High compute efficiency because each GPU runs the full model independently on its own mini-batch, so computation is large-grained and continuous, and communication is mainly limited to gradient synchronization. Low memory efficiency because each GPU stores a full copy of all model states, including parameters, gradients, and optimizer states. Replicate the full model on every GPU, split data across GPUs, then synchronize gradients. Heavy memory redundancy across GPUs. Model Parallelism (MP) Low compute efficiency because one model computation is split across multiple GPUs, which introduces fine-grained coordination, frequent synchronization, and expensive communication on the critical path. High memory efficiency because each GPU stores only a partition of the model states instead of the full model. Partition the model itself across GPUs so each GPU holds only part of the parameters / states. Communication overhead, synchronization cost, and reduced scalability. ZeRO-DP Tries to retain the high compute efficiency of DP by preserving DP-style computation granularity and communication pattern as much as possible. Tries to achieve the high memory efficiency of MP by partitioning model states across data-parallel processes instead of fully replicating them. Keep DP-style training flow, but partition optimizer states, gradients, and eventually parameters to remove redundancy. More complex state management and dynamic communication scheduling. ...
Attention 计算的线性代数问题 attention 和 FFN 的关系 如果记某层输入为 x, 那么可以粗略理解成: attention 输出: 给 x 补充上下文信息, 像"开会听别人说话" FFN 输出: 给 x 补充局部计算后的新特征, - 像"你自己在脑子里消化, 归纳, 形成判断" 如果我们尝试把一个 FFN 层变成一个 attention 层, 结果就是可能会更加适合长距离语义传输但是缺少本地语义特征变换器 多层 attention-FFN 结构 可以理解为不断重复"交换信息 $\rightarrow$ 消化信息 $\rightarrow$ 再交换 $\rightarrow$ 再消化" 也就是说各自对本 token 处于上下文的含义理解之后再次进行交换分享,让整体的文意理解更加深刻 ...
神经网络基础 如图是一个基础的神经网络结构, 我们这里首先要明确几个函数: 每一层内部的计算是 $h_i := \sigma(z_i)$, $z_i := W_i h_{i-1} + b_i$ 我们最终的输出函数是 $L :=$loss(sample; forward) forward: 指的是从输入样本数据 $h_0$ 到 最终输出 $\sigma(z_2)$ 的所有计算过程 backward: 从 $L$ 开始不断计算每一层中的 $\frac{\partial L}{\partial W_i}$ 和 $\frac{\partial L}{\partial b_i}$ 的方向梯度, 然后用这个来不断更新 $W_i,\ b_i$ 现在来拆解一下反向传播的过程: 基本根据的是莱布尼茨链式法则 (chain-rule) ...
DDP 是什么 DDP(Distributed Data Parallel)是 PyTorch 官方提供的分布式数据并行训练机制; 它的核心思想是: 让多个训练进程各自持有同一个模型的副本, 分别处理不同的数据子集, 并在反向传播阶段自动同步梯度, 从而保持所有模型副本的一致更新; DDP 要解决什么问题 深度学习训练通常面临两个核心限制: ...