Implement a transformer block from scratch in PyTorch.
Implement the forward pass for a batch-first transformer block with multi-head self-attention, scaled dot-product attention, residual connections, layer normalization, and a two-layer feed-forward network. For grading, represent x as a nested Python list with shape [batch_size][sequence_length][d_model]; return a nested list with the same shape. Use dropout = 0 for deterministic execution. The reference implementation uses identity projections to keep the standard-library test harness deterministic.
def transformer_block(x, d_model, num_heads, d_ff, dropout):