Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Relay][Op] Add type check to dense #4724

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/relay/op/nn/nn.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ bool DenseRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
} else {
if (weight == nullptr) return false;
Array<tvm::PrimExpr> wshape = weight->shape;
CHECK(static_cast<int>(weight->shape.size()) == 2);
CHECK(reporter->AssertEQ(data->shape[data->shape.size() - 1],
weight->shape[1]))
<< "DenseRel: input dimension doesn't match,"
<< " data shape=" << data->shape << ", weight shape=" << weight->shape;
oshape.Set((oshape.size() - 1), wshape[0]);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/python/relay/test_op_level1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.
import numpy as np
import pytest
import tvm
import scipy
from tvm import relay
Expand Down Expand Up @@ -336,6 +337,16 @@ def test_batch_norm():
relay.ty.TensorType((3,), dtype)
]))

@pytest.mark.xfail
def test_dense_type_check():
dtype = 'float16'
n, c , h, w = 2, 2 , 2 ,2
x = relay.var("x", relay.TensorType((n, c, h, w), dtype))
# it should fail since it does not match with m(2)
mismatch_w = 3
w = relay.var("w", relay.TensorType((2, mismatch_w), dtype))
y = relay.nn.dense(x, w)
yy = run_infer_type(y)

def test_dense():
for dtype in ['float16', 'float32']:
Expand Down