#64Sequential steps — serial vs parallelEasyTransformersRNN
Sequential steps — serial vs parallel
Background
RNNs are inherently serial along time: computing position requires position to be done, so a length- sequence needs sequential steps. Attention computes all positions in one big parallel operation, so its sequential depth is — which is exactly why it saturates GPUs.
Problem statement
Implement sequential_steps(seq_len, arch) returning the number of sequential (non-parallelizable) steps to process the sequence.
Input
seq_len—int, sequence length .arch—"rnn"or"attention".
Output
Returns an int: seq_len for "rnn", 1 for "attention".
Examples
Example 1
Input: seq_len = 100, arch = "rnn"
Output: 100
Example 2
Input: seq_len = 100, arch = "attention"
Output: 1
Constraints
"rnn"→seq_len;"attention"→1.- Return a plain
int.
Notes
- Fewer sequential steps means more work can run in parallel on a GPU — the throughput advantage that let transformers scale.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example 1 - RNN needs T sequential steps
- •Reference - attention is a single parallel step
- •Sample - short RNN sequence