# FAQ

**URL:** https://discuss.pytorch.org/c/faq/30.md

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

---

## [About the FAQ category](https://discuss.pytorch.org/t/about-the-faq-category/111452)

<div class="topic-metadata">

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

</div>

The FAQ category contains commonly-asked questions and their answers. Please refer to this section before you post your query. The topics here are closed to replying. For follow-up questions, start a new topic in the re…

---

## [How do I get the accuracy of an unbalanced dataset or segmentation task?](https://discuss.pytorch.org/t/how-do-i-get-the-accuracy-of-an-unbalanced-dataset-or-segmentation-task/194579)

<div class="topic-metadata">

**Author:** [@J\_Johnson](https://discuss.pytorch.org/u/J_Johnson)\
**Replies:** 1\
**Last updated:** [July 30, 2024, 2:00pm UTC](https://discuss.pytorch.org/t/how-do-i-get-the-accuracy-of-an-unbalanced-dataset-or-segmentation-task/194579 "2024-07-30T14:00:47Z")

</div>

This post is to define a Class Weighted Accuracy function(WCA). As questions related to this get asked often, I thought it might help people to post a tool torchers can use and reference here. Why? Take, for example, a…

---

## [How to measure execution time in PyTorch?](https://discuss.pytorch.org/t/how-to-measure-execution-time-in-pytorch/111458)

<div class="topic-metadata">

**Author:** [@suraj.pt](https://discuss.pytorch.org/u/suraj.pt)\
**Replies:** 0\
**Last updated:** [February 9, 2021, 8:26pm UTC](https://discuss.pytorch.org/t/how-to-measure-execution-time-in-pytorch/111458 "2021-02-09T20:26:33Z")

</div>

tl;dr The recommended profiling methods are: torch.profiler: API Docs Profiler Tutorial Profiler Recipe torch.utils.benchmark: API docs Benchmark Recipe CPU-only benchmarking CPU operations are synchronous; you can …

---

## [Why are my tensor's gradients unexpectedly None or not None?](https://discuss.pytorch.org/t/why-are-my-tensors-gradients-unexpectedly-none-or-not-none/111461)

<div class="topic-metadata">

**Author:** [@suraj.pt](https://discuss.pytorch.org/u/suraj.pt)\
**Replies:** 0\
**Last updated:** [February 9, 2021, 9:16pm UTC](https://discuss.pytorch.org/t/why-are-my-tensors-gradients-unexpectedly-none-or-not-none/111461 "2021-02-09T21:16:53Z")

</div>

tl;dr Ensure that tensor.is\_leaf == True tensor.requires\_grad == True. tensor.grad\_fn is None; if it is not None, you need to retain\_grad(). gradient computation is not disabled using torch.no\_grad() context manager …

---

## [Time/Memory keeps increasing at every iteration](https://discuss.pytorch.org/t/time-memory-keeps-increasing-at-every-iteration/111453)

<div class="topic-metadata">

**Author:** [@suraj.pt](https://discuss.pytorch.org/u/suraj.pt)\
**Replies:** 0\
**Last updated:** [February 9, 2021, 8:03pm UTC](https://discuss.pytorch.org/t/time-memory-keeps-increasing-at-every-iteration/111453 "2021-02-09T20:03:36Z")

</div>

How are you measuring time? If each new iteration is taking longer, first make sure you’re measuring run time accurately https://discuss.pytorch.org/t/how-to-measure-execution-time-in-pytorch/111458. Without properly syn…

---

## [Precision / Determinism / Reproducibility Issues](https://discuss.pytorch.org/t/precision-determinism-reproducibility-issues/111462)

<div class="topic-metadata">

**Author:** [@suraj.pt](https://discuss.pytorch.org/u/suraj.pt)\
**Replies:** 0\
**Last updated:** [February 9, 2021, 9:23pm UTC](https://discuss.pytorch.org/t/precision-determinism-reproducibility-issues/111462 "2021-02-09T21:23:11Z")

</div>

Floating point precision Floating point precision limits the number of digits you can accurately rely on. torch.float32 has precision between 6 and 7 digits regardless of exponent, i.e. precision issues are expected for…
