KatInterview

Loss Function Optimization Dynamics and Mechanics of LoRA

Machine LearningModel answer
MediumModel answerMachine Learningloss-functionsoptimizationlora

Last updated

Evaluate MSE vs. Cross-Entropy using likelihood assumptions and logit gradients, then detail LoRA implementation, parameter counting, memory trade-offs, and failure modes.

This conceptual screening assesses your technical depth in objective function design and parameter-efficient fine-tuning (PEFT) for large neural architectures.


Part 1: Loss Functions (MSE vs. Cross-Entropy)

Provide a thorough analysis comparing Mean Squared Error (MSE) and Cross-Entropy (CE):

  1. Task Domain & Likelihood Assumptions: Identify the natural problem settings for both loss functions. Formalize their probabilistic interpretation under Maximum Likelihood Estimation (MLE), detailing the specific output probability distributions and noise assumptions implied by each objective.
  2. Gradient Dynamics & Saturation: For a binary classification setup where the network outputs a probability $\hat{y} = \sigma(z)$ via a sigmoid activation applied to logit $z$, derive the partial derivatives $\frac{\partial \mathcal{L}{\text{MSE}}}{\partial z}$ and $\frac{\partial \mathcal{L}{\text{CE}}}{\partial z}$. Contrast their behavior on a "confidently wrong" prediction (i.e., when $y = 1$ but $\hat{y} \to 0$).
  3. Optimization Topology: Explain how activation functions alter the convexity of the loss surface for each loss when optimizing parameters $w$ of a linear projection $z = w^\top x$.

Part 2: Low-Rank Adaptation (LoRA)

Explain the structural design and operational behavior of Low-Rank Adaptation (LoRA):

  1. Mathematical Parameterization & Initialization: Write the equation defining the modified forward pass for a frozen linear layer $W_0 \in \mathbb{R}^{d \times k}$ adapted by low-rank matrices $A$ and $B$ under rank $r \ll \min(d, k)$. Explain the role of the hyperparameter scale factor $\frac{\alpha}{r}$ and why specific initialization choices for $A$ and $B$ are required at step 0.
  2. Parameter Reduction: Calculate the exact count of trainable parameters for full fine-tuning versus LoRA fine-tuning ($r=8$) on a single linear weight matrix of dimension $4096 \times 4096$. Express the reduction as a ratio.
  3. Memory footprint during training: Explain why reducing trainable parameter count lowers VRAM consumption during training. Contrast the reduction in optimizer state overhead with the behavior of activation memory.
  4. Deployment & Limitations: Contrast the deployment approaches of weight merging versus maintaining distinct adapter modules for multi-tenant inference. Describe failure modes where low-rank adaptation underperforms full parameter fine-tuning.

Hints

Hint 1

Recall that MSE corresponds to maximum likelihood estimation under a Gaussian error model, whereas Cross-Entropy corresponds to a Bernoulli/Categorical likelihood.

Hint 2

Compute dL/dz using the chain rule for sigmoid derivative: dσ(z)/dz = σ(z)(1 - σ(z)). Look at what happens to the error term in both losses when σ(z) approaches 0 for y = 1.

Hint 3

Consider how LoRA initializations affect the initial output step-zero state ΔW = B * A, and why zeroing both matrices simultaneously would break backpropagation.