-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fast Inheritted Instantiation #4
Comments
Another way is to deduce the inherited fields at runtime and change the @dy.dynamize(extends=[torch.nn.Linear])
class MyLinear(torch.nn.Linear):
def __init__(self, in_features, out_features):
# do something with in_features and out_features
# call super().__init__ to create the linear instance itself
super().__init__(in_features, out_features) # specially changed method which passes on other arguments There's no actual need to specify which fields of the base class(es) should be dynamized; instead, we can assume that when a class is mentioned as This means that other parameters in the mentioned example, like I suggest that we wrap the base classes In summary, we can extend the init of a class by mentioning which base classes it tries to extend. |
When using multiple inheritances, as long as the init's of parents don't collide everything is nice and easy, but when they do, we can just agree on a syntax to handle them Take the example of: class BaseA:
def __init__(self, x, y, z):
pass
class BaseB:
def __init__(self, y, z, k):
pass
class BaseC:
def __init__(self, z, k, i):
pass
@dy.dynamize(extends=[BaseA, BaseB])
class MyClass(BaseA, BaseB, BaseC):
def __init__(self, a, b, c):
# codes here
BaseA.__init__(self, x=...)
BaseB.__init__(self, ...)
BaseC.__init__(self, ...) First of all, I believe Second, in this example, we can't just extend the original Oneway is to create the new init with new parameter names which don't collide with one another, like: def __init__(self, ..., x, BaseA__y, BaseA__z, BaseB__y, BaseB__z, ...) Another way is to allow sharing of arguments with the same names, meaning if someone called init with: |
It's also a good idea to explicitly specify which arguments could be merged between the base classes mentioned in the |
Just like Composites, sometimes when something is inherited then all the way down in the inheritance tree everything should be included in the constructors.
In that case, we can use a notion of
dyw.inherited_field
as follows:This should then be similarly instantiated as the previous one.
The text was updated successfully, but these errors were encountered: