async def test_tdb_request_with_autoencoder_vs_transformer(
    standard_model_context: StandardModelContext,
    standard_autoencoder_context: AutoencoderContext,
) -> None:
    """
    Test that the top MLP autoencoder latent 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 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)

    tdb_request = TdbRequestSpec(
        prompt=prompt,
        target_tokens=["."],
        distractor_tokens=["!"],
        component_type_for_mlp=ComponentTypeForMlp.AUTOENCODER_LATENT,
        component_type_for_attention=ComponentTypeForAttention.ATTENTION_HEAD,
        top_and_bottom_k_for_node_table=15,
        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_and_autoencoder_context(
        standard_model_context, standard_autoencoder_context
    )

    batched_tdb_response = await interactive_model.handle_batched_tdb_request(batched_tdb_request)

    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]
    ae_index, ae_activation = next(
        (
            (node_index, activation)
            for node_index, activation in zip(top_node_indices, top_activations)
            if node_index.node_type == NodeType.MLP_AUTOENCODER_LATENT
        ),
        (None, None),
    )  # get the first latent index returned by the TDB request
    assert ae_index is not None

    hooks = TransformerHooks()
    stored_activation = {}

    def saving_hook_fn(act: torch.Tensor, **kwargs: Any) -> torch.Tensor:
        stored_activation["act"] = act[
            (0,) + ae_index.tensor_indices[0:1]
        ]  # 0 batch index, keep token index from ae_index
        return act  # store the activation value for the latent in question

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

    transformer(input_token_ints, hooks=hooks)

    autoencoder = standard_autoencoder_context.get_autoencoder(ae_index.layer_index)

    # the hook should have populated the dict with the latent's activation value
    assert ae_activation is not None
    assert math.isclose(
        autoencoder.encode(stored_activation["act"])[ae_index.tensor_indices[-1]],
        ae_activation,
        rel_tol=1e-4,
    )

    Test that the top MLP autoencoder latent 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 activations from a Transformer, with the way that is
    used in TDB.
    
neuron_explainer/tests/test_interactive_model.py