Skip to content

Conversation

@BernhardAhrens
Copy link
Collaborator

No description provided.

@BernhardAhrens BernhardAhrens changed the title test if is the st's too lazy to run tests locally Continuation: use Lux.Training.single_train_step! Dec 5, 2025
@BernhardAhrens
Copy link
Collaborator Author

BernhardAhrens commented Dec 5, 2025

I reworked the loss functions to match the signature Lux expects

At least one of them. There is the other signature that @Qfl3x implemented but I think the one with these inputs

model, ps, st, (x, y) where model is the model, ps are the parameters, st are the states and (x, y) are the input and target pair.

fits best to what we already had as lossfn functions. The bad performance in training was indeed a BatchNorm and states issue (pretty sure).

@BernhardAhrens
Copy link
Collaborator Author

Let's test more before we merge @lazarusA

@info "Check the saved output (.png, .mp4, .jld2) from training at: $(tmp_folder)"

prog = Progress(nepochs, desc = "Training loss", enabled = show_progress)
loss(hybridModel, ps, st, (x, y)) = lossfn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is nice.

struct MultiNNModel
struct MultiNNModel <: LuxCore.AbstractLuxContainerLayer{
(
:NNs, :predictors, :targets, :scale_nn_outputs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should dispatch on this, -> the NNs, instead of having 2 different structs, only one struct HybridModel end and an internal function HybridModel end that does the current constructHybridModel bit. For now, is good that this already works but we should address this in a following PR.

@BernhardAhrens
Copy link
Collaborator Author

btw, projects/book_chapter/example_synthetic.jl is currently the best script to test the GenericHybrid model in all flavors @lazarusA @Qfl3x. Also feel free to add to this PR on top

@lazarusA
Copy link
Member

lazarusA commented Dec 8, 2025

btw, projects/book_chapter/example_synthetic.jl is currently the best script to test the GenericHybrid model in all flavors @lazarusA @Qfl3x. Also feel free to add to this PR on top

I will add only a few test for the different possible options of autodiff_backend, then we merge, ? ok?

@BernhardAhrens
Copy link
Collaborator Author

Yes, sounds good! Feel free to add or rm what you deem necessary.

I also experimented a bit with making Enzyme work in the aforementioned script - but run into a problem/dead end with DimensionalData, so far: https://github.com/EarthyScience/EasyHybrid.jl/tree/ba/enzyme_tries

@lazarusA
Copy link
Member

lazarusA commented Dec 8, 2025

Yes, sounds good! Feel free to add or rm what you deem necessary.

I also experimented a bit with making Enzyme work in the aforementioned script - but run into a problem/dead end with DimensionalData, so far: https://github.com/EarthyScience/EasyHybrid.jl/tree/ba/enzyme_tries

yes, we need a new rrule for metadata (Enzyme expects mutable entities, but KA and DD have their metadata const). We will need a rrule that removes that metadata.

struct MultiNNHybridModel
struct MultiNNHybridModel <: LuxCore.AbstractLuxContainerLayer{
(
:NNs, #:predictors, :forcing, :targets,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the interface should only deal with Layers, and not static inputs, see

https://lux.csail.mit.edu/stable/api/Building_Blocks/LuxCore#States

Zygote doesn't complain about it, but ForwardDiff will fail trying to apply preserves_state_type.

Leaving these as comments now, to be clean up later, once things are more stable they should be removed.

@lazarusA lazarusA merged commit fe1b3f7 into main Dec 8, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants