Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethrow the error caught when builder fails #238

Merged
merged 3 commits into from
Sep 5, 2023
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
1 change: 1 addition & 0 deletions src/mlj_model_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function MLJModelInterface.fit(model::MLJFluxModel,
build(model, rng, shape) |> move
catch ex
@error ERR_BUILDER
rethrow()
end

penalty = Penalty(model)
Expand Down
28 changes: 28 additions & 0 deletions test/mlj_model_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,31 @@ end
@test length(losses) == 10
end

mutable struct LisasBuilder
n1::Int
end

@testset "builder errors and issue #237" begin
# create a builder with an intentional flaw;
# `Chains` is undefined - it should be `Chain`
function MLJFlux.build(builder::LisasBuilder, rng, nin, nout)
return Flux.Chains(
Flux.Dense(nin, builder.n1),
Flux.Dense(builder.n1, nout)
)
end

model = NeuralNetworkRegressor(
epochs = 2,
batch_size = 32,
builder = LisasBuilder(10),
)

X, y = @load_boston
@test_logs(
(:error, MLJFlux.ERR_BUILDER),
@test_throws UndefVarError(:Chains) MLJBase.fit(model, 0, X, y)
)
end

true
Loading