Incomprehensible behaviour

Hello @zetyquickly,

Thanks one more time for this finding.

It happened as in jni tensorType was deduced from the first entry value of dictionary, including shape, requires_grad etc.
While torchscript function did not have it. Dict is not covariant, so the subtype check required equal KeyType(str) and ValueType(TensorType0).
TensorType’s of function argument and provided value were different and typecheck failed.
Error message did not include that additional information about TensorType.

This problem was fixed on android-jni level in commit:


It was merged in master recently.

Separate issue for more detailed error messages in TensorType checks.

Android nightlies (snapshots) are already republished with this fix, the error should not happen with them.
To use nightlies (to force refresh dependencies gradle has argument --refresh-dependencies)

repositories {
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
}

dependencies {
    ...
    implementation 'org.pytorch:pytorch_android:1.4.0-SNAPSHOT'
    implementation 'org.pytorch:pytorch_android_torchvision:1.4.0-SNAPSHOT'
    ...
}
1 Like