pfnet-research / chainer-compiler

Experimental toolchain to compile and run Chainer models
MIT License
112 stars 23 forks source link

Fix unification of shapes #811

Closed momohatt closed 4 years ago

momohatt commented 4 years ago

This PR fixes the unification of shapes. Originally,

x = ShapeElem(1)
y = ShapeElem(None)
unify_shape((x,), (y,))

would have changed y into (ShapeElem(1),). However, this will result in the following inference.

x = torch.Tensor(4, 1, dtype=torch.float)
for i in range(5):
    x = x.expand(4, x.size(1) + 1)
# x : torch.Tensor(float32, (4, 1)) <-- shape should be (4, None)

This PR a) fixes this behavior, and b) adds implementation for applying shape annotation for tensors, which will be broken by a).

shinh commented 4 years ago

/test

pfn-ci-bot commented 4 years ago

Successfully created a job for commit b107dba: