Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Attention-Free Transformer in PyTorch

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Attention-Free Transformer in PyTorch. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Implement a custom Attention-Free Transformer module in PyTorch based on a provided formula (where Q is used as a gating mechanism rather than query, K and a trainable positional embedding act as logits for softmax).

Asked in the Technical Coding Round stage. AI autocomplete tools were disabled, and the code did not need to run fully, but the logic and structure needed to look reasonable. Reported follow-ups: how would you extend this implementation to multi-head, and how can you debottleneck this and reduce the computational complexity to linear, similar to Linear Attention?

Output

Return the module output tensor shape and the per-layer parameter audit in the required order.

Schema

transformer_layers
ColumnTypeDescription
layer_idPKINTUnique layer identifier
layer_nameVARCHAR(100)Transformer layer name
parameter_nameVARCHAR(100)Parameter name within the layer
is_trainableBOOLEANWhether the parameter is trainable
module_outputs
ColumnTypeDescription
output_idPKINTUnique output record identifier
module_nameVARCHAR(100)Module name
layer_nameVARCHAR(100)Layer name referenced by the output
output_shapeVARCHAR(50)Tensor output shape
Tablestransformer_layersmodule_outputs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results