Input parameter restriction for HybridBlock

I got the following error while doing the forward pass in my network:

AssertionError: HybridBlock requires the first argument to forward be either Symbol or NDArray, but got <class 'list'>

Currently, I am passing in a list because in addition to the “actual input”, some of the custom layers in the network need some extra information to do their forward pass computation.

Is there an easy way to do this, i.e., to pass the extra information along in addition to the actual input?

Theoretically, I could somehow encode that extra information along with the actual input into a single NDArray and then have each layer separate out the extra information and the actual input. But, that would be a pain and possibly hit performance. In case there is any easy way to avoid that, can you please let me know?


expand the list with block(*arguments) and define hybrid_forward as def hybrid_forward(self, F, x1, x2, ...)

I tried the following:

class MyNetwork(gluon.HybridBlock):
    def hybrid_forward(self, F, in1, in2, in3, in4, in5, in6, in7, in8):

In the main code:

net = MyNetwork()
with autograd.record():
   args = (a1, a2, a3, a4, a5, a6, a7, a8)
   outY = net(*args)

But, that gives me the following error:

AssertionError: HybridBlock input must be (nested) list of Symbol or NDArray, but got 32 of type <class 'int'>

Am I doing it wrong?

P.S. Interestingly, I noticed that the above code does work if the net.hybridize() line is commented out, but, gives the error mentioned above if the line is not commented out.

can you make sure that
a1, a2, a3, a4, a5, a6, a7, a8

are ndarray rather than int?

Please make sure that all the variables in your hybridblock are defined in ndarray.


a = 1 should be a = nd.array([1])