Pulls a single (layer, component) slice out of a llm_trace() result as a
base numeric matrix: one row per captured (prompt_id, token_pos) and one
column per neuron (hidden_size wide). Row names are "<prompt_id>.<token_pos>".
This is the bridge from the long-format trace to matrix tools such as
stats::prcomp().
Usage
# S3 method for class 'relm_trace'
as.matrix(x, layer, component = "residual", ...)Arguments
- x
A
relm_tracefromllm_trace().- layer
Required single 1-based layer index; it must be present in the trace.
- component
Single component name (default
"residual"); it must be present in the trace.- ...
Ignored.
Value
A numeric matrix, rows = captured (prompt_id, token_pos) (row names
"<prompt_id>.<token_pos>"), columns = neurons.
Examples
if (FALSE) { # nzchar(Sys.getenv("RELM_TEST_MODEL_QWEN"))
m <- llm(Sys.getenv("RELM_TEST_MODEL_QWEN"))
tr <- llm_trace(m, "The cat sat.", layers = 1:2)
as.matrix(tr, layer = 1, component = "residual")
close(m)
}