trnfft 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- trnfft-0.5.0/.github/ISSUE_TEMPLATE/bug_report.md +31 -0
- trnfft-0.5.0/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- trnfft-0.5.0/.github/pull_request_template.md +9 -0
- trnfft-0.5.0/.github/workflows/ci.yml +20 -0
- trnfft-0.5.0/.github/workflows/docs.yml +38 -0
- trnfft-0.5.0/.github/workflows/publish.yml +56 -0
- trnfft-0.5.0/.gitignore +24 -0
- trnfft-0.5.0/CHANGELOG.md +96 -0
- trnfft-0.5.0/CLAUDE.md +122 -0
- trnfft-0.5.0/LICENSE +199 -0
- trnfft-0.5.0/PKG-INFO +174 -0
- trnfft-0.5.0/README.md +143 -0
- trnfft-0.5.0/benchmarks/bench_fft.py +94 -0
- trnfft-0.5.0/benchmarks/conftest.py +30 -0
- trnfft-0.5.0/docs/api/complex.md +64 -0
- trnfft-0.5.0/docs/api/fft.md +70 -0
- trnfft-0.5.0/docs/api/nki.md +46 -0
- trnfft-0.5.0/docs/api/nn.md +62 -0
- trnfft-0.5.0/docs/architecture.md +51 -0
- trnfft-0.5.0/docs/aws_setup.md +79 -0
- trnfft-0.5.0/docs/index.md +30 -0
- trnfft-0.5.0/docs/installation.md +53 -0
- trnfft-0.5.0/docs/quickstart.md +76 -0
- trnfft-0.5.0/examples/speech_stft.py +115 -0
- trnfft-0.5.0/infra/terraform/README.md +58 -0
- trnfft-0.5.0/infra/terraform/main.tf +153 -0
- trnfft-0.5.0/mkdocs.yml +34 -0
- trnfft-0.5.0/pyproject.toml +57 -0
- trnfft-0.5.0/scripts/run_neuron_tests.sh +144 -0
- trnfft-0.5.0/setup.cfg +4 -0
- trnfft-0.5.0/tests/conftest.py +53 -0
- trnfft-0.5.0/tests/test_complex.py +154 -0
- trnfft-0.5.0/tests/test_fft.py +202 -0
- trnfft-0.5.0/tests/test_nn.py +98 -0
- trnfft-0.5.0/tests/test_stft.py +82 -0
- trnfft-0.5.0/trnfft/__init__.py +27 -0
- trnfft-0.5.0/trnfft/api.py +370 -0
- trnfft-0.5.0/trnfft/complex.py +151 -0
- trnfft-0.5.0/trnfft/fft_core.py +218 -0
- trnfft-0.5.0/trnfft/nki/__init__.py +16 -0
- trnfft-0.5.0/trnfft/nki/butterfly.py +95 -0
- trnfft-0.5.0/trnfft/nki/dispatch.py +238 -0
- trnfft-0.5.0/trnfft/nki/multicore.py +91 -0
- trnfft-0.5.0/trnfft/nn.py +109 -0
- trnfft-0.5.0/trnfft/plan.py +54 -0
- trnfft-0.5.0/trnfft.egg-info/PKG-INFO +174 -0
- trnfft-0.5.0/trnfft.egg-info/SOURCES.txt +48 -0
- trnfft-0.5.0/trnfft.egg-info/dependency_links.txt +1 -0
- trnfft-0.5.0/trnfft.egg-info/requires.txt +13 -0
- trnfft-0.5.0/trnfft.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Report a bug in trnfft
|
|
4
|
+
labels: bug
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Environment
|
|
8
|
+
|
|
9
|
+
- trnfft version:
|
|
10
|
+
- Python version:
|
|
11
|
+
- PyTorch version:
|
|
12
|
+
- Hardware: CPU / trn1 / trn2 / inf2
|
|
13
|
+
- OS:
|
|
14
|
+
|
|
15
|
+
## Description
|
|
16
|
+
|
|
17
|
+
What happened?
|
|
18
|
+
|
|
19
|
+
## Steps to reproduce
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
# Minimal code to reproduce
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Expected behavior
|
|
26
|
+
|
|
27
|
+
What should have happened?
|
|
28
|
+
|
|
29
|
+
## Actual behavior
|
|
30
|
+
|
|
31
|
+
What happened instead? Include error messages/tracebacks if applicable.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest a new feature or enhancement
|
|
4
|
+
labels: enhancement
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Description
|
|
8
|
+
|
|
9
|
+
What feature would you like?
|
|
10
|
+
|
|
11
|
+
## Motivation
|
|
12
|
+
|
|
13
|
+
Why is this needed? What problem does it solve?
|
|
14
|
+
|
|
15
|
+
## Alternatives considered
|
|
16
|
+
|
|
17
|
+
Any other approaches you've thought about?
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- run: pip install -e ".[dev]"
|
|
20
|
+
- run: pytest tests/ -v -x --tb=short -m "not neuron"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Deploy Docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
pages: write
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: pages
|
|
14
|
+
cancel-in-progress: true
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
build:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.12"
|
|
24
|
+
- run: pip install mkdocs mkdocs-material
|
|
25
|
+
- run: mkdocs build --strict
|
|
26
|
+
- uses: actions/upload-pages-artifact@v3
|
|
27
|
+
with:
|
|
28
|
+
path: site/
|
|
29
|
+
|
|
30
|
+
deploy:
|
|
31
|
+
needs: build
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
environment:
|
|
34
|
+
name: github-pages
|
|
35
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
36
|
+
steps:
|
|
37
|
+
- id: deployment
|
|
38
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
- uses: actions/setup-python@v5
|
|
13
|
+
with:
|
|
14
|
+
python-version: "3.12"
|
|
15
|
+
- run: pip install build
|
|
16
|
+
- run: python -m build
|
|
17
|
+
- uses: actions/upload-artifact@v4
|
|
18
|
+
with:
|
|
19
|
+
name: dist
|
|
20
|
+
path: dist/
|
|
21
|
+
|
|
22
|
+
publish-pypi:
|
|
23
|
+
needs: build
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
# Only publish stable releases (v1.2.3), not pre-releases (v1.2.3-rc1)
|
|
26
|
+
if: ${{ !contains(github.event.release.tag_name, '-') }}
|
|
27
|
+
environment:
|
|
28
|
+
name: pypi
|
|
29
|
+
url: https://pypi.org/project/trnfft/
|
|
30
|
+
permissions:
|
|
31
|
+
id-token: write
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/download-artifact@v4
|
|
34
|
+
with:
|
|
35
|
+
name: dist
|
|
36
|
+
path: dist/
|
|
37
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
38
|
+
|
|
39
|
+
publish-testpypi:
|
|
40
|
+
needs: build
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
# Only publish pre-releases to TestPyPI
|
|
43
|
+
if: ${{ contains(github.event.release.tag_name, '-') }}
|
|
44
|
+
environment:
|
|
45
|
+
name: testpypi
|
|
46
|
+
url: https://test.pypi.org/project/trnfft/
|
|
47
|
+
permissions:
|
|
48
|
+
id-token: write
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/download-artifact@v4
|
|
51
|
+
with:
|
|
52
|
+
name: dist
|
|
53
|
+
path: dist/
|
|
54
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
55
|
+
with:
|
|
56
|
+
repository-url: https://test.pypi.org/legacy/
|
trnfft-0.5.0/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*$py.class
|
|
4
|
+
*.egg-info/
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
.eggs/
|
|
8
|
+
*.egg
|
|
9
|
+
.pytest_cache/
|
|
10
|
+
.tox/
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
*.so
|
|
14
|
+
.idea/
|
|
15
|
+
.vscode/
|
|
16
|
+
*.swp
|
|
17
|
+
*.swo
|
|
18
|
+
*~
|
|
19
|
+
site/
|
|
20
|
+
.benchmarks/
|
|
21
|
+
.terraform/
|
|
22
|
+
*.tfstate
|
|
23
|
+
*.tfstate.backup
|
|
24
|
+
.terraform.lock.hcl
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.5.0] - 2026-04-12
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Terraform module (`infra/terraform/`) for provisioning a Trainium CI instance with SSM access.
|
|
15
|
+
- `docs/aws_setup.md` and `scripts/run_neuron_tests.sh` for running neuron-marked tests locally via `AWS_PROFILE=aws`.
|
|
16
|
+
- Hardware compatibility matrix in `docs/installation.md` documenting validated Neuron SDK and AMI versions.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- All three NKI kernels validated and passing on real Trainium hardware (trn1.2xlarge, neuronxcc 2.24.5133.0).
|
|
21
|
+
- NKI butterfly kernel rewritten with 2D `(num_groups, m)` partition-dim tile layout. Twiddle factors are pre-broadcast on the host to `(num_groups, half)` so element-wise ops have matching partition dims. Outputs are allocated and returned by the kernel (NKI 2.24 parameters are immutable). Constant-size partition tiles (no `min()` in `affine_range`).
|
|
22
|
+
- `_complex_gemm_kernel` updated to use the NKI 2.24 calling convention (`psum[...] += nisa.nc_matmul(stationary, moving)` returning a PSUM tile) and `nl.load_transpose2d` for the stationary A tile. Uses `nl.negative` + `+=` instead of `-=` (unsupported inside `affine_range`).
|
|
23
|
+
- `_complex_mul_kernel` reshapes inputs to `(128, free)` to satisfy the partition-dim ≤ 128 constraint; falls back to PyTorch for inputs whose total size isn't divisible by 128.
|
|
24
|
+
- All NKI dispatch wrappers move tensors to/from the XLA device (`xm.xla_device()`) since NKI kernels require XLA tensors.
|
|
25
|
+
- Pinned `neuronxcc>=2.24` and `torch-neuronx>=2.9` in the `neuron` extra. Kernels do not compile against older Neuron SDKs.
|
|
26
|
+
- `neuron.yml` GitHub Actions workflow removed; AWS access is now local-only via `scripts/run_neuron_tests.sh` with `AWS_PROFILE=aws`.
|
|
27
|
+
|
|
28
|
+
## [0.4.0] - 2026-04-11
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- MkDocs documentation site with pages for installation, quickstart, API reference, and architecture.
|
|
33
|
+
- GitHub Pages deployment workflow.
|
|
34
|
+
- PyPI publishing workflow (OIDC trusted publishers, sdist + wheel on release).
|
|
35
|
+
- Benchmark suite (`benchmarks/bench_fft.py`) for 1D/2D FFT, STFT, and complex GEMM.
|
|
36
|
+
- Multi-NeuronCore parallelism scaffold (`trnfft.nki.multicore`) with data-parallel batch split.
|
|
37
|
+
- PyPI, Python version, license, and docs badges in README.
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- LICENSE replaced with full Apache 2.0 text (Copyright 2026 Scott Friedman).
|
|
42
|
+
- `pyproject.toml` dev deps now include mkdocs and mkdocs-material.
|
|
43
|
+
|
|
44
|
+
## [0.3.0] - 2026-04-11
|
|
45
|
+
|
|
46
|
+
### Added
|
|
47
|
+
|
|
48
|
+
- NKI complex GEMM kernel with stationary tile reuse (ported from neuron-complex-ops).
|
|
49
|
+
- NKI fused element-wise complex multiply kernel.
|
|
50
|
+
- NKI butterfly kernel wired into Cooley-Tukey FFT path.
|
|
51
|
+
- `nki_backend` test fixture and 4 neuron-marked tests for on-hardware validation.
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- `_cooley_tukey()` now dispatches to NKI butterfly kernel when running on Trainium.
|
|
56
|
+
- `_nki_complex_gemm()` and `_nki_complex_mask()` call real NKI kernels instead of PyTorch fallback.
|
|
57
|
+
|
|
58
|
+
## [0.2.0] - 2026-04-11
|
|
59
|
+
|
|
60
|
+
### Added
|
|
61
|
+
|
|
62
|
+
- `istft()` — inverse STFT with overlap-add reconstruction, matching `torch.istft` signature.
|
|
63
|
+
- `fftn()` and `ifftn()` — N-dimensional FFT along arbitrary dimensions.
|
|
64
|
+
- GitHub Actions CI (Python 3.10, 3.11, 3.12).
|
|
65
|
+
- Neuron hardware CI workflow (manual `workflow_dispatch` scaffold).
|
|
66
|
+
- Issue and PR templates.
|
|
67
|
+
|
|
68
|
+
### Changed
|
|
69
|
+
|
|
70
|
+
- `fft2()` now delegates to `fftn()` internally.
|
|
71
|
+
- `neuron-complex-ops` repo archived with pointer to trnfft.
|
|
72
|
+
|
|
73
|
+
## [0.1.0] - 2026-04-11
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
|
|
77
|
+
- `ComplexTensor` class with split real/imaginary representation and full arithmetic operator support.
|
|
78
|
+
- Complex matrix multiplication decomposed into four real matmuls.
|
|
79
|
+
- 1D FFT and IFFT using iterative Cooley-Tukey radix-2 (decimation-in-time).
|
|
80
|
+
- Bluestein's chirp-z algorithm for arbitrary-size transforms.
|
|
81
|
+
- `rfft` and `irfft` for real-valued input signals.
|
|
82
|
+
- 2D FFT (`fft2`) via sequential 1D transforms along each axis.
|
|
83
|
+
- STFT matching `torch.stft` signature with `unfold`-based framing.
|
|
84
|
+
- Complex neural network layers: `ComplexLinear`, `ComplexConv1d`, `ComplexBatchNorm1d`, `ComplexModReLU`.
|
|
85
|
+
- NKI dispatch layer with `auto`, `pytorch`, and `nki` backend selection.
|
|
86
|
+
- FFT plan caching (FFTW-style) for repeated transforms of the same size.
|
|
87
|
+
- NKI butterfly and GEMM kernel stubs (scaffolded for on-hardware validation).
|
|
88
|
+
- Speech enhancement example using complex ideal ratio mask (cIRM).
|
|
89
|
+
- 83 tests covering arithmetic, FFT correctness, STFT, NN layers, and gradients.
|
|
90
|
+
|
|
91
|
+
[Unreleased]: https://github.com/scttfrdmn/trnfft/compare/v0.5.0...HEAD
|
|
92
|
+
[0.5.0]: https://github.com/scttfrdmn/trnfft/compare/v0.4.0...v0.5.0
|
|
93
|
+
[0.4.0]: https://github.com/scttfrdmn/trnfft/compare/v0.3.0...v0.4.0
|
|
94
|
+
[0.3.0]: https://github.com/scttfrdmn/trnfft/compare/v0.2.0...v0.3.0
|
|
95
|
+
[0.2.0]: https://github.com/scttfrdmn/trnfft/compare/v0.1.0...v0.2.0
|
|
96
|
+
[0.1.0]: https://github.com/scttfrdmn/trnfft/releases/tag/v0.1.0
|
trnfft-0.5.0/CLAUDE.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# trnfft
|
|
2
|
+
|
|
3
|
+
FFT and complex-valued tensor operations for AWS Trainium via NKI.
|
|
4
|
+
Part of the trn-* scientific computing suite by Playground Logic.
|
|
5
|
+
|
|
6
|
+
Incorporates neuron-complex-ops (https://github.com/scttfrdmn/neuron-complex-ops).
|
|
7
|
+
|
|
8
|
+
## What This Is
|
|
9
|
+
|
|
10
|
+
A cuFFT-equivalent for Trainium. Trainium has no native complex dtype and no
|
|
11
|
+
FFT library. trnfft fills that gap using split real/imaginary representation,
|
|
12
|
+
complex neural network layers, and NKI kernels targeting the Tensor, Vector,
|
|
13
|
+
and Scalar engines.
|
|
14
|
+
|
|
15
|
+
## Relationship to neuron-complex-ops
|
|
16
|
+
|
|
17
|
+
`neuron-complex-ops` was the proof-of-concept for the Williamson/ASPIRE
|
|
18
|
+
engagement at OSU. This project absorbs it:
|
|
19
|
+
|
|
20
|
+
**Folded in from neuron-complex-ops:**
|
|
21
|
+
- `ComplexTensor` with full arithmetic → `trnfft/complex.py`
|
|
22
|
+
- NKI dispatch layer (pytorch ↔ nki auto-select) → `trnfft/nki/dispatch.py`
|
|
23
|
+
- Complex GEMM kernel (stationary reuse, PSUM accumulation) → `trnfft/nki/dispatch.py`
|
|
24
|
+
- Complex mask apply kernel → `trnfft/nki/dispatch.py`
|
|
25
|
+
- DFT-matrix-multiply STFT → absorbed into `trnfft/api.py` stft()
|
|
26
|
+
- ComplexLinear, ComplexConv1d, ComplexBatchNorm1d, ComplexModReLU → `trnfft/nn.py`
|
|
27
|
+
- Speech enhancement example (cIRM training) → `trnfft/examples/`
|
|
28
|
+
|
|
29
|
+
**trnfft adds on top:**
|
|
30
|
+
- Cooley-Tukey / Bluestein FFT algorithms (`trnfft/fft_core.py`)
|
|
31
|
+
- Plan-based execution with caching (`trnfft/plan.py`)
|
|
32
|
+
- torch.fft-compatible API surface (`trnfft/api.py`)
|
|
33
|
+
- NKI butterfly kernels for hardware-accelerated FFT (`trnfft/nki/butterfly.py`)
|
|
34
|
+
- Multi-NeuronCore parallelism for large transforms (future)
|
|
35
|
+
|
|
36
|
+
neuron-complex-ops repo stays public with a pointer to trnfft.
|
|
37
|
+
|
|
38
|
+
## Architecture
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
trnfft/
|
|
42
|
+
├── trnfft/
|
|
43
|
+
│ ├── __init__.py # Public API re-exports
|
|
44
|
+
│ ├── api.py # torch.fft-compatible: fft, ifft, rfft, irfft, fft2, stft
|
|
45
|
+
│ ├── complex.py # ComplexTensor (split real/imag) — from neuron-complex-ops
|
|
46
|
+
│ ├── fft_core.py # Cooley-Tukey + Bluestein algorithms
|
|
47
|
+
│ ├── nn.py # ComplexLinear, ComplexConv1d, ComplexBatchNorm1d, ComplexModReLU
|
|
48
|
+
│ ├── plan.py # FFTPlan with caching
|
|
49
|
+
│ ├── nki/
|
|
50
|
+
│ │ ├── __init__.py
|
|
51
|
+
│ │ ├── dispatch.py # PyTorch ↔ NKI auto-dispatch + GEMM/mask kernels
|
|
52
|
+
│ │ └── butterfly.py # NKI butterfly kernel stubs (validate on hardware)
|
|
53
|
+
├── tests/
|
|
54
|
+
│ ├── conftest.py # Fixtures, hardware detection
|
|
55
|
+
│ ├── test_complex.py # ComplexTensor arithmetic + matmul
|
|
56
|
+
│ ├── test_fft.py # 1D/2D FFT, IFFT, RFFT, Bluestein
|
|
57
|
+
│ ├── test_stft.py # STFT shape, energy, tone detection
|
|
58
|
+
│ └── test_nn.py # Complex neural network layers
|
|
59
|
+
├── examples/
|
|
60
|
+
│ └── speech_stft.py # cIRM speech enhancement demo
|
|
61
|
+
├── benchmarks/
|
|
62
|
+
├── docs/
|
|
63
|
+
├── pyproject.toml
|
|
64
|
+
├── README.md
|
|
65
|
+
├── LICENSE # Apache 2.0
|
|
66
|
+
└── CLAUDE.md # This file
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Key Design Decisions
|
|
70
|
+
|
|
71
|
+
1. **Split real/imaginary** — Trainium has no complex dtype. ComplexTensor wraps paired real tensors with arithmetic operators.
|
|
72
|
+
|
|
73
|
+
2. **Iterative Cooley-Tukey** — Standard radix-2 DIT with bit-reversal. Each butterfly stage vectorized across all groups simultaneously.
|
|
74
|
+
|
|
75
|
+
3. **Bluestein for arbitrary sizes** — Converts arbitrary-N DFT to circular convolution via three power-of-2 FFTs.
|
|
76
|
+
|
|
77
|
+
4. **Plan-based execution** — Like FFTW/cuFFT. Plans cached by (size, inverse).
|
|
78
|
+
|
|
79
|
+
5. **torch.fft-compatible API** — `trnfft.fft(x)` mirrors `torch.fft.fft(x)`.
|
|
80
|
+
|
|
81
|
+
6. **NKI dispatch** — `set_backend("auto"|"pytorch"|"nki")`. Auto-detects Neuron hardware.
|
|
82
|
+
|
|
83
|
+
## Known Gaps & Design Notes
|
|
84
|
+
|
|
85
|
+
- **NKI kernels are stubs.** Both GEMM and butterfly kernels fall back to
|
|
86
|
+
PyTorch even when NKI is available. Next milestone is on-hardware validation
|
|
87
|
+
on a trn2 instance, wiring the actual kernels from neuron-complex-ops.
|
|
88
|
+
|
|
89
|
+
- **Bluestein FP32 precision.** N>=500 accumulates ~2e-2 error through the
|
|
90
|
+
3-FFT Bluestein chain in float32. For applications needing higher precision,
|
|
91
|
+
run on float64 input (`x.double()`) — the implementation supports it. NKI
|
|
92
|
+
kernels (FP32-only on Trainium) will need iterative refinement or Kahan
|
|
93
|
+
summation for large arbitrary-size transforms.
|
|
94
|
+
|
|
95
|
+
- **ComplexBatchNorm** uses independent real/imag normalization, not the
|
|
96
|
+
covariance-based variant (Trabelsi et al. 2018). Deliberate simplicity —
|
|
97
|
+
the simple form works for cIRM speech enhancement.
|
|
98
|
+
|
|
99
|
+
## Dependencies
|
|
100
|
+
|
|
101
|
+
- `torch>=2.1` — tensor operations and CPU fallback
|
|
102
|
+
- `numpy>=1.24` — reference FFT for testing
|
|
103
|
+
- `neuronxcc` — NKI kernels (optional, only on Neuron hardware)
|
|
104
|
+
|
|
105
|
+
## Development
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install -e ".[dev]"
|
|
109
|
+
pytest tests/ -v # CPU fallback mode
|
|
110
|
+
pytest tests/ -v -m neuron # On-hardware tests (requires trn instance)
|
|
111
|
+
python examples/speech_stft.py --demo # Quick STFT demo
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Naming Convention
|
|
115
|
+
|
|
116
|
+
This repo is part of the `trn*` suite under Playground Logic:
|
|
117
|
+
- `trnfft` — FFT + complex ops (this repo)
|
|
118
|
+
- `trnblas` — BLAS operations (planned)
|
|
119
|
+
- `trnsolver` — Linear solvers, eigendecomposition (planned)
|
|
120
|
+
- `trnrand` — Random number generation (planned)
|
|
121
|
+
|
|
122
|
+
All repos: Python/NKI, Apache 2.0, Playground Logic.
|
trnfft-0.5.0/LICENSE
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept support,
|
|
167
|
+
obligations, or other liability only on behalf of Yourself and on
|
|
168
|
+
Your sole responsibility, not on behalf of any other Contributor,
|
|
169
|
+
and only if You agree to indemnify, defend, and hold each Contributor
|
|
170
|
+
harmless for any liability incurred by, or claims asserted against,
|
|
171
|
+
such Contributor by reason of your accepting any such warranty or
|
|
172
|
+
additional liability.
|
|
173
|
+
|
|
174
|
+
END OF TERMS AND CONDITIONS
|
|
175
|
+
|
|
176
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
177
|
+
|
|
178
|
+
To apply the Apache License to your work, attach the following
|
|
179
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
180
|
+
replaced with your own identifying information. (Don't include
|
|
181
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
182
|
+
comment syntax for the file format. We also recommend that a
|
|
183
|
+
file or class name and description of purpose be included on the
|
|
184
|
+
same "printed page" as the copyright notice for easier
|
|
185
|
+
identification within third-party archives.
|
|
186
|
+
|
|
187
|
+
Copyright 2026 Scott Friedman
|
|
188
|
+
|
|
189
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
190
|
+
you may not use this file except in compliance with the License.
|
|
191
|
+
You may obtain a copy of the License at
|
|
192
|
+
|
|
193
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
194
|
+
|
|
195
|
+
Unless required by applicable law or agreed to in writing, software
|
|
196
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
197
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
198
|
+
See the License for the specific language governing permissions and
|
|
199
|
+
limitations under the License.
|