Giter Site home page Giter Site logo

Comments (9)

ovthf avatar ovthf commented on August 12, 2024 1

Hello @IvanKobzarev

Thanks for your quick response.
The issue has been fixed.

I noticed another issue that quantized model was much slower than floating model on moto G7 power android phone.

With floating model, duration per inference is around 3 second.
With quantized model, duration per inference is around 10 second, and it outputs below message
"E/QNNPACK: failed to create convolution with 0.03779296 input scale, 2.583814 kernel scale, and 0.06601464 output scale: convolution scale 1.479217 is greater or equal to 1.0"

Please help to investigate.

Thanks a lot.

from android-demo-app.

zetyquickly avatar zetyquickly commented on August 12, 2024

Same here #31

from android-demo-app.

IvanKobzarev avatar IvanKobzarev commented on August 12, 2024

Hello @ovthf
Sorry for my late reply.

There was a bug that was introduced into nightly builds - they included debug symbols and were very big, that gradle without additional setup of heap size (Xmx) failed to transform them.

The fix was landed in master today ( pytorch/pytorch@8e3486d ) and the latest nightlies are 'normal' size.

Please try the latest nightlies if it is still the problem.

from android-demo-app.

ovthf avatar ovthf commented on August 12, 2024

Hello @IvanKobzarev

Thanks for your help.

It works fine now.

But when doing second time forward, encounter below issue. Please help. Thanks a lot.

Testing code:
// running the model
final Tensor outputTensor = module.forward(IValue.from(inputTensor)).toTensor(); // first time is OK
final Tensor outputTensor2 = module.forward(IValue.from(inputTensor)).toTensor();

com.facebook.jni.CppException:
Unknown builtin op: aten::_adaptive_avg_pool2d_backward.
Could not find any similar ops to aten::_adaptive_avg_pool2d_backward. This op may not exist or may not be currently supported in TorchScript.
:
at :9:28
grad_self = grad.expand(self.size()) / (self_size[-1] * self_size[-2])
else:
grad_self = torch._adaptive_avg_pool2d_backward(grad, self)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE

            return grad_self

    at org.pytorch.Module$NativePeer.forward(Native Method)

from android-demo-app.

IvanKobzarev avatar IvanKobzarev commented on August 12, 2024

@ovthf
Yes, its connected with the issue that was fixed in pytorch/pytorch#30067

It was merged yesterday in pytorch master and it is included in our nightly android builds. To use them:

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'
    ...
}

If you already using nightlies, you might need gradle key --refresh-dependencies to be sure that gradle would not use the cached version.

To check that the patch is included, 1.4.0 nightlies version should be >= 45
the latest nightly url:
https://oss.sonatype.org/service/local/repositories/snapshots/content/org/pytorch/pytorch_android/1.4.0-SNAPSHOT/pytorch_android-1.4.0-20191120.095738-45.aar

from android-demo-app.

dreiss avatar dreiss commented on August 12, 2024

@raghuramank100 , have you seen that error before?

from android-demo-app.

raghuramank100 avatar raghuramank100 commented on August 12, 2024

I havent seen this before, but this error is specific to QNNPACK and is related to allowed values of scale and zero-point. I havent seen this issue for Mobilenet-v2.

from android-demo-app.

raghuramank100 avatar raghuramank100 commented on August 12, 2024

This looks like a genuine error related to QNNPACK, it is coming from: https://github.com/pytorch/QNNPACK/blob/901e9d40aeedb2c1b212b28f022fb099ffe617c2/src/convolution.c#L161
There is an assumption that (input_scale*wt_scale) < output_scale.

Are you running your model with sufficient calibration data prior to quantizing it?
cc @AshkanAliabadi @supriyar

from android-demo-app.

ovthf avatar ovthf commented on August 12, 2024

Used 50 images to do calibration.

Here is how to quantize model:

model = torch.load(m_path)
torch.backends.quantized.engine = "qnnpack"
model.eval()
model.fuse_model()
model.qconfig = torch.quantization.get_default_qconfig("qnnpack")
torch.quantization.prepare(model, inplace=True)
calibrate_model(model)
torch.quantization.convert(model, inplace=True)
example = torch.rand(1, 1, width, height)
traced_script_module = torch.jit.trace(model, example)
traced_script_module.save(out_file)

Please help to verify.

from android-demo-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.