File size: 1,744 Bytes
f57e879
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# SPDX-FileCopyrightText: © 2026 Tenstorrent AI ULC
# SPDX-License-Identifier: Apache-2.0

from models.common.models import executor as executor_module


def test_easy_trace_prefill_replay_copies_only_mutable_inputs(monkeypatch):
    engine = executor_module.TracedLLMExecutor.__new__(executor_module.TracedLLMExecutor)
    engine.mesh_device = "mesh"
    engine.trace_id_prefill = {128: 7}
    engine.trace_inputs_prefill = {
        128: ("device_tokens", "device_cos", "device_sin", "device_page_table", None),
    }
    engine.trace_output_prefill = {128: "trace_output"}

    monkeypatch.setattr(
        engine,
        "_prepare_prefill_trace_inputs_host",
        lambda tokens, page_table, last_token_idx: (
            "host_tokens",
            "device_cos_slice",
            "device_sin_slice",
            "host_page_table",
            None,
        ),
    )

    copy_calls = []
    monkeypatch.setattr(
        executor_module,
        "copy_host_to_device",
        lambda host_tensors, device_tensors: copy_calls.append((host_tensors, device_tensors)),
    )

    execute_calls = []
    monkeypatch.setattr(
        executor_module.ttnn,
        "execute_trace",
        lambda mesh_device, trace_id, cq_id, blocking: execute_calls.append((mesh_device, trace_id, cq_id, blocking)),
    )

    result = engine._easy_trace_prefill(
        tokens="tokens",
        page_table="page_table",
        user_id=0,
        last_token_idx=127,
        prefill_seq_len=128,
    )

    assert result == "trace_output"
    assert copy_calls == [
        (
            ("host_tokens", "host_page_table", None),
            ("device_tokens", "device_page_table", None),
        )
    ]
    assert execute_calls == [("mesh", 7, 0, False)]