# jit

**URL:** https://discuss.pytorch.org/c/jit/13.md?page=2

[Latest](https://discuss.pytorch.org/latest.md) · [Categories](https://discuss.pytorch.org/categories.md)

**Page:** 3

---

## [Failing to export the Swin Transformer model into the Onnx file](https://discuss.pytorch.org/t/failing-to-export-the-swin-transformer-model-into-the-onnx-file/202588)

<div class="topic-metadata">

**Author:** [@ali\_shahedi](https://discuss.pytorch.org/u/ali_shahedi)\
**Replies:** 0\
**Last updated:** [May 12, 2024, 11:01am UTC](https://discuss.pytorch.org/t/failing-to-export-the-swin-transformer-model-into-the-onnx-file/202588 "2024-05-12T11:01:06Z")

</div>

Hi everyone. I want to export the Pytorch Swin Transformer model into the Onnx format. However, I got the following error: Traceback (most recent call last): File "/content/Rethinking\_of\_PAR/export\_onnx.py", line 163,…

---

## [Disable TracerWarnings for known constants](https://discuss.pytorch.org/t/disable-tracerwarnings-for-known-constants/124634)

<div class="topic-metadata">

**Author:** [@tjoseph](https://discuss.pytorch.org/u/tjoseph)\
**Replies:** 4\
**Last updated:** [May 9, 2024, 8:51pm UTC](https://discuss.pytorch.org/t/disable-tracerwarnings-for-known-constants/124634 "2024-05-09T20:51:42Z")

</div>

Hi everyone, is there a way to deactivate some TracerWarnings for when I know the input size will not change? My code is written such that it work with variable input sizes, but actually a single run always uses consta…

---

## [Torchscript with ToTensor / ToImage](https://discuss.pytorch.org/t/torchscript-with-totensor-toimage/200008)

<div class="topic-metadata">

**Author:** [@lc\_26](https://discuss.pytorch.org/u/lc_26)\
**Replies:** 0\
**Last updated:** [April 1, 2024, 8:30pm UTC](https://discuss.pytorch.org/t/torchscript-with-totensor-toimage/200008 "2024-04-01T20:30:58Z")

</div>

I see in the docs that torchvision’s ToTensor (deprecated) and the recommended replacement that includes ToImage are not supported by torchscript. What are the recommended ways to serialize these transforms with or witho…

---

## [\[jit\] bad constant exponent (e+38.f) in default\_program fused\_mul\_div\_add](https://discuss.pytorch.org/t/jit-bad-constant-exponent-e-38-f-in-default-program-fused-mul-div-add/201489)

<div class="topic-metadata">

**Author:** [@sits](https://discuss.pytorch.org/u/sits)\
**Replies:** 0\
**Last updated:** [April 24, 2024, 1:06am UTC](https://discuss.pytorch.org/t/jit-bad-constant-exponent-e-38-f-in-default-program-fused-mul-div-add/201489 "2024-04-24T01:06:38Z")

</div>

Hi - I have been using DJL (GitHub - deepjavalibrary/djl: An Engine-Agnostic Deep Learning Framework in Java) with PyTorch of late, and hit this bug: \[nightly\]\[jit\] bad constant exponent (e+38.f) in default\_program fused…

---

## [Running cpp torch::jit::Graph](https://discuss.pytorch.org/t/running-cpp-torch-graph/78858)

<div class="topic-metadata">

**Author:** [@Omer\_B](https://discuss.pytorch.org/u/Omer_B)\
**Replies:** 5\
**Last updated:** [April 17, 2024, 5:52am UTC](https://discuss.pytorch.org/t/running-cpp-torch-graph/78858 "2024-04-17T05:52:15Z")

</div>

Hey, I’m quite stuck on trying to run torch::jit::Graph with cpp API, I have already tried to search for docs or implementations but failed. my main purpose to do so is to divide a JIT Graph into subgraphs (I would like…

---

## [Call Cython Module in Torchscript](https://discuss.pytorch.org/t/call-cython-module-in-torchscript/140354)

<div class="topic-metadata">

**Author:** [@Jacky\_Wang](https://discuss.pytorch.org/u/Jacky_Wang)\
**Replies:** 5\
**Last updated:** [April 12, 2024, 12:24pm UTC](https://discuss.pytorch.org/t/call-cython-module-in-torchscript/140354 "2024-04-12T12:24:39Z")

</div>

Hi, guys. I wonder how to call scripts written in cython when creating jit scripts? Traditionally, I can call cython class directly in python file after compiling those cython modules. And part of my model inference req…

---

## [Torchscript C++ forward() Expected a value of type 'List\[Tensor\]' for argument 'images'](https://discuss.pytorch.org/t/torchscript-c-forward-expected-a-value-of-type-list-tensor-for-argument-images/200697)

<div class="topic-metadata">

**Author:** [@ricardo\_assaad](https://discuss.pytorch.org/u/ricardo_assaad)\
**Replies:** 0\
**Last updated:** [April 11, 2024, 6:02pm UTC](https://discuss.pytorch.org/t/torchscript-c-forward-expected-a-value-of-type-list-tensor-for-argument-images/200697 "2024-04-11T18:02:02Z")

</div>

Hello Everyone, I have been trying to figure out an issue with torchscript in c++ When I use the scripted model in python it works # code in python for inference script = torch.jit.optimize\_for\_inference(torch.jit.scr…

---

## [Torch.jit.script is not working with fasterrcnn](https://discuss.pytorch.org/t/torch-jit-script-is-not-working-with-fasterrcnn/200628)

<div class="topic-metadata">

**Author:** [@ricardo\_assaad](https://discuss.pytorch.org/u/ricardo_assaad)\
**Replies:** 0\
**Last updated:** [April 10, 2024, 5:46pm UTC](https://discuss.pytorch.org/t/torch-jit-script-is-not-working-with-fasterrcnn/200628 "2024-04-10T17:46:51Z")

</div>

Hello Everyone, I have been trying to figure out an issue with torchscript in c++ I get the following error: forward() Expected a value of type ‘List\[Tensor\]’ for argument ‘images’ but instead found type ‘Tensor’. P…

---

## [How to Persist JIT Fused CUDA Kernels State for Efficient Inference on Multi-GPU Setup?](https://discuss.pytorch.org/t/how-to-persist-jit-fused-cuda-kernels-state-for-efficient-inference-on-multi-gpu-setup/200106)

<div class="topic-metadata">

**Author:** [@jonf](https://discuss.pytorch.org/u/jonf)\
**Replies:** 5\
**Last updated:** [April 4, 2024, 1:07pm UTC](https://discuss.pytorch.org/t/how-to-persist-jit-fused-cuda-kernels-state-for-efficient-inference-on-multi-gpu-setup/200106 "2024-04-04T13:07:52Z")

</div>

Hi, PyTorch Community! I’m currently working on a deep learning project focused on computer vision, utilizing CNNs for inference. Our setup involves a multi-GPU environment, specifically using 8 GPUs, to handle our work…

---

## [Torch.jit.trace() memory leak workarounds](https://discuss.pytorch.org/t/torch-jit-trace-memory-leak-workarounds/199184)

<div class="topic-metadata">

**Author:** [@dshin](https://discuss.pytorch.org/u/dshin)\
**Replies:** 4\
**Last updated:** [April 3, 2024, 3:39pm UTC](https://discuss.pytorch.org/t/torch-jit-trace-memory-leak-workarounds/199184 "2024-04-03T15:39:04Z")

</div>

It has been reported elsewhere that torch.jit.trace() has a memory leak. This is a problem for me because my application repeatedly calls torch.jit.trace().save() in a loop (later loading the saved model with torchlib in…

---

## [Build torch 2.2.0 with vulkan failed by ndk-26b](https://discuss.pytorch.org/t/build-torch-2-2-0-with-vulkan-failed-by-ndk-26b/199926)

<div class="topic-metadata">

**Author:** [@dearwind253](https://discuss.pytorch.org/u/dearwind253)\
**Replies:** 0\
**Last updated:** [March 31, 2024, 2:31pm UTC](https://discuss.pytorch.org/t/build-torch-2-2-0-with-vulkan-failed-by-ndk-26b/199926 "2024-03-31T14:31:58Z")

</div>

torch code version: 2.2.0 ndk version: ndk-r26b OS: mac IOS M1 error : – Configuring done CMake Error at cmake/VulkanDependencies.cmake:18 (add\_library): Cannot find source file: /Users/tools/android-ndk-r26b/NDK…

---

## [Cannot trace my own model using torch.jit.trace](https://discuss.pytorch.org/t/cannot-trace-my-own-model-using-torch-jit-trace/199791)

<div class="topic-metadata">

**Author:** [@111408](https://discuss.pytorch.org/u/111408)\
**Replies:** 1\
**Last updated:** [March 30, 2024, 3:51pm UTC](https://discuss.pytorch.org/t/cannot-trace-my-own-model-using-torch-jit-trace/199791 "2024-03-30T15:51:41Z")

</div>

I want trace my own model. I want to use it in C++. But when I use torch.jit.trace to trace it, I got errors as follows: Traceback (most recent call last): File “main.py”, line 457, in traced\_script\_module = torch.jit.t…

---

## [Why torch1.13.x JIT compiler doesn't support sm90](https://discuss.pytorch.org/t/why-torch1-13-x-jit-compiler-doesnt-support-sm90/199676)

<div class="topic-metadata">

**Author:** [@Jonson](https://discuss.pytorch.org/u/Jonson)\
**Replies:** 1\
**Last updated:** [March 27, 2024, 12:15pm UTC](https://discuss.pytorch.org/t/why-torch1-13-x-jit-compiler-doesnt-support-sm90/199676 "2024-03-27T12:15:17Z")

</div>

These snippets are in torch.utils.cpp\_extension.py::\_get\_cuda\_arch\_flags. And the latest supported arch is sm\_86.

---

## [How to add Attribute and use after building the model?](https://discuss.pytorch.org/t/how-to-add-attribute-and-use-after-building-the-model/199468)

<div class="topic-metadata">

**Author:** [@Hrridoyv2](https://discuss.pytorch.org/u/Hrridoyv2)\
**Replies:** 0\
**Last updated:** [March 24, 2024, 3:56pm UTC](https://discuss.pytorch.org/t/how-to-add-attribute-and-use-after-building-the-model/199468 "2024-03-24T15:56:25Z")

</div>

I’ve built a neural network model and I’d like to incorporate custom functions, encodeImage and encodeText , for pre-processing data. Ideally, I want these functions to be callable both during model definition and after…

---

## [How to load constant tensors in the model onto GPU?](https://discuss.pytorch.org/t/how-to-load-constant-tensors-in-the-model-onto-gpu/108512)

<div class="topic-metadata">

**Author:** [@vdantu](https://discuss.pytorch.org/u/vdantu)\
**Replies:** 4\
**Last updated:** [March 12, 2024, 1:54am UTC](https://discuss.pytorch.org/t/how-to-load-constant-tensors-in-the-model-onto-gpu/108512 "2024-03-12T01:54:08Z")

</div>

I am facing a weird issue. I am doing the following Freeze a torchvision model on CPU host, which internalizes parameters/weight tensors as constants. Save this frozen module. Try to load and run the model on GPU host…

---

## [Libtorch 2.1.1 build error in linux](https://discuss.pytorch.org/t/libtorch-2-1-1-build-error-in-linux/198469)

<div class="topic-metadata">

**Author:** [@jayden1](https://discuss.pytorch.org/u/jayden1)\
**Replies:** 1\
**Last updated:** [March 9, 2024, 9:14am UTC](https://discuss.pytorch.org/t/libtorch-2-1-1-build-error-in-linux/198469 "2024-03-09T09:14:18Z")

</div>

Hi all, I tried to include torch in my script, by: #include \<torch/script.h\> #include \<torch/torch.h\> but I got the following errors when I tried to build a C++ project using libtorch: In file included from /usr/loc…

---

## [Problem saving nn.Module as a TorchScript module (DLRM model)](https://discuss.pytorch.org/t/problem-saving-nn-module-as-a-torchscript-module-dlrm-model/90338)

<div class="topic-metadata">

**Author:** [@pollo\_loco](https://discuss.pytorch.org/u/pollo_loco)\
**Replies:** 1\
**Last updated:** [March 7, 2024, 6:47pm UTC](https://discuss.pytorch.org/t/problem-saving-nn-module-as-a-torchscript-module-dlrm-model/90338 "2024-03-07T18:47:40Z")

</div>

Hi, I am trying to create a TorchScript module of Facebook’s deep learning recommendation model (DLRM) using torch.jit.script() method. The conversion fails owing to the following runtime error: RuntimeError: cannot ca…

---

## [Export Detectron2 Model](https://discuss.pytorch.org/t/export-detectron2-model/198358)

<div class="topic-metadata">

**Author:** [@anaandreea1228](https://discuss.pytorch.org/u/anaandreea1228)\
**Replies:** 0\
**Last updated:** [March 6, 2024, 6:32pm UTC](https://discuss.pytorch.org/t/export-detectron2-model/198358 "2024-03-06T18:32:17Z")

</div>

Hello! I am trying to export a model from the panoptic-deeplab project that uses detectron2. I want to export it as .pt so that I can load it in LibTorch later on. I want to predit the panoptic segmentation of a single…

---

## [When will \`torch.jit.fork\` create new cuda stream?](https://discuss.pytorch.org/t/when-will-torch-jit-fork-create-new-cuda-stream/198268)

<div class="topic-metadata">

**Author:** [@nahso](https://discuss.pytorch.org/u/nahso)\
**Replies:** 0\
**Last updated:** [March 5, 2024, 2:57pm UTC](https://discuss.pytorch.org/t/when-will-torch-jit-fork-create-new-cuda-stream/198268 "2024-03-05T14:57:09Z")

</div>

I expect there will be two cuda streams to execute these two interaction, but nsys shows this two interactoin execute serially. I wonder how torch.jit.fork is implemented, and when will it create two cuda stream to execu…

---

## [Getting \_ivalue\_ INTERNAL ASSERT FAILED at "../torch/csrc/jit/api/object.h](https://discuss.pytorch.org/t/getting-ivalue-internal-assert-failed-at-torch-csrc-jit-api-object-h/197578)

<div class="topic-metadata">

**Author:** [@glaand](https://discuss.pytorch.org/u/glaand)\
**Replies:** 0\
**Last updated:** [February 23, 2024, 9:57am UTC](https://discuss.pytorch.org/t/getting-ivalue-internal-assert-failed-at-torch-csrc-jit-api-object-h/197578 "2024-02-23T09:57:04Z")

</div>

Hello everybody I am trying to load a torchscript which i’ve generated with python into c++. Now, when trying the tutorial with torchvision.resnet it works fine, i can load the model in c++ and forward an input tensor …

---

## [Error in loading the model](https://discuss.pytorch.org/t/error-in-loading-the-model/84614)

<div class="topic-metadata">

**Author:** [@krrishabh](https://discuss.pytorch.org/u/krrishabh)\
**Replies:** 8\
**Last updated:** [February 23, 2024, 9:52am UTC](https://discuss.pytorch.org/t/error-in-loading-the-model/84614 "2024-02-23T09:52:48Z")

</div>

When I make a small project to check. It works fine… But as soon as I put the same thing in the Kaldi (Pytorch lattice rescoring) and run the executable file then I receive the same error as mentioned below. Error data…

---

## [How to avoid \`intimplicit\` when \`torch.jit.trace\` a Model?](https://discuss.pytorch.org/t/how-to-avoid-intimplicit-when-torch-jit-trace-a-model/197398)

<div class="topic-metadata">

**Author:** [@DavidG](https://discuss.pytorch.org/u/DavidG)\
**Replies:** 1\
**Last updated:** [February 22, 2024, 5:36pm UTC](https://discuss.pytorch.org/t/how-to-avoid-intimplicit-when-torch-jit-trace-a-model/197398 "2024-02-22T17:36:14Z")

</div>

I am trying to convert a PyTorch model to CoreML but CoreML needs a traced model BUT does not support all the ops generated by torch.jit.trace For example, trying to coremltools.converters.convert a traced PyTorch model…

---

## [How to trace external modules for model serialization](https://discuss.pytorch.org/t/how-to-trace-external-modules-for-model-serialization/121931)

<div class="topic-metadata">

**Author:** [@AfonsoSalgadoSousa](https://discuss.pytorch.org/u/AfonsoSalgadoSousa)\
**Replies:** 2\
**Last updated:** [February 19, 2024, 6:45am UTC](https://discuss.pytorch.org/t/how-to-trace-external-modules-for-model-serialization/121931 "2024-02-19T06:45:11Z")

</div>

Hi. I wrote this question tagged as quantization, but the problem seems to be in how to save the model using torch.jit.save while containing external modules. Is this possible? I really appreciate any help you can provid…

---

## [Can I perform jit.trace only on specific layers of a model?](https://discuss.pytorch.org/t/can-i-perform-jit-trace-only-on-specific-layers-of-a-model/197066)

<div class="topic-metadata">

**Author:** [@JimW](https://discuss.pytorch.org/u/JimW)\
**Replies:** 1\
**Last updated:** [February 14, 2024, 3:49pm UTC](https://discuss.pytorch.org/t/can-i-perform-jit-trace-only-on-specific-layers-of-a-model/197066 "2024-02-14T15:49:37Z")

</div>

Hi, I received an JIT version of encoder file from my colleague, and I was appending my own decoder layer (i.e. a simple MLP for classification purpose) on top of it, and I wrapped everything as one module. class Comb…

---

## [LSTM h\_0 & c\_0 storage when using One by one forward step](https://discuss.pytorch.org/t/lstm-h-0-c-0-storage-when-using-one-by-one-forward-step/196832)

<div class="topic-metadata">

**Author:** [@jodunkel](https://discuss.pytorch.org/u/jodunkel)\
**Replies:** 5\
**Last updated:** [February 13, 2024, 11:16am UTC](https://discuss.pytorch.org/t/lstm-h-0-c-0-storage-when-using-one-by-one-forward-step/196832 "2024-02-13T11:16:44Z")

</div>

Hello everyone, I would like to create a real-time anomaly checker for a sensor. To do this, I initialise a self.h\_0 & self.c\_0 in \_\_init\_\_ and with each forward step I save the state in it (very similar to that: https:…

---

## [Torch.jit.save not working on some models from Torchhub](https://discuss.pytorch.org/t/torch-jit-save-not-working-on-some-models-from-torchhub/196777)

<div class="topic-metadata">

**Author:** [@LewsTherin](https://discuss.pytorch.org/u/LewsTherin)\
**Replies:** 0\
**Last updated:** [February 7, 2024, 6:44pm UTC](https://discuss.pytorch.org/t/torch-jit-save-not-working-on-some-models-from-torchhub/196777 "2024-02-07T18:44:37Z")

</div>

Hi! I’m having issues with exporting some models from Torchhub to Torchscript. For example, if I try: model\_name = "x3d\_xs" # this does NOT work model\_name = "i3d\_r50" # this works device = torch.device("cuda:0" if t…

---

## [How can I prevent TorchScript from including the original Python source code?](https://discuss.pytorch.org/t/how-can-i-prevent-torchscript-from-including-the-original-python-source-code/196707)

<div class="topic-metadata">

**Author:** [@michaeleisel](https://discuss.pytorch.org/u/michaeleisel)\
**Replies:** 0\
**Last updated:** [February 6, 2024, 12:31pm UTC](https://discuss.pytorch.org/t/how-can-i-prevent-torchscript-from-including-the-original-python-source-code/196707 "2024-02-06T12:31:45Z")

</div>

I’ve created a model via torch.jit.script(...).save('file.pt') in Python, and want to export it without including the original Python source code at all. This is because the model is going to be deployed on-prem for exte…

---

## [Torch.jit.trace consumes more than 40x gpu memory](https://discuss.pytorch.org/t/torch-jit-trace-consumes-more-than-40x-gpu-memory/191420)

<div class="topic-metadata">

**Author:** [@Junxuan\_Chen](https://discuss.pytorch.org/u/Junxuan_Chen)\
**Replies:** 1\
**Last updated:** [January 31, 2024, 10:11am UTC](https://discuss.pytorch.org/t/torch-jit-trace-consumes-more-than-40x-gpu-memory/191420 "2024-01-31T10:11:45Z")

</div>

I’m using torch.jit.trace to export a vov99 model to torchscript Module on a A100 with 80GB gpu memory. When I inference with the torch original torch.nn.Module model, it works well and only consumes around 2GB gpu memo…

---

## [Replace a specific attribute in RecursiveScriptModule](https://discuss.pytorch.org/t/replace-a-specific-attribute-in-recursivescriptmodule/196119)

<div class="topic-metadata">

**Author:** [@GreyZzzzzzXh](https://discuss.pytorch.org/u/GreyZzzzzzXh)\
**Replies:** 0\
**Last updated:** [January 26, 2024, 1:08pm UTC](https://discuss.pytorch.org/t/replace-a-specific-attribute-in-recursivescriptmodule/196119 "2024-01-26T13:08:27Z")

</div>

import torch from torch import nn class ADD1(nn.Module): def \_\_init\_\_(self): super().\_\_init\_\_() def forward(self, x): return x + 1 class ADD2(nn.Module): def \_\_init\_\_(self): super().…

---

## [Comparison between saving the whole model, saving only state\_dict and torchscript](https://discuss.pytorch.org/t/comparison-between-saving-the-whole-model-saving-only-state-dict-and-torchscript/196033)

<div class="topic-metadata">

**Author:** [@LewsTherin](https://discuss.pytorch.org/u/LewsTherin)\
**Replies:** 3\
**Last updated:** [January 25, 2024, 2:42pm UTC](https://discuss.pytorch.org/t/comparison-between-saving-the-whole-model-saving-only-state-dict-and-torchscript/196033 "2024-01-25T14:42:24Z")

</div>

I’m trying to figure out what’s the best way to save a model trained with Pytorch and load it for inference, and I was wondering about the different possible approaches. Let’s say I successfully train a model, as far as…

[Previous page](https://discuss.pytorch.org/c/jit/13.md?page=1)

[Next page](https://discuss.pytorch.org/c/jit/13.md?page=3)
