Implement LoRA (low-rank adaptation) as an ML coding exercise. Asked in the Tech screen stage for an NLP/LM research engineer team, followed by basic ML questions and resume project discussion.
Implement lora_forward(x, W, A, B, alpha), where x is [batch, in_features], W is [in_features, out_features], A is [in_features, rank], and B is [rank, out_features]. Return xW + (alpha / rank)xAB as a nested list. Do not use NumPy or other matrix libraries.
Constraints: all dimensions are positive, rank <= in_features, and values are finite numbers.
def lora_forward(x, W, A, B, alpha):