haoyang9804 commented on issue #15004:
URL: https://github.com/apache/tvm/issues/15004#issuecomment-1646876481

   If I get it correctly, here is how the error occurs.
   In the low-level library of PyTorch, pooling operator is separated into 
several sub-operators. For instance, `adaptive_max_pool2d_0_0` pools the first 
dimension (the width dimension) while `adaptive_max_pool2d_0_1` pools the 
second dimension (the height dimension) in a common 2-d tensor.
   However, as for `adaptive_max_pool1d`, PyTorch also uses sub-operators, 
which are`adaptive_max_pool1d_0_0` and `adaptive_max_pool1d_0_1` to represent 
it.  In this representation, `adaptive_max_pool1d_0_0` actually takes charge of 
performing pooling while `adaptive_max_pool1d_0_1` does nothing.
   I don't know why the PyTorch developers design in this way, but to perfectly 
converting `adaptive_max_pool1d` in PyTorch, TVM developers maps this operator 
to the a tuple consisting of a call node in the high-level IR and a `None`. 
Here is the implementation in `tvm/relay/frontend/pytorch.py`.
   ```Python
   def adaptive_max_pool(self, op, inputs, input_types):
           data = inputs[0]
           output_size = inputs[1]
           for i, item in enumerate(output_size):
               if isinstance(item, tvm.relay.expr.Constant):
                   # convert Constant to int
                   output_size[i] = item.data.numpy()[()]
           # returns dummy indices too
           return op(data, output_size=output_size), None
   ```
   `None` will finally flow into the `const` function in `tvm/relay/expr.py`, 
which includes the following code:
   ```Python
   if not dtype:
           # when dtype is None: int maps to "int32", float maps to "float32"
           dtype = {_np.dtype("int64"): _np.int32, _np.dtype("float64"): 
_np.float32}.get(
               value.dtype, None
           )
   ```
   `value` here is `None`, and it certainly does not have `dtype` attribute.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to