Implement a bottleneck adapter module: a small residual block inserted into a frozen transformer that down-projects to a low dimension, applies a non-linearity, and up-projects back.
Signature: def adapter_forward(x: np.ndarray, W_down: np.ndarray, W_up: np.ndarray) -> np.ndarray
Shapes:
x: (batch, d)W_down: (bottleneck, d)W_up: (d, bottleneck)Returns: an array with the same shape as x. The block down-projects x with W_down, applies a ReLU, up-projects with W_up, and adds the residual x.
Math
Asked at
import numpy as np
def adapter_forward(...):
pass
Premium problem
Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.
Already premium?