Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions tests/testthat/helper-chronos.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ stub_chronos_loaders <- function(also_mock_predict_core = FALSE) {
dir.create(fake_dir, recursive = TRUE, showWarnings = FALSE)

bindings <- list(
chronos2_download = function(model_id, revision, cache_dir) {
chronos2_download = function(..., revision) {
list(
model_dir = fake_dir,
sha = if (grepl("^[0-9a-f]{40}$", revision)) {
Expand All @@ -22,7 +22,7 @@ stub_chronos_loaders <- function(also_mock_predict_core = FALSE) {
}
)
},
chronos2_parse_config = function(path) {
chronos2_parse_config = function(...) {
list(
d_model = 384L,
num_layers = 12L,
Expand All @@ -32,10 +32,10 @@ stub_chronos_loaders <- function(also_mock_predict_core = FALSE) {
quantiles = (1:9) / 10
)
},
chronos2_model = function(config) {
structure(list(config = config), class = "fake_chronos_module")
chronos2_model = function(...) {
structure(list(), class = "fake_chronos_module")
},
load_chronos2_weights = function(model, path) invisible(NULL)
load_chronos2_weights = function(...) invisible(NULL)
)

if (also_mock_predict_core) {
Expand All @@ -46,9 +46,8 @@ stub_chronos_loaders <- function(also_mock_predict_core = FALSE) {
bindings$chronos2_predict_core <- function(
object,
context,
prediction_length = NULL,
past_covariates = NULL,
future_covariates = NULL
...,
prediction_length = NULL
) {
n_series <- if (is.list(context)) length(context) else 1L
n_q <- length(object$config$quantiles)
Expand Down
37 changes: 9 additions & 28 deletions tests/testthat/helper-icl.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,27 @@ stub_tabicl_loaders <- function() {
bindings <- list(
# `tabicl_cache_lookup()` normally locates a cached checkpoint and errors if
# none is available; return a throwaway directory instead.
tabicl_cache_lookup = function(task, call = rlang::caller_env()) {
tabicl_cache_lookup = function(...) {
fake_dir
},
# Only `config$max_classes` is consumed at fit time: `> 0` marks a
# classification checkpoint, `<= 0` a regression one. `tabicl_bridge()`
# passes `file.path(path, files$config)`, so branch on the file name.
tabicl_parse_config = function(path) {
tabicl_parse_config = function(path, ...) {
list(
max_classes = if (grepl("classification", path)) 10L else 0L
)
},
# `tabicl_load_model()` reads the safetensors weights; the fake object it
# returns is never inspected because the inference cores below are mocked.
tabicl_load_model = function(
model_dir,
task,
device = "cpu",
verbose = FALSE
) {
structure(list(task = task), class = "fake_tabicl_module")
tabicl_load_model = function(...) {
structure(list(), class = "fake_tabicl_module")
},
# Deterministic class probabilities: one row per test case, one column per
# class, rows summing to 1. The arg-max is rotated across rows so `class`
# predictions are non-constant (guards against the column extraction
# collapsing to a single level).
tabicl_classifier_proba = function(
loaded,
x_train,
y_train,
x_test,
members,
temperature = 0.9,
device = "cpu"
) {
tabicl_classifier_proba = function(loaded, x_train, y_train, x_test, ...) {
n <- nrow(x_test)
n_classes <- length(unique(y_train))
proba <- matrix(0, nrow = n, ncol = n_classes)
Expand All @@ -59,16 +46,10 @@ stub_tabicl_loaders <- function() {
}
proba
},
# Deterministic, non-constant regression predictions.
tabicl_regressor_mean = function(
loaded,
x_train,
y_train,
x_test,
members,
device = "cpu"
) {
seq_len(nrow(x_test)) + mean(y_train)
# Deterministic, non-constant regression predictions. Only the `mean` output
# is stubbed, which covers `type = "numeric"`.
tabicl_regressor_stats = function(loaded, x_train, y_train, x_test, ...) {
list(mean = seq_len(nrow(x_test)) + mean(y_train))
}
)

Expand Down
Loading