question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EngineException with pytorch-native-cpu:osx-x86_64

See original GitHub issue

Description

When I run my inference in osx, I got the EngineException. It seems that the inference call the torch python code in my virtualenvs.

The Code runs all right in linux if i change the classifier of pytorch-native-cpu from osx-x86_64 to linux-x86_64.

My Java code is:

        Translator<Image, Classifications> translator = ImageClassificationTranslator.builder()
                .addTransform(new Resize(200, 150))
                .addTransform(new ToTensor())
                .build();

        Criteria<Image, Classifications> criteria = Criteria.builder()
                .setTypes(Image.class, Classifications.class)
                .optApplication(Application.CV.IMAGE_CLASSIFICATION)
                .optModelUrls("file:///Users/jinlong.hao/Project/02-python/02-pytorch/02-drive-classification/output/model")
                .optTranslator(translator)
                .build();

        ZooModel<Image, Classifications> model = ModelZoo.loadModel(criteria);
        Predictor<Image, Classifications> predictor = model.newPredictor(translator);

I got the exception while loadModel(criteria)

my pom:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>ai.djl</groupId>
                <artifactId>bom</artifactId>
                <version>0.8.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>model-zoo</artifactId>
        </dependency>

        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>api</artifactId>
        </dependency>

        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-engine</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-native-cpu</artifactId>
            <version>1.6.0</version>
            <classifier>osx-x86_64</classifier>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

Expected Behavior

The same code can successfully execute in osx.

Error Message

Exception in thread "main" ai.djl.engine.EngineException: 

aten::_convolution(Tensor input, Tensor weight, Tensor? bias, int[] stride, int[] padding, int[] dilation, bool transposed, int[] output_padding, int groups, bool benchmark, bool deterministic, bool cudnn_enabled) -> (Tensor):
Expected at most 12 arguments but found 13 positional arguments.
:
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/torch/nn/modules/conv.py(420): _conv_forward
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/torch/nn/modules/conv.py(423): forward
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/torch/nn/modules/module.py(709): _slow_forward
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/torch/nn/modules/module.py(725): _call_impl
<ipython-input-4-9fa5f3569917>(14): forward
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/torch/nn/modules/module.py(709): _slow_forward
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/torch/nn/modules/module.py(725): _call_impl
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/torch/jit/_trace.py(940): trace_module
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/torch/jit/_trace.py(742): trace
<ipython-input-9-1a9190abafbf>(6): <module>
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/IPython/core/interactiveshell.py(3418): run_code
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/IPython/core/interactiveshell.py(3338): run_ast_nodes
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/IPython/core/interactiveshell.py(3147): run_cell_async
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/IPython/core/async_helpers.py(68): _pseudo_sync_runner
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/IPython/core/interactiveshell.py(2923): _run_cell
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/IPython/core/interactiveshell.py(2878): run_cell
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/ipykernel/zmqshell.py(536): run_cell
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/ipykernel/ipkernel.py(306): do_execute
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/gen.py(234): wrapper
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/ipykernel/kernelbase.py(545): execute_request
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/gen.py(234): wrapper
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/ipykernel/kernelbase.py(268): dispatch_shell
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/gen.py(234): wrapper
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/ipykernel/kernelbase.py(365): process_one
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/gen.py(775): run
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/gen.py(741): __init__
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/gen.py(250): wrapper
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/ipykernel/kernelbase.py(381): dispatch_queue
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/gen.py(775): run
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/gen.py(814): inner
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/ioloop.py(741): _run_callback
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/ioloop.py(688): <lambda>
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/asyncio/events.py(88): _run
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py(1775): _run_once
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py(539): run_forever
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/tornado/platform/asyncio.py(199): start
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/ipykernel/kernelapp.py(612): start
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/traitlets/config/application.py(845): launch_instance
/Users/dev/.local/share/virtualenvs/02-pytorch-Vcd_DXB5/lib/python3.7/site-packages/ipykernel_launcher.py(16): <module>
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py(85): _run_code
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py(193): _run_module_as_main
Serialized   File "code/__torch__/torch/nn/modules/conv.py", line 10
    input: Tensor) -> Tensor:
    _0 = self.bias
    input0 = torch._convolution(input, self.weight, _0, [1, 1], [0, 0], [1, 1], False, [0, 0], 1, False, False, True, True)
             ~~~~~~~~~~~~~~~~~~ <--- HERE
    return input0

	at ai.djl.pytorch.jni.PyTorchLibrary.moduleLoad(Native Method)
	at ai.djl.pytorch.jni.JniUtils.loadModule(JniUtils.java:1110)
	at ai.djl.pytorch.engine.PtModel.load(PtModel.java:72)
	at ai.djl.repository.zoo.BaseModelLoader.loadModel(BaseModelLoader.java:142)
	at ai.djl.repository.zoo.ModelZoo.loadModel(ModelZoo.java:162)
	at cn.eppdev.test.djl.pytorch.ImageClassification.main(ImageClassification.java:63)

How to Reproduce?

Steps to reproduce

1.download my model.pt and synset.txt to the same directory 2.run the same code in osx

What have you tried to solve it?

Environment Info

Please run the command ./gradlew debugEnv from the root directory of DJL (if necessary, clone DJL first). It will output information about your system, environment, and installation that can help us debug your issue. Paste the output of the command below:

PASTE OUTPUT HERE

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
frankfliucommented, Nov 21, 2020

This looks like a jit issue. Looks you you traced model using pytorch 1.7.0

I got the same error using pytorch 1.6.0, but it works fine with DJL 0.9.0-SNAPSHOT with PyTorch 1.7.0

0reactions
stu1130commented, Dec 29, 2020

Hi @jinlong-hao you can try out djl 0.9.0 with pytorch 1.7 now! feel free to reopen the issue if you still have questions

Read more comments on GitHub >

github_iconTop Results From Across the Web

Native Deodorant | Clean. Simple. Effective.
Aluminum-Free & Paraben-Free Deodorant. Vegan & Cruelty Free. More than 15000 5 Star Reviews. Free Shipping on US Orders $10+.
Read more >
Contact Us - Native Deodorant
Let us know how we can help, and we`ll reply faster than you can say `no phthalates`. Name. Email. Subject. Subscriptions, Order Tracking,...
Read more >
Native FAQ - Native Deodorant
Have a question? Native's Frequently Asked Questions can answer questions about our Aluminum Free Deodorant, Sulfate Free Body Wash, Vegan Toothpaste, ...
Read more >
Products - Native Deodorant
We love and stand behind the products we make. If you don't love your first order from Native, we'll gladly help you return...
Read more >
Shop All - Native Deodorant
If you think you smell great with just one Native product, imagine what life will be like when you're flaunting your favorite fragrance...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found