Comments (9)
Yes that's what I mean
from burn.
I'm closing this, since we have the init
and init_with
function on the config struct to build modules.
from burn.
The builder pattern is already implemented for configs, and I really want to put emphasis on using serializable hyper-parameters. However, we could still improve the API with an init
function:
let conv = Conv2dConfig::new(1, 3) // Required arguments
.with_bias(false)
.init();
This would be a new Trait to be implemented by Module with something like:
// The derive can add `init()` to `Conv2dConfig` that dispatch to the `Initialize` trait.
#[derive(Module(config = "Conv2dConfig"))]
pub struct Conv2d{
...
}
impl<B: Backend> Initialize<B> for Conv2d<B> {
type Config = Conv2dConfig;
fn init(config: &Self::Config) -> Self {
...
}
/// It would be cool to have an optional `init_state` function that would, by default, use the `init` method.
fn init_state(state: &State<B::FloatElem>, config: &Self::Config) -> Self {
...
}
}
We could require every module to implement Initialize
and force them to have an associative type Config
. With this, we could avoid having to initialize a module just before loading the weights (waste), which could reduce cold starts.
from burn.
Ho I forgot that you can't have arguments in derive macros. After consideration, I think we should just implement From
.
impl<B: Backend> From<ModuleConfig> for Module<B> {
...
}
It automatically generate the into method, so you could have:
let module: Module<B> = ModuleConfig::new(...).into();
What I like about it is that it's very Rusty and you can have multiple From
implementations for the same module. Which means that we could also implement:
impl<B: Backend> From<(ModuleConfig, State)> for Module<B> {
...
}
So instead of initializing a new module, it creates a new module with the given weights.
let module: Module<B> = (ModuleConfig:new(...), state).into();
// or
let module = Module::from((ModuleConfig::new(...), state));
It's a bit less pretty than the previous use case, since you have a tuple, but it's easy to understand I think.
Of course you don't always have to specify the type Module<B>
if Rust can infer it, which may lighten up the syntax most of the time.
from burn.
I feel like using from and into is a bit overloaded here. I think of into
and from
are used transform to a similar/sister structure but here we are trying to use a configuration to build a module.
Why is it necessary to do #[derive(Module(config = "Conv2dConfig"))]
?
Can we just do this?
impl<B: Backend> Initialize<B> for Conv2dConfig<B> {
type Module = Conv2d;
fn init(&self) -> Module {
...
}
fn init_state(&self, state: State) -> Module {
...
}
}
It's similar as implementing From
.
from burn.
The thing that bothers me with this is that some modules may need something else then the config to be initialized. For example, some modules may need shared parameters from another module before being initialized. So the Initialize
trait would not fit that purpose. So do we need an abtraction for this knowing that not all modules will be able to implement it? I'm not sure.
Maybe we could just implement init
and init_state
on modules without being a trait. Also, the Initialize
trait would not need to be imported to see the methods pop in autocomplete, maybe helping discoverability.
from burn.
Maybe we could just implement
init
andinit_state
on modules without being a trait. Also, theInitialize
trait would not need to be imported to see the methods pop in autocomplete, maybe helping discoverability.
Do you mean init
and init_state
on *Config structs? Are we still able to do this?
let conv = Conv2dConfig::new(1, 3) // Required arguments
.with_bias(false)
.init();
with we can do this too:
let conv_config = Conv2dConfig::new(1, 3) // Required arguments
.with_bias(false);
let conv = conv_config.init();
// or
let conv = conv_config.init_state(data);
from burn.
@nathanielsimard Where do we stand on this task? Will you have additional check-ins on top what of your merged PR?
from burn.
I think we need to be able to load a model with the sate before the issue is 100% completed, probably very soon.
from burn.
Related Issues (20)
- loss.backward() hangs after burn update 0.12 -> 0.13 HOT 3
- Help Wanted: Implementing ONNX Ops
- Implement multi-dimensional repeat operation and rename existing repeat method HOT 2
- [Tensor] Add `cumsum` operation HOT 1
- .select_assign does not work with Autodiff<NdArray> backend
- Add indentation in contributing book
- Text classification example gives "Shader validation error" when run on multiple GPUs HOT 5
- Upgrade all dependencies
- Better memory management in Burn Compute
- Config Derive: Generic Types? HOT 2
- Optimizer / Visitor / Mapper confusion, no documentation HOT 4
- clamp_min does not handle -inf correctly on Autodiff<NdArray> backend
- Update tch to 0.16+
- Add multi-stream support to all the different backends.
- Add application logger strategy to learner builder
- Improve pickle (`CandleTensor`) conversions to `NestedValue`
- Add `squeeze_dims` function
- Building failed. Err: Is gcc.exe installed
- Bug with element types in JIT when using all(), related to PRNG
- Crate libc 0.2.154 is yanked
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from burn.