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

Infer_shape_partial for rank 0 arrays #8133

@aseyboldt

Description

@aseyboldt

In the python interface of mxnet it seems to be impossible to distinguish between an array of unknown shape and an array with known shape of ():

a = mx.sym.var('a')
b = mx.sym.var('b')

(a + b).infer_shape_partial(b=())
([(), ()], [()], [])

In this case b is known to be a scalar, while a's shape is unknown.
Shouldn't it return something like ([None, ()], [None], [])?

If a is set to be a scalar, it returns an invalid result:

a = mx.sym.var('a')
b = mx.sym.var('b')

(a + b).infer_shape_partial(a=(), b=(1, 2))
([(1, 2), (1, 2)], [(1, 2)], [])

It identifies the shape of a as (1, 2), even though we set it to a scalar.

If we don't set the shape of a, it returns results, that aren't always true:

a = mx.sym.var('a')
b = mx.sym.var('b')
c = a + b

c.infer_shape_partial(b=(1, 2))
([(1, 2), (1, 2)], [(1, 2)], [])

# but a could also be a scalar:
a_ = mx.nd.zeros(())
b_ = mx.nd.zeros((1, 2))
func = c.bind(mx.cpu(), {'a': a_, 'b': b_})
func.forward()

Edit: Does it? It looks like it accesses memory out of bounds:

a = mx.sym.var('a')
b = mx.sym.var('b')

c = a + b

a_ = mx.nd.ones(())
b_ = mx.nd.ones((5))
func = c.bind(mx.cpu(), {'a': a_, 'b': b_})
func.forward()
func.outputs[0].asnumpy()
array([  2.00000000e+00,   2.52435490e-29,   8.84247875e+05,
         1.08446609e-19,  -1.92860745e-26], dtype=float32)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions