Admittedly, this stack trace is somewhat involved, with magic happening in a few frames.
I was hoping to be able to hide reticulate internal frames from the traceback we present by default.
Attached is an rds of the actual trace giving the error (ignore the .zip extension, that's just so github lets me upload the file).
# r_trace <- readRDS("trace.rds.zip")
> print(r_trace, drop = TRUE)
Error in `$<-.data.frame`:
! replacement has 21 rows, data has 16
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `$<-.data.frame`:
! replacement has 21 rows, data has 16
---
Backtrace:
▆
1. ├─base::print(r_trace, drop = TRUE)
2. └─rlang:::print.rlang_trace(r_trace, drop = TRUE)
3. ├─rlang:::cat_line(...)
4. │ ├─base::cat(paste_line(..., .trailing = .trailing), file = file)
5. │ └─rlang:::paste_line(..., .trailing = .trailing)
6. │ └─rlang::chr(...)
7. │ └─rlang::dots_values(...)
8. ├─base::format(...)
9. └─rlang:::format.rlang_trace(...)
10. └─rlang:::trace_format(...)
11. └─rlang:::trace_as_tree(trace, dir = dir, srcrefs = srcrefs, drop = drop)
12. ├─base::`$<-`(`*tmp*`, "node_type", value = `<chr>`)
13. └─base::`$<-.data.frame`(`*tmp*`, "node_type", value = `<chr>`)
drop = FALSE prints fine:
> print(r_trace)
▆
1. ├─base::source("~/github/t-kalinowski/llama-keras/load-tf-llama.R")
2. │ ├─base::withVisible(eval(ei, envir))
3. │ └─base::eval(ei, envir)
4. │ └─base::eval(ei, envir)
5. ├─keras (local) Transformer(model_args) at t-kalinowski/llama-keras/load-tf-llama.R:54:2
6. │ └─reticulate::py_call(callable, ...) at keras/R/py-classes.R:515:4
7. │ └─reticulate:::py_call_impl(x, dots$unnamed, dots$named) at reticulate/R/python.R:869:2
8. └─reticulate:::call_r_func(`<initialize>`, `<list>`, `<named list>`) at reticulate/R/RcppExports.R:158:4
9. ├─base::withRestarts(...) at reticulate/R/utils.R:9:2
10. │ └─base (local) withOneRestart(expr, restarts[[1L]])
11. │ └─base (local) doWithOneRestart(return(expr), restart)
12. ├─base::withCallingHandlers(...) at reticulate/R/utils.R:9:2
13. ├─base::do.call(fn, c(args, named_args)) at reticulate/R/utils.R:9:2
14. └─`<initialize>`(`<Transformer>`, `<pairlist>`)
15. └─precompute_freqs_cis(...) at t-kalinowski/llama-keras/llama.R:325:4
16. ├─tf$linalg$matmul(...) at t-kalinowski/llama-keras/llama.R:90:2
17. │ ├─reticulate:::split_named_unnamed(eval(cl, parent.frame())) at reticulate/R/python.R:1369:4
18. │ └─base::eval(cl, parent.frame()) at reticulate/R/python.R:1384:2
19. │ └─base::eval(cl, parent.frame())
20. ├─rlang (local) `<fn>`(tf$expand_dims(t, -1), tf$expand_dims(freqs, 0))
21. └─tf$expand_dims(t, -1)
22. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named) at reticulate/R/python.R:1370:4
> r_trace2 %>%
+ as_tibble() %>%
+ mutate(call2 = sapply(call, deparse1)) %>%
+ print(n = Inf)
# A tibble: 22 × 6
call parent visible namespace scope call2
<list> <int> <lgl> <chr> <chr> <chr>
1 <language> 0 TRUE base :: "source(\"~/github/t-kalinowski/llama-keras/load-tf-llama.R\")"
2 <language> 1 TRUE base :: "withVisible(eval(ei, envir))"
3 <language> 1 TRUE base :: "eval(ei, envir)"
4 <language> 3 TRUE base :: "eval(ei, envir)"
5 <language> 0 TRUE keras local "Transformer(model_args)"
6 <language> 5 TRUE reticulate :: "py_call(callable, ...)"
7 <language> 6 FALSE reticulate ::: "py_call_impl(x, dots$unnamed, dots$named)"
8 <language> 0 TRUE reticulate ::: "call_r_func(`<initialize>`, `<list>`, `<named list>`)"
9 <language> 8 FALSE base :: "withRestarts(expr = withCallingHandlers(expr = return(list(do.call(fn, c(args, named_ar…
10 <language> 9 FALSE base local "withOneRestart(expr, restarts[[1L]])"
11 <language> 10 FALSE base local "doWithOneRestart(return(expr), restart)"
12 <language> 8 FALSE base :: "withCallingHandlers(expr = return(list(do.call(fn, c(args, named_args)), NULL)), python…
13 <language> 8 FALSE base :: "do.call(fn, c(args, named_args))"
14 <language> 8 TRUE NA NA "`<initialize>`(`<Transformer>`, `<pairlist>`)"
15 <language> 14 TRUE NA NA "precompute_freqs_cis(self$params$dim%/%self$params$n_heads, self$params$max_seq_len * 2…
16 <language> 15 TRUE NA NA "tf$linalg$matmul(tf$expand_dims(t, -1), tf$expand_dims(freqs, 0))"
17 <language> 16 TRUE reticulate ::: "split_named_unnamed(eval(cl, parent.frame()))"
18 <language> 16 TRUE base :: "eval(cl, parent.frame())"
19 <language> 18 TRUE base :: "eval(cl, parent.frame())"
20 <language> 15 TRUE rlang local "`<fn>`(tf$expand_dims(t, -1), tf$expand_dims(freqs, 0))"
21 <language> 15 TRUE NA NA "tf$expand_dims(t, -1)"
22 <language> 21 FALSE reticulate ::: "py_call_impl(callable, call_args$unnamed, call_args$named)"
Admittedly, this stack trace is somewhat involved, with magic happening in a few frames. I was hoping to be able to hide reticulate internal frames from the traceback we present by default. Attached is an rds of the actual trace giving the error (ignore the .zip extension, that's just so github lets me upload the file).
drop = FALSE
prints fine:trace.rds.zip