Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Inconsistency between HybridBlock and Block #17785

Open
arcadiaphy opened this issue Mar 7, 2020 · 0 comments
Open

Inconsistency between HybridBlock and Block #17785

arcadiaphy opened this issue Mar 7, 2020 · 0 comments
Assignees
Labels

Comments

@arcadiaphy
Copy link
Member

arcadiaphy commented Mar 7, 2020

Following #16279, another example of inconsistency between HybridBlock and Block:

import mxnet as mx
from mxnet.gluon import HybridBlock

class Foo(HybridBlock):
    def hybrid_forward(self, F, a, b):
        return a + b


b1 = Foo(prefix='non_hybrid')
b2 = Foo(prefix='hybrid')
b2.hybridize()

print(b1(mx.nd.ones((10,)), mx.nd.ones((1,))))
print(b2(mx.nd.ones((10,)), mx.nd.ones((1,))))

MXNetError is triggered for hybridized case:

MXNetError: MXNetError: Error in operator hybrid_plus0: [14:24:15] src/operator/numpy/linalg/../../tensor/../elemwise_op_common.h:135: Check failed: assign(&dattr, vec.at(i)): Incompatible attr in node hybridized_plus0 at 1-th input: expected [10], got [1]

I think it's because for symbol, elemwise_add is used for __add__, while for ndarray broadcasting is considered in __add__ considering input shape. Can we add broadcasting in symbol too and avoid the need to differentiate between elemwise_add and broadcast_add?

Note that the same problem exists in subtract, multiply and divide operation, too.

@leezu leezu self-assigned this Mar 9, 2020
@leezu leezu added the Gluon label Mar 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants