# complex

**URL:** https://discuss.pytorch.org/c/complex/22.md

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

---

## [About the complex category](https://discuss.pytorch.org/t/about-the-complex-category/70893)

<div class="topic-metadata">

**Author:** [@albanD](https://discuss.pytorch.org/u/albanD)\
**Replies:** 0

</div>

---

## [How are pretrained weights loaded in nn.LazyLinear layers](https://discuss.pytorch.org/t/how-are-pretrained-weights-loaded-in-nn-lazylinear-layers/222459)

<div class="topic-metadata">

**Author:** [@gk-mixar](https://discuss.pytorch.org/u/gk-mixar)\
**Replies:** 2\
**Last updated:** [August 19, 2025, 10:06am UTC](https://discuss.pytorch.org/t/how-are-pretrained-weights-loaded-in-nn-lazylinear-layers/222459 "2025-08-19T10:06:59Z")

</div>

Hello in a project of mine I am trying to build a linear layer for which the input dim may change depending upon the dataset used. So I am using a nn.lazylinear. However after obtaining the stat\_dict after training whe…

---

## [How to optimize pytorch CNN with complex-numbers (no gradient used)?](https://discuss.pytorch.org/t/how-to-optimize-pytorch-cnn-with-complex-numbers-no-gradient-used/218373)

<div class="topic-metadata">

**Author:** [@Etienne\_Guichard](https://discuss.pytorch.org/u/Etienne_Guichard)\
**Replies:** 0\
**Last updated:** [March 28, 2025, 6:00pm UTC](https://discuss.pytorch.org/t/how-to-optimize-pytorch-cnn-with-complex-numbers-no-gradient-used/218373 "2025-03-28T18:00:40Z")

</div>

Hi, A basic recap of what we are doing. My team and I are building a Cellular Automata program (effectively Convolutional Networks) in PyTorch. Because we are not training them via backprop, we don’t need or use the gra…

---

## [For a model takes custom type as input, can I customize scatter function for DataParallel?](https://discuss.pytorch.org/t/for-a-model-takes-custom-type-as-input-can-i-customize-scatter-function-for-dataparallel/217050)

<div class="topic-metadata">

**Author:** [@liabrarristsh](https://discuss.pytorch.org/u/liabrarristsh)\
**Replies:** 0\
**Last updated:** [February 23, 2025, 8:57am UTC](https://discuss.pytorch.org/t/for-a-model-takes-custom-type-as-input-can-i-customize-scatter-function-for-dataparallel/217050 "2025-02-23T08:57:31Z")

</div>

Mymodel has too much inputs so I’ve created a class MyInput to handle it. The class has many list of tensors as property, and each tensor in the lists is a (batched) input. import torch as pt class MyInput: # batched i…

---

## [Question about implementation of complex Layers](https://discuss.pytorch.org/t/question-about-implementation-of-complex-layers/209467)

<div class="topic-metadata">

**Author:** [@Timwolf01](https://discuss.pytorch.org/u/Timwolf01)\
**Replies:** 2\
**Last updated:** [September 16, 2024, 12:07pm UTC](https://discuss.pytorch.org/t/question-about-implementation-of-complex-layers/209467 "2024-09-16T12:07:33Z")

</div>

I have a question about the implementation of complex Layers, maybe its a duplicate, but havent found a similar. In linear Layer the forward Implementation is x @ w.T + b, made with torch.addmm. With complex data, weig…

---

## [Potential bug in ADAM for complex parameters?](https://discuss.pytorch.org/t/potential-bug-in-adam-for-complex-parameters/189912)

<div class="topic-metadata">

**Author:** [@borisb](https://discuss.pytorch.org/u/borisb)\
**Replies:** 4\
**Last updated:** [November 22, 2023, 3:46pm UTC](https://discuss.pytorch.org/t/potential-bug-in-adam-for-complex-parameters/189912 "2023-11-22T15:46:35Z")

</div>

In the documentation/code of ADAM here I noticed something that seems like an error to me. Even though torch.view\_as\_real is called on grad, grad.conj() is called later for the computation of exp\_avg\_sq. Unless I misunde…

---

## [Pytorch Extension issue](https://discuss.pytorch.org/t/pytorch-extension-issue/161042)

<div class="topic-metadata">

**Author:** [@albertotono](https://discuss.pytorch.org/u/albertotono)\
**Replies:** 2\
**Last updated:** [October 11, 2023, 10:41am UTC](https://discuss.pytorch.org/t/pytorch-extension-issue/161042 "2023-10-11T10:41:02Z")

</div>

I am trying to build this extension GitHub - daerduoCarey/PyTorchEMD: PyTorch Wrapper for Earth-Mover-Distance (EMD) for 3D point cloud regression but I am getting an errors with CUDA 11.1 and Pytorch cuda 11.3. and Pyto…

---

## [Accessing weights in custom layer](https://discuss.pytorch.org/t/accessing-weights-in-custom-layer/189012)

<div class="topic-metadata">

**Author:** [@SantaTitular](https://discuss.pytorch.org/u/SantaTitular)\
**Replies:** 0\
**Last updated:** [September 27, 2023, 12:35am UTC](https://discuss.pytorch.org/t/accessing-weights-in-custom-layer/189012 "2023-09-27T00:35:11Z")

</div>

Hi, I wrote a custom linear layer that allows the use of complex value-data as such: Custom layerdef apply\_complex(fr, fi, input, dtype = torch.complex128): return (fr(input.real)-fi(input.imag)).type(dtype) \\ …

---

## [Error in implementing custom complex-valued layers](https://discuss.pytorch.org/t/error-in-implementing-custom-complex-valued-layers/188552)

<div class="topic-metadata">

**Author:** [@SantaTitular](https://discuss.pytorch.org/u/SantaTitular)\
**Replies:** 2\
**Last updated:** [September 26, 2023, 12:45pm UTC](https://discuss.pytorch.org/t/error-in-implementing-custom-complex-valued-layers/188552 "2023-09-26T12:45:56Z")

</div>

So I’ve been around the use of complex NNs in pytorch for a while, and I’m trying to implement a custom working version based on some available code online that works for complex-valued data. The purpose is to build a AE…

---

## [How to convert numpy.ndarray with data type np.complex128 to a torch tensor?](https://discuss.pytorch.org/t/how-to-convert-numpy-ndarray-with-data-type-np-complex128-to-a-torch-tensor/95233)

<div class="topic-metadata">

**Author:** [@Gautam\_Phadke](https://discuss.pytorch.org/u/Gautam_Phadke)\
**Replies:** 2\
**Last updated:** [August 31, 2023, 8:29am UTC](https://discuss.pytorch.org/t/how-to-convert-numpy-ndarray-with-data-type-np-complex128-to-a-torch-tensor/95233 "2023-08-31T08:29:32Z")

</div>

I have a variable named feature\_data is of type numpy.ndarray, with every element in it being a complex number of form x + yi. How do I convert this to Torch tensor? When I use the following syntax: torch.from\_numpy(fea…

---

## [Profiler not working in multi-threaded scenario](https://discuss.pytorch.org/t/profiler-not-working-in-multi-threaded-scenario/187449)

<div class="topic-metadata">

**Author:** [@joshua\_marqo](https://discuss.pytorch.org/u/joshua_marqo)\
**Replies:** 0\
**Last updated:** [August 31, 2023, 3:35am UTC](https://discuss.pytorch.org/t/profiler-not-working-in-multi-threaded-scenario/187449 "2023-08-31T03:35:52Z")

</div>

With Torch 2.1.0, my multi-threaded program does not work as intended when trying to profile it with the profiler. Code I am trying to profile: import argparse import threading import time from typing import List, Tuple…

---

## [Problem with complex tensors](https://discuss.pytorch.org/t/problem-with-complex-tensors/156326)

<div class="topic-metadata">

**Author:** [@nowitzki18](https://discuss.pytorch.org/u/nowitzki18)\
**Replies:** 5\
**Last updated:** [July 22, 2023, 2:19pm UTC](https://discuss.pytorch.org/t/problem-with-complex-tensors/156326 "2023-07-22T14:19:47Z")

</div>

Hi, I’m trying to implement a Fourier unit as a part of a model for object detection. The original code written by the paper’s author uses an old version of pytorch that using the torch.rfft() and torch.irfft() methods, …

---

## [DataParallel or DistributedDataParallel workaround](https://discuss.pytorch.org/t/dataparallel-or-distributeddataparallel-workaround/184279)

<div class="topic-metadata">

**Author:** [@SmoothKen](https://discuss.pytorch.org/u/SmoothKen)\
**Replies:** 0\
**Last updated:** [July 15, 2023, 8:36am UTC](https://discuss.pytorch.org/t/dataparallel-or-distributeddataparallel-workaround/184279 "2023-07-15T08:36:42Z")

</div>

Hi, For a complex model, DistributedDataParallel does not work as the support is not yet there as of 06/23. DataParallel throws me something like RuntimeError: Input type (CUDAComplexFloatType) and weight type (torch.c…

---

## [Warping layer in PWC-Net](https://discuss.pytorch.org/t/warping-layer-in-pwc-net/183831)

<div class="topic-metadata">

**Author:** [@hosein\_warp](https://discuss.pytorch.org/u/hosein_warp)\
**Replies:** 0\
**Last updated:** [July 10, 2023, 9:02am UTC](https://discuss.pytorch.org/t/warping-layer-in-pwc-net/183831 "2023-07-10T09:02:56Z")

</div>

i am researching about PWC\_Net from below paper: i am confused in "warping layer " section in this paper. please explain me in simple words about warping layer thanks a lot.

---

## [Gradient mismatch for complex networks using nn.DataParallel](https://discuss.pytorch.org/t/gradient-mismatch-for-complex-networks-using-nn-dataparallel/174728)

<div class="topic-metadata">

**Author:** [@Minennick](https://discuss.pytorch.org/u/Minennick)\
**Replies:** 5\
**Last updated:** [May 15, 2023, 1:33pm UTC](https://discuss.pytorch.org/t/gradient-mismatch-for-complex-networks-using-nn-dataparallel/174728 "2023-05-15T13:33:48Z")

</div>

Dear all, I am currently building a network that gets complex numbers as input, processes them using complex layers, and gives back again complex numbers. I already recognized, that passing the input to the model, cause…

---

## [Complex numbers - Cuda 11.6 documentation warning](https://discuss.pytorch.org/t/complex-numbers-cuda-11-6-documentation-warning/178588)

<div class="topic-metadata">

**Author:** [@Danfoa](https://discuss.pytorch.org/u/Danfoa)\
**Replies:** 1\
**Last updated:** [April 26, 2023, 7:17pm UTC](https://discuss.pytorch.org/t/complex-numbers-cuda-11-6-documentation-warning/178588 "2023-04-26T19:17:08Z")

</div>

Documentation on Complex numbers has a note indicating that the user should use Cuda 11.6 without additional information on why this is recommended. Cuda 11.6 is considerably old and does not support new OS versions (e.…

---

## [Some tensors getting left on CPU despite calling model.to("cuda")](https://discuss.pytorch.org/t/some-tensors-getting-left-on-cpu-despite-calling-model-to-cuda/112915)

<div class="topic-metadata">

**Author:** [@gabriel-earle](https://discuss.pytorch.org/u/gabriel-earle)\
**Replies:** 6\
**Last updated:** [April 4, 2023, 6:58am UTC](https://discuss.pytorch.org/t/some-tensors-getting-left-on-cpu-despite-calling-model-to-cuda/112915 "2023-04-04T06:58:52Z")

</div>

Hello, Would like to politely request another set of eyes on some problems we’re running into trying to train our model. Background: We’re using complex64 dtype tensors generated from torchaudio stft(). We are using a…

---

## [Best practice for complex/float operations](https://discuss.pytorch.org/t/best-practice-for-complex-float-operations/171745)

<div class="topic-metadata">

**Author:** [@Ronan\_Gautier](https://discuss.pytorch.org/u/Ronan_Gautier)\
**Replies:** 0\
**Last updated:** [February 3, 2023, 4:05pm UTC](https://discuss.pytorch.org/t/best-practice-for-complex-float-operations/171745 "2023-02-03T16:05:50Z")

</div>

If I want to operate on both float and complex-valued tensors, what is the best practice? Should everything be in complex format throughout computation? Or is it fine and efficient to multiply float and complex tensors t…

---

## [Converting ComplexFloat to Float at the Last Layer](https://discuss.pytorch.org/t/converting-complexfloat-to-float-at-the-last-layer/168412)

<div class="topic-metadata">

**Author:** [@SantaTitular](https://discuss.pytorch.org/u/SantaTitular)\
**Replies:** 1\
**Last updated:** [December 16, 2022, 12:07am UTC](https://discuss.pytorch.org/t/converting-complexfloat-to-float-at-the-last-layer/168412 "2022-12-16T00:07:13Z")

</div>

Hello, I’m developing an FFN for classification of complex-valued data. As such, need the output of the NN to be real (so I can make the classification). Here, there are several Examples of Possible Softmax Functions. T…

---

## [Warning about complex casting in Copy.cpp](https://discuss.pytorch.org/t/warning-about-complex-casting-in-copy-cpp/166416)

<div class="topic-metadata">

**Author:** [@tito21](https://discuss.pytorch.org/u/tito21)\
**Replies:** 2\
**Last updated:** [November 22, 2022, 5:07pm UTC](https://discuss.pytorch.org/t/warning-about-complex-casting-in-copy-cpp/166416 "2022-11-22T17:07:33Z")

</div>

Hello, My network uses a 2 value tensor to represent complex numbers. In an intermediate state, cast the numbers to a complex tensor for calculating an FFT and then moves them back to a 2 value tensor to continue proces…

---

## [Pytorch Geometric - Loss always 'NaN'](https://discuss.pytorch.org/t/pytorch-geometric-loss-always-nan/161933)

<div class="topic-metadata">

**Author:** [@Akash\_142](https://discuss.pytorch.org/u/Akash_142)\
**Replies:** 0\
**Last updated:** [September 22, 2022, 1:52am UTC](https://discuss.pytorch.org/t/pytorch-geometric-loss-always-nan/161933 "2022-09-22T01:52:22Z")

</div>

Hello, I am training a simple GCN model. For some reason, my loss is always NaN from the beginning. Please let me know if you need the whole code and data. Thank you! Here is my data: Num\_graphs = 800 X (num\_nodes,…

---

## [Extracting metadata from PDF](https://discuss.pytorch.org/t/extracting-metadata-from-pdf/159544)

<div class="topic-metadata">

**Author:** [@MagaMakhauri](https://discuss.pytorch.org/u/MagaMakhauri)\
**Replies:** 0\
**Last updated:** [August 19, 2022, 6:52am UTC](https://discuss.pytorch.org/t/extracting-metadata-from-pdf/159544 "2022-08-19T06:52:11Z")

</div>

Hi! I have used PyPDF2 with regex to extract metadata from different invoice PDFs my company recieves. Then I tried tesseract-ocr and thought some manipulation improved the ‘PDF reading capabilities’ But its still not …

---

## [Convert complex to bool](https://discuss.pytorch.org/t/convert-complex-to-bool/157477)

<div class="topic-metadata">

**Author:** [@desktoop](https://discuss.pytorch.org/u/desktoop)\
**Replies:** 3\
**Last updated:** [July 27, 2022, 4:04am UTC](https://discuss.pytorch.org/t/convert-complex-to-bool/157477 "2022-07-27T04:04:38Z")

</div>

When I try to convert a complex data to bool, I found the results are not what I expect. For example: \>\>\> t = torch.tensor(\[1+1j, 0+1j, 1+0j\]) \>\>\> t.to(torch.bool) and then I get this: \<ipython-input-3-666889c1a9fa\>:…

---

## [Implementation of complex-valued activation functions](https://discuss.pytorch.org/t/implementation-of-complex-valued-activation-functions/157434)

<div class="topic-metadata">

**Author:** [@SantaTitular](https://discuss.pytorch.org/u/SantaTitular)\
**Replies:** 0\
**Last updated:** [July 25, 2022, 11:10am UTC](https://discuss.pytorch.org/t/implementation-of-complex-valued-activation-functions/157434 "2022-07-25T11:10:00Z")

</div>

I’m working with complex-valued activation functions and, similarly to discussions at #47052, I am interested in knowing what type of function does the ReLu (and others such as tanh, sigmoid, etc. Complex Activation Func…

---

## [Backward() compatibility with custom complex CrossEntropyLoss](https://discuss.pytorch.org/t/backward-compatibility-with-custom-complex-crossentropyloss/157262)

<div class="topic-metadata">

**Author:** [@SantaTitular](https://discuss.pytorch.org/u/SantaTitular)\
**Replies:** 1\
**Last updated:** [July 22, 2022, 5:20pm UTC](https://discuss.pytorch.org/t/backward-compatibility-with-custom-complex-crossentropyloss/157262 "2022-07-22T17:20:03Z")

</div>

I started discussion this topic in issue #81950. Basically, I have designed a custom CrossEntropyLoss function to work with complex-valued data (remote sensing, signal processing, etc.), and I designed a simple FNN. Howe…

---

## [FFT2 Input range](https://discuss.pytorch.org/t/fft2-input-range/155241)

<div class="topic-metadata">

**Author:** [@callbarian](https://discuss.pytorch.org/u/callbarian)\
**Replies:** 0\
**Last updated:** [June 28, 2022, 10:10am UTC](https://discuss.pytorch.org/t/fft2-input-range/155241 "2022-06-28T10:10:47Z")

</div>

According to the document 1.8.0-fft2, two ffts and fft2 should be allclose It is true when input range is 0~1. When input range is above 1 (ex.0~25), first row and first column are allclose but the rest of them are no…

---

## [Uncertainty Estimation](https://discuss.pytorch.org/t/uncertainty-estimation/151040)

<div class="topic-metadata">

**Author:** [@Nerolf05](https://discuss.pytorch.org/u/Nerolf05)\
**Replies:** 0\
**Last updated:** [May 7, 2022, 8:03pm UTC](https://discuss.pytorch.org/t/uncertainty-estimation/151040 "2022-05-07T20:03:55Z")

</div>

Hello together, I am trying to estimate a conservative description of distribution p(y|x) (see image) So far I am working with a MixtureDensityNetwork (estimating only 1 gaussian mixture and a negLogLikelihoodGaussi…

---

## [Emerging 2 different models to create a multi-model](https://discuss.pytorch.org/t/emerging-2-different-models-to-create-a-multi-model/146924)

<div class="topic-metadata">

**Author:** [@tnguyen87](https://discuss.pytorch.org/u/tnguyen87)\
**Replies:** 7\
**Last updated:** [April 28, 2022, 5:32am UTC](https://discuss.pytorch.org/t/emerging-2-different-models-to-create-a-multi-model/146924 "2022-04-28T05:32:29Z")

</div>

Greetings, I have 2 different models - A (GNN) and B (LSTM). I am trying to combine these models to predict the same output “y”. These models only share the same input and output only. I found 2 different posts (Merging…

---

## [Model.forward() automatically converts complex128 \[a+bj\] to stacked complex form \[a,b\]](https://discuss.pytorch.org/t/model-forward-automatically-converts-complex128-a-bj-to-stacked-complex-form-a-b/149413)

<div class="topic-metadata">

**Author:** [@C\_J](https://discuss.pytorch.org/u/C_J)\
**Replies:** 1\
**Last updated:** [April 18, 2022, 4:54am UTC](https://discuss.pytorch.org/t/model-forward-automatically-converts-complex128-a-bj-to-stacked-complex-form-a-b/149413 "2022-04-18T04:54:34Z")

</div>

Just before the return, the output format is complex128, but in the forloop during the training the output is automatically converted to stacked complex form. Just as below: def forward(self, input): output…

---

## [Same model, weight, input data, but output is different](https://discuss.pytorch.org/t/same-model-weight-input-data-but-output-is-different/147759)

<div class="topic-metadata">

**Author:** [@gongmil](https://discuss.pytorch.org/u/gongmil)\
**Replies:** 2\
**Last updated:** [March 30, 2022, 4:00am UTC](https://discuss.pytorch.org/t/same-model-weight-input-data-but-output-is-different/147759 "2022-03-30T04:00:14Z")

</div>

Hello, i have simple FCN network for learning. within a single epoch, the output while learning in the model.train() is different from the output when the all batch loop is ending. Also changing model.train() to model…

[Next page](https://discuss.pytorch.org/c/complex/22.md?page=1)
