Skip to content

Update tensor factory method docs - #6640

Merged
zou3519 merged 2 commits into
pytorch:masterfrom
zou3519:factory-methods
Apr 17, 2018
Merged

zou3519 merged 2 commits into
pytorch:masterfrom
zou3519:factory-methods

Conversation

@zou3519

@zou3519 zou3519 commented Apr 16, 2018

Copy link
Copy Markdown
Contributor

Also add new docs for torch.empty.

cc @gchanan @ssnl

Also add new docs for `torch.empty`.
@ssnl

ssnl commented Apr 17, 2018

Copy link
Copy Markdown
Collaborator

Cool! Can you also add full and full_like please? :)

@ezyang

ezyang commented Apr 17, 2018

Copy link
Copy Markdown
Contributor

I'm wondering if there's a reasonable way we can avoid copy-pasting the same block of three arguments to every site. Maybe not...

@zou3519

zou3519 commented Apr 17, 2018

Copy link
Copy Markdown
Contributor Author

@ezyang I could link them to a "explanation of tensor factory method arguments" section or page, but the descriptions are brief enough that linking them somewhere else might be confusing.

@ssnl thanks, I didn't know those existed

@zou3519

zou3519 commented Apr 17, 2018

Copy link
Copy Markdown
Contributor Author

Oh! Docstrings are strings so I could just add them together... Will look into it

@zou3519

zou3519 commented Apr 17, 2018

Copy link
Copy Markdown
Contributor Author

@gchanan how does this look to you?

@zou3519
zou3519 merged commit 1f2829d into pytorch:master Apr 17, 2018
Jorghi12 pushed a commit to wsttiger/pytorch that referenced this pull request May 10, 2018
* Update tensor factory method docs

Also add new docs for `torch.empty`.

* Add full; some refactoring to make docs nicer
atalman added a commit to atalman/pytorch that referenced this pull request Jul 7, 2026
…ch` deadlock (pytorch#189110)

`import torch` from ROCm 2.13 wheels intermittently hangs forever on hosts
without a usable GPU / kfd (CPU-only nodes, or GPU nodes without amdgpu/amdkfd
loaded). Root cause chain (native backtrace):

  import torch -> dlopen(_C) -> static init of libtorch_rocshmem.so
    -> rocshmem::NUMAWrapper::NUMAWrapper()   (upstream rocSHMEM global ctor)
       -> dlopen("libnuma.so")  == NULL       -> exit(1)
          -> atexit -> rocprofiler::registration::finalize()
             -> ThreadPool::destroy_threadpool() -> std::thread::join()   # HANGS

Why it regressed at pytorch#182696: the old build_rocm.sh renamed bundled OS deps to
bare sonames, so torch/lib shipped `libnuma.so`. The new repair_wheel.py keeps
them versioned (`libnuma.so.1`) only. rocSHMEM's NUMAWrapper ctor does
`dlopen("libnuma.so")` (bare) via libtorch_rocshmem.so's $ORIGIN RPATH; with
only `libnuma.so.1` present that dlopen fails and NUMAWrapper calls exit() at
library-load time, which trips a racy rocprofiler-sdk atexit finalize deadlock
(hence the intermittency). The good (0513) wheel shipped bare `libnuma.so` and
never hangs; the bad (0514+) wheel ships only `libnuma.so.1` and does.

Fix: when bundling a versioned OS dep, also create a bare-name symlink
(libnuma.so -> libnuma.so.1, etc.), restoring build_rocm.sh behavior. The bare
symlink satisfies rocSHMEM's dlopen while the versioned file still satisfies
NEEDED references. Verified: adding this symlink to an installed wheel makes
`import torch` succeed deterministically on a no-kfd host.

The underlying rocSHMEM bug (NUMAWrapper must not exit() from a global ctor;
should dlopen "libnuma.so.1") is fixed upstream after our pinned commit
(ROCm/rocm-systems pytorch#5918, pytorch#6640) and should be picked up via a pin bump too.
pytorchmergebot pushed a commit that referenced this pull request Jul 8, 2026
…ock (#189114)

## Summary

`import torch` from ROCm 2.13 wheels **intermittently hangs forever** on hosts without a usable GPU / kfd (CPU-only nodes, or GPU nodes where `amdgpu`/`amdkfd` isn't loaded). Fixes #189110.

This is related to this fix PR in upstream: ROCm/rocm-systems#6640 (this is not included in pytorch, hence a failure)

### Root cause (native backtrace)
```
import torch → dlopen(_C) → static init of libtorch_rocshmem.so
  → rocshmem::NUMAWrapper::NUMAWrapper()          (upstream rocSHMEM global ctor)
     → dlopen("libnuma.so") == NULL  →  exit(1)    (at library-load time!)
        → atexit → rocprofiler::registration::finalize()
           → ThreadPool::destroy_threadpool() → std::thread::join()   # HANGS
```

### Why it regressed here (and why 0513 was fine but 0514 hangs)
This is a **packaging** regression from the ROCm manywheel pipeline port (#182696), not the rocSHMEM binary:

| | bundled `libnuma` | `dlopen("libnuma.so")` from `$ORIGIN` | result |
|---|---|---|---|
| old `build_rocm.sh` (0513) | **`libnuma.so`** (bare) | resolves | ✅ no `exit()` → never hangs |
| new `repair_wheel.py` (0514+) | **`libnuma.so.1`** only | fails (no bare name in-wheel) | ❌ `exit(1)` → rocprofiler atexit deadlock → intermittent hang |

The old `build_rocm.sh` renamed bundled OS deps to **bare** sonames, so `torch/lib` shipped `libnuma.so`. `repair_wheel.py` keeps them **versioned** (`libnuma.so.1`). rocSHMEM's `NUMAWrapper` global ctor does `dlopen("libnuma.so")` (bare) via `libtorch_rocshmem.so`'s `$ORIGIN` RPATH — with only `libnuma.so.1` present it fails and `exit(1)`s at load, tripping a **racy** rocprofiler-sdk atexit `finalize()` deadlock (hence the intermittency; the `agent.cpp:608` kfd warning is a red herring). Same rocSHMEM binary in both wheels — only the bundled `libnuma` filename differs.

## Fix
When bundling a versioned OS dep, also create a **bare-name symlink** (`libnuma.so` → `libnuma.so.1`, etc.), restoring `build_rocm.sh` behavior. The bare symlink satisfies rocSHMEM's `dlopen`; the versioned file still satisfies `NEEDED` references.

**Verified:** adding this symlink to an installed wheel makes `import torch` succeed deterministically on a no-`kfd` host (loop-tested; the hang no longer reproduces).

## Follow-ups (upstream)
The underlying rocSHMEM bug — `NUMAWrapper` must not `exit()` from a global constructor, and should `dlopen("libnuma.so.1")` — is already fixed upstream *after* PyTorch's pinned commit (`cb8a2d6`): ROCm/rocm-systems **#5918** (runtime numalib check) and **#6640** (link numa directly, no `dlopen` — removes `numa_wrapper.cpp`). Bumping `ROCSHMEM_VERSION` in `.ci/docker/common/install_rocSHMEM.sh` would also fix it and is worth doing separately. The rocprofiler-sdk atexit `finalize()` deadlock ("does not exit cleanly") is a separate AMD-side bug.

Pull Request resolved: #189114
Approved by: https://github.com/huydhn, https://github.com/albanD
vishalgoyal316 pushed a commit to vishalgoyal316/pytorch that referenced this pull request Jul 16, 2026
…ock (pytorch#189114)

## Summary

`import torch` from ROCm 2.13 wheels **intermittently hangs forever** on hosts without a usable GPU / kfd (CPU-only nodes, or GPU nodes where `amdgpu`/`amdkfd` isn't loaded). Fixes pytorch#189110.

This is related to this fix PR in upstream: ROCm/rocm-systems#6640 (this is not included in pytorch, hence a failure)

### Root cause (native backtrace)
```
import torch → dlopen(_C) → static init of libtorch_rocshmem.so
  → rocshmem::NUMAWrapper::NUMAWrapper()          (upstream rocSHMEM global ctor)
     → dlopen("libnuma.so") == NULL  →  exit(1)    (at library-load time!)
        → atexit → rocprofiler::registration::finalize()
           → ThreadPool::destroy_threadpool() → std::thread::join()   # HANGS
```

### Why it regressed here (and why 0513 was fine but 0514 hangs)
This is a **packaging** regression from the ROCm manywheel pipeline port (pytorch#182696), not the rocSHMEM binary:

| | bundled `libnuma` | `dlopen("libnuma.so")` from `$ORIGIN` | result |
|---|---|---|---|
| old `build_rocm.sh` (0513) | **`libnuma.so`** (bare) | resolves | ✅ no `exit()` → never hangs |
| new `repair_wheel.py` (0514+) | **`libnuma.so.1`** only | fails (no bare name in-wheel) | ❌ `exit(1)` → rocprofiler atexit deadlock → intermittent hang |

The old `build_rocm.sh` renamed bundled OS deps to **bare** sonames, so `torch/lib` shipped `libnuma.so`. `repair_wheel.py` keeps them **versioned** (`libnuma.so.1`). rocSHMEM's `NUMAWrapper` global ctor does `dlopen("libnuma.so")` (bare) via `libtorch_rocshmem.so`'s `$ORIGIN` RPATH — with only `libnuma.so.1` present it fails and `exit(1)`s at load, tripping a **racy** rocprofiler-sdk atexit `finalize()` deadlock (hence the intermittency; the `agent.cpp:608` kfd warning is a red herring). Same rocSHMEM binary in both wheels — only the bundled `libnuma` filename differs.

## Fix
When bundling a versioned OS dep, also create a **bare-name symlink** (`libnuma.so` → `libnuma.so.1`, etc.), restoring `build_rocm.sh` behavior. The bare symlink satisfies rocSHMEM's `dlopen`; the versioned file still satisfies `NEEDED` references.

**Verified:** adding this symlink to an installed wheel makes `import torch` succeed deterministically on a no-`kfd` host (loop-tested; the hang no longer reproduces).

## Follow-ups (upstream)
The underlying rocSHMEM bug — `NUMAWrapper` must not `exit()` from a global constructor, and should `dlopen("libnuma.so.1")` — is already fixed upstream *after* PyTorch's pinned commit (`cb8a2d6`): ROCm/rocm-systems **pytorch#5918** (runtime numalib check) and **pytorch#6640** (link numa directly, no `dlopen` — removes `numa_wrapper.cpp`). Bumping `ROCSHMEM_VERSION` in `.ci/docker/common/install_rocSHMEM.sh` would also fix it and is worth doing separately. The rocprofiler-sdk atexit `finalize()` deadlock ("does not exit cleanly") is a separate AMD-side bug.

Pull Request resolved: pytorch#189114
Approved by: https://github.com/huydhn, https://github.com/albanD
DamJanusz pushed a commit to DamJanusz/pytorch that referenced this pull request Jul 21, 2026
…ock (pytorch#189114)

## Summary

`import torch` from ROCm 2.13 wheels **intermittently hangs forever** on hosts without a usable GPU / kfd (CPU-only nodes, or GPU nodes where `amdgpu`/`amdkfd` isn't loaded). Fixes pytorch#189110.

This is related to this fix PR in upstream: ROCm/rocm-systems#6640 (this is not included in pytorch, hence a failure)

### Root cause (native backtrace)
```
import torch → dlopen(_C) → static init of libtorch_rocshmem.so
  → rocshmem::NUMAWrapper::NUMAWrapper()          (upstream rocSHMEM global ctor)
     → dlopen("libnuma.so") == NULL  →  exit(1)    (at library-load time!)
        → atexit → rocprofiler::registration::finalize()
           → ThreadPool::destroy_threadpool() → std::thread::join()   # HANGS
```

### Why it regressed here (and why 0513 was fine but 0514 hangs)
This is a **packaging** regression from the ROCm manywheel pipeline port (pytorch#182696), not the rocSHMEM binary:

| | bundled `libnuma` | `dlopen("libnuma.so")` from `$ORIGIN` | result |
|---|---|---|---|
| old `build_rocm.sh` (0513) | **`libnuma.so`** (bare) | resolves | ✅ no `exit()` → never hangs |
| new `repair_wheel.py` (0514+) | **`libnuma.so.1`** only | fails (no bare name in-wheel) | ❌ `exit(1)` → rocprofiler atexit deadlock → intermittent hang |

The old `build_rocm.sh` renamed bundled OS deps to **bare** sonames, so `torch/lib` shipped `libnuma.so`. `repair_wheel.py` keeps them **versioned** (`libnuma.so.1`). rocSHMEM's `NUMAWrapper` global ctor does `dlopen("libnuma.so")` (bare) via `libtorch_rocshmem.so`'s `$ORIGIN` RPATH — with only `libnuma.so.1` present it fails and `exit(1)`s at load, tripping a **racy** rocprofiler-sdk atexit `finalize()` deadlock (hence the intermittency; the `agent.cpp:608` kfd warning is a red herring). Same rocSHMEM binary in both wheels — only the bundled `libnuma` filename differs.

## Fix
When bundling a versioned OS dep, also create a **bare-name symlink** (`libnuma.so` → `libnuma.so.1`, etc.), restoring `build_rocm.sh` behavior. The bare symlink satisfies rocSHMEM's `dlopen`; the versioned file still satisfies `NEEDED` references.

**Verified:** adding this symlink to an installed wheel makes `import torch` succeed deterministically on a no-`kfd` host (loop-tested; the hang no longer reproduces).

## Follow-ups (upstream)
The underlying rocSHMEM bug — `NUMAWrapper` must not `exit()` from a global constructor, and should `dlopen("libnuma.so.1")` — is already fixed upstream *after* PyTorch's pinned commit (`cb8a2d6`): ROCm/rocm-systems **pytorch#5918** (runtime numalib check) and **pytorch#6640** (link numa directly, no `dlopen` — removes `numa_wrapper.cpp`). Bumping `ROCSHMEM_VERSION` in `.ci/docker/common/install_rocSHMEM.sh` would also fix it and is worth doing separately. The rocprofiler-sdk atexit `finalize()` deadlock ("does not exit cleanly") is a separate AMD-side bug.

Pull Request resolved: pytorch#189114
Approved by: https://github.com/huydhn, https://github.com/albanD
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…ock (pytorch#189114)

## Summary

`import torch` from ROCm 2.13 wheels **intermittently hangs forever** on hosts without a usable GPU / kfd (CPU-only nodes, or GPU nodes where `amdgpu`/`amdkfd` isn't loaded). Fixes pytorch#189110.

This is related to this fix PR in upstream: ROCm/rocm-systems#6640 (this is not included in pytorch, hence a failure)

### Root cause (native backtrace)
```
import torch → dlopen(_C) → static init of libtorch_rocshmem.so
  → rocshmem::NUMAWrapper::NUMAWrapper()          (upstream rocSHMEM global ctor)
     → dlopen("libnuma.so") == NULL  →  exit(1)    (at library-load time!)
        → atexit → rocprofiler::registration::finalize()
           → ThreadPool::destroy_threadpool() → std::thread::join()   # HANGS
```

### Why it regressed here (and why 0513 was fine but 0514 hangs)
This is a **packaging** regression from the ROCm manywheel pipeline port (pytorch#182696), not the rocSHMEM binary:

| | bundled `libnuma` | `dlopen("libnuma.so")` from `$ORIGIN` | result |
|---|---|---|---|
| old `build_rocm.sh` (0513) | **`libnuma.so`** (bare) | resolves | ✅ no `exit()` → never hangs |
| new `repair_wheel.py` (0514+) | **`libnuma.so.1`** only | fails (no bare name in-wheel) | ❌ `exit(1)` → rocprofiler atexit deadlock → intermittent hang |

The old `build_rocm.sh` renamed bundled OS deps to **bare** sonames, so `torch/lib` shipped `libnuma.so`. `repair_wheel.py` keeps them **versioned** (`libnuma.so.1`). rocSHMEM's `NUMAWrapper` global ctor does `dlopen("libnuma.so")` (bare) via `libtorch_rocshmem.so`'s `$ORIGIN` RPATH — with only `libnuma.so.1` present it fails and `exit(1)`s at load, tripping a **racy** rocprofiler-sdk atexit `finalize()` deadlock (hence the intermittency; the `agent.cpp:608` kfd warning is a red herring). Same rocSHMEM binary in both wheels — only the bundled `libnuma` filename differs.

## Fix
When bundling a versioned OS dep, also create a **bare-name symlink** (`libnuma.so` → `libnuma.so.1`, etc.), restoring `build_rocm.sh` behavior. The bare symlink satisfies rocSHMEM's `dlopen`; the versioned file still satisfies `NEEDED` references.

**Verified:** adding this symlink to an installed wheel makes `import torch` succeed deterministically on a no-`kfd` host (loop-tested; the hang no longer reproduces).

## Follow-ups (upstream)
The underlying rocSHMEM bug — `NUMAWrapper` must not `exit()` from a global constructor, and should `dlopen("libnuma.so.1")` — is already fixed upstream *after* PyTorch's pinned commit (`cb8a2d6`): ROCm/rocm-systems **pytorch#5918** (runtime numalib check) and **pytorch#6640** (link numa directly, no `dlopen` — removes `numa_wrapper.cpp`). Bumping `ROCSHMEM_VERSION` in `.ci/docker/common/install_rocSHMEM.sh` would also fix it and is worth doing separately. The rocprofiler-sdk atexit `finalize()` deadlock ("does not exit cleanly") is a separate AMD-side bug.

Pull Request resolved: pytorch#189114
Approved by: https://github.com/huydhn, https://github.com/albanD
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ock (pytorch#189114)

## Summary

`import torch` from ROCm 2.13 wheels **intermittently hangs forever** on hosts without a usable GPU / kfd (CPU-only nodes, or GPU nodes where `amdgpu`/`amdkfd` isn't loaded). Fixes pytorch#189110.

This is related to this fix PR in upstream: ROCm/rocm-systems#6640 (this is not included in pytorch, hence a failure)

### Root cause (native backtrace)
```
import torch → dlopen(_C) → static init of libtorch_rocshmem.so
  → rocshmem::NUMAWrapper::NUMAWrapper()          (upstream rocSHMEM global ctor)
     → dlopen("libnuma.so") == NULL  →  exit(1)    (at library-load time!)
        → atexit → rocprofiler::registration::finalize()
           → ThreadPool::destroy_threadpool() → std::thread::join()   # HANGS
```

### Why it regressed here (and why 0513 was fine but 0514 hangs)
This is a **packaging** regression from the ROCm manywheel pipeline port (pytorch#182696), not the rocSHMEM binary:

| | bundled `libnuma` | `dlopen("libnuma.so")` from `$ORIGIN` | result |
|---|---|---|---|
| old `build_rocm.sh` (0513) | **`libnuma.so`** (bare) | resolves | ✅ no `exit()` → never hangs |
| new `repair_wheel.py` (0514+) | **`libnuma.so.1`** only | fails (no bare name in-wheel) | ❌ `exit(1)` → rocprofiler atexit deadlock → intermittent hang |

The old `build_rocm.sh` renamed bundled OS deps to **bare** sonames, so `torch/lib` shipped `libnuma.so`. `repair_wheel.py` keeps them **versioned** (`libnuma.so.1`). rocSHMEM's `NUMAWrapper` global ctor does `dlopen("libnuma.so")` (bare) via `libtorch_rocshmem.so`'s `$ORIGIN` RPATH — with only `libnuma.so.1` present it fails and `exit(1)`s at load, tripping a **racy** rocprofiler-sdk atexit `finalize()` deadlock (hence the intermittency; the `agent.cpp:608` kfd warning is a red herring). Same rocSHMEM binary in both wheels — only the bundled `libnuma` filename differs.

## Fix
When bundling a versioned OS dep, also create a **bare-name symlink** (`libnuma.so` → `libnuma.so.1`, etc.), restoring `build_rocm.sh` behavior. The bare symlink satisfies rocSHMEM's `dlopen`; the versioned file still satisfies `NEEDED` references.

**Verified:** adding this symlink to an installed wheel makes `import torch` succeed deterministically on a no-`kfd` host (loop-tested; the hang no longer reproduces).

## Follow-ups (upstream)
The underlying rocSHMEM bug — `NUMAWrapper` must not `exit()` from a global constructor, and should `dlopen("libnuma.so.1")` — is already fixed upstream *after* PyTorch's pinned commit (`cb8a2d6`): ROCm/rocm-systems **pytorch#5918** (runtime numalib check) and **pytorch#6640** (link numa directly, no `dlopen` — removes `numa_wrapper.cpp`). Bumping `ROCSHMEM_VERSION` in `.ci/docker/common/install_rocSHMEM.sh` would also fix it and is worth doing separately. The rocprofiler-sdk atexit `finalize()` deadlock ("does not exit cleanly") is a separate AMD-side bug.

Pull Request resolved: pytorch#189114
Approved by: https://github.com/huydhn, https://github.com/albanD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants