async def test_tdb_request_vs_transformer(
    standard_model_context: StandardModelContext,
) -> None:
    """
    Test that the top and bottom output token logits returned by a BatchedTdbRequest
    match those straightforwardly output by the Transformer. Also test that the top
    MLP activation returned by the BatchedTdbRequest matches the activation value stored
    using a hook on the Transformer forward pass directly.
    This test compares the simplest way to get outputs and activations from a Transformer, with the
    way that is used in TDB.
    """
    transformer = standard_model_context.get_or_create_model()

    prompt = "This is a test"
    input_token_ints = torch.tensor(
        standard_model_context.encode(prompt), device=standard_model_context.device
    ).unsqueeze(0)
    logits, _ = transformer(input_token_ints)
    # these are the logits for the next token in the sequence, directly from the Transformer
    logits = logits[0, -1, : standard_model_context.n_vocab]

    tdb_request = TdbRequestSpec(
        prompt=prompt,
        target_tokens=["."],
        distractor_tokens=["!"],
        component_type_for_mlp=ComponentTypeForMlp.NEURON,
        component_type_for_attention=ComponentTypeForAttention.ATTENTION_HEAD,
        top_and_bottom_k_for_node_table=5,
        hide_early_layers_when_ablating=False,
        node_ablations=None,
        upstream_node_to_trace=None,
        downstream_node_to_trace=None,
    )
    batched_tdb_request = BatchedTdbRequest(sub_requests=[tdb_request])

    interactive_model = InteractiveModel.from_standard_model_context(standard_model_context)

    batched_tdb_response = await interactive_model.handle_batched_tdb_request(batched_tdb_request)

    output_token_logits_response = batched_tdb_response.inference_sub_responses[
        0
    ].processing_response_data_by_name["topOutputTokenLogits"]
    assert isinstance(output_token_logits_response, MultipleTopKDerivedScalarsResponseData)
    logit_activations = output_token_logits_response.activations_by_group_id[GroupId.LOGITS]
    logit_indices = output_token_logits_response.node_indices
    # these are activations and NodeIndex objects associated with the top and bottom predicted
    # tokens for the next token in the sequence

    vocab_token_indices = [index.tensor_indices[1] for index in logit_indices]
    top_k_logits = len(vocab_token_indices) // 2
    # first half are largest
    assert logits.topk(top_k_logits).indices.tolist() == vocab_token_indices[:top_k_logits]
    assert logits.topk(top_k_logits).values.tolist() == logit_activations[:top_k_logits]
    # second half are smallest
    assert (
        logits.topk(top_k_logits, largest=False).indices.tolist()
        == vocab_token_indices[-top_k_logits:][::-1]
    )
    assert (
        logits.topk(top_k_logits, largest=False).values.tolist()
        == logit_activations[-top_k_logits:][::-1]
    )

    top_k_components_response = batched_tdb_response.inference_sub_responses[
        0
    ].processing_response_data_by_name["topKComponents"]
    assert isinstance(top_k_components_response, MultipleTopKDerivedScalarsResponseData)
    top_node_indices = top_k_components_response.node_indices
    top_activations = top_k_components_response.activations_by_group_id[GroupId.ACTIVATION]

    mlp_neuron_index, mlp_activation = next(
        (
            (node_index, activation)
            for node_index, activation in zip(top_node_indices, top_activations)
            if node_index.node_type == NodeType.MLP_NEURON
        ),
        (None, None),
    )  # get the first MLP neuron index returned by the TDB request
    assert mlp_neuron_index is not None

    hooks = TransformerHooks()
    stored_activation = {}

    def saving_hook_fn(act: torch.Tensor, **kwargs: Any) -> torch.Tensor:
        stored_activation["act"] = act[
            (0,) + mlp_neuron_index.tensor_indices
        ].item()  # 0 batch index
        return act  # store the activation value for the MLP neuron in question

    hooks.append_to_path(
        "mlp.post_act.fwd",
        AtLayers([assert_not_none(mlp_neuron_index.layer_index)]).append(saving_hook_fn),
    )

    transformer(input_token_ints, hooks=hooks)

    # the hook should have populated the dict with the MLP neuron's activation value
    assert stored_activation["act"] == mlp_activation

    Test that the top and bottom output token logits returned by a BatchedTdbRequest
    match those straightforwardly output by the Transformer. Also test that the top
    MLP activation returned by the BatchedTdbRequest matches the activation value stored
    using a hook on the Transformer forward pass directly.
    This test compares the simplest way to get outputs and activations from a Transformer, with the
    way that is used in TDB.
    
neuron_explainer/tests/test_interactive_model.py