Comments (4)
I thought to add another class called Initializers
with a function that we could pass the weights and a string with the initialization
name. Also add a string argument to every layer called "initialization".
In a Linear layer the init should be something like this:
def __init__(self, in_features, out_features, bias=True, initializer=None):
super(Linear, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.weight = Parameter(torch.Tensor(out_features, in_features))
Initializers.initialize(self.weight, initializer)
if bias:
self.bias = Parameter(torch.Tensor(out_features))
else:
self.register_parameter('bias', None)
self.reset_parameters()
Do you think that this is the best approach? If not, what would be the best way to do this?
from pytorch.
I think it's better to pass in a function as the initializer and call it with weights as argument. It's clean, verbose, and you don't have to do error checking for invalid/incompatible strings. For example:
nn.Linear(20, 20, weight_init=nn.init.orthogonal)
Do you want to implement it, or was your comment only a suggestion?
from pytorch.
Chainer has a nice approach, where the initializer argument is a little polymorphic (can be a callable or a scalar/matrix value). Looks like this:
super().__init__(
maxout=Maxout(maxout_size, maxout_size, 2, initialW=initializers.GlorotUniform()),
softmax_linear=Linear(maxout_size, task.num_classes, initialW=0))
from pytorch.
@apaszke, I am thinking to implement it.
I think that String-like is cleaner. But we could go the way Chainer implements it, as shown by @jekbradbury. With strings or class names being accepted.
What do you guys think?
from pytorch.
Related Issues (20)
- [RFC] Cuda support matrix for Release 2.4 HOT 13
- [DTensor] High CPU memory usage/slowdown for `aten._foreach_addcdiv_.ScalarList` HOT 1
- Running `aten._foreach_addcdiv_.ScalarList` with `FakeTensor`s uses high CPU memory and is slow HOT 7
- torch._C.JitType annotation is busted HOT 1
- lintrunner-noclang job may diverge from `lintrunner` locally HOT 2
- Undefined behavior when an OpOverload's Library is deleted but the OpOverload continues to be used
- torch.compile x custom ops: op that accepts float also accepts Tensor in eager-mode
- Inductor: expected scalar type Long but found Float for int literal HOT 2
- Export producing wrong overload for aten.mul HOT 2
- Compiling optimizers with closure argument HOT 2
- Export serializes empty list as list of bools HOT 2
- [dynamo] Are we over guarding on `__defaults__`? HOT 4
- [bug] Tensor.numpy() should return np.ndarray not Any HOT 2
- Support Exceptions in Pytorch Export HOT 2
- Cannot add 2 sparse_csc_tensor directly, raising RuntimeError
- [inductor][cpu] FP32/AMP Static/Dynamic shape default/CPP wrapper models regression in 2024-04-01 nightly release HOT 2
- [inductor][cpu]basic_gnn_gcn AMP static/dynamic shape default/cpp wrapper single thread performance regression HOT 3
- [inductor][cpu]GPT2ForSequenceClassification AMP static/dynamic shape default/cpp wrapper single thread accuracy crash HOT 1
- RuntimeError: Unrecognized CachingAllocator option: expandable_segments HOT 2
- [RFE] Disallow submodule updates without successful minimal binary builds HOT 1
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 pytorch.