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

Loading record on initialized model set Option<Module> to None #1892

Closed
patata3000 opened this issue Jun 15, 2024 · 11 comments
Closed

Loading record on initialized model set Option<Module> to None #1892

patata3000 opened this issue Jun 15, 2024 · 11 comments

Comments

@patata3000
Copy link

patata3000 commented Jun 15, 2024

Describe the bug

Records don't seem to be saved or loaded correctly with Option<Module>.

To Reproduce

When saving model after training, the model is saved with a field that is an Option<Module> that is set to Some(...).
The training config is saved as well.
Then init is called on the loaded TrainingConfig.
Then is the time to load the record on the initialized model with load_record. Weirdly, the Option<Module> field is set to None.

Expected behavior

When loading record, the field should be set to the saved Some(...).

Desktop (please complete the following information):

  • OS: nixos
  • Browser : not applicable
  • Version: Burn 0.13.2

Additional context

@antimora
Copy link
Collaborator

@nathanielsimard @laggui

@patata3000
Copy link
Author

Sorry, for now, don't bother. I may have f***ed up configuration. I'm closing. If I get sure of the error, I'll reopen it. I may have tried to save some (sub)configs that were not deriving Config.

@patata3000
Copy link
Author

patata3000 commented Jun 18, 2024

Reopening as it was not a configuration problem. Using the DefaultRecorder or CompactRecorder for models gives back None for Option<SomeEnum>. I've not tried with anything else than Enum

@laggui
Copy link
Member

laggui commented Jun 18, 2024

Probably related to #1893.

@laggui
Copy link
Member

laggui commented Jun 19, 2024

When you get the chance, can you try your use case with the latest branch? We just merged #1902 and I think this will solve your issue.

@patata3000
Copy link
Author

I'm gonna try in the next few days. Was not available last week

@patata3000
Copy link
Author

Ok so I tried to make it work. Now I have a new problem. I'm trying to derive Module AND Config for the same enum and I get

conflicting implementations of trait `std::fmt::Display` for type `evaluator::dynamic_model::TensorDimension`
   conflicting implementation for `evaluator::dynamic_model::TensorDimension` [E0119]

Moreover, I cannot derive Module for enums that are struct like.

#[derive(Debug, Module, Clone)]
pub enum TensorDimension {
    Chw {
        channel: usize, // no field `channel` on type `&evaluator::dynamic_model::TensorDimension` unknown field [E0609]
        height: usize, // Same error for all fields. 
        width: usize,
    },
    Hw {
        height: usize,
        width: usize,
    }, // Batch-Height-Width
    Flat {
        length: usize,
    },
}

What about Display duplicate? Should I make 2 differents enum?

What about enums with struct fields? Should I change this to tuples? I prefered struct though.

@laggui
Copy link
Member

laggui commented Jun 25, 2024

Named enum modules are not supported yet (ref #1343). Shouldn't be too difficult to extend the support based on the current derive macro for tuple enum but we haven't seen a lot of use cases for that yet.

Regarding Config and Module conflicts, usually both are separate. Think this conflicts comes from a recent PR to add display capabilities to inspect a module. But I'm not sure in your example why the TensorDimension enum needs to be a module?

If I understand correctly though the original issue has been resolved with the PR linked in the previous comment?

@patata3000
Copy link
Author

Not checked yet, it's a small refacto to use 2 different enums for modules and config

@patata3000
Copy link
Author

I confirm, I get Some instead of None

@patata3000
Copy link
Author

But I'm not sure in your example why the TensorDimension enum needs to be a module?

I need to have a Module because I need to reshape tensors and I don't have a fixed model. Model is static between trainings but is defined programmatically. So I need the info of the shape of the tensor to know if I need to make a reshape.

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

No branches or pull requests

3 participants