Skip to content

Commit 12d913b

Browse files
committed
docs: update softmax backend guidance and dim contract
1 parent 7107abb commit 12d913b

3 files changed

Lines changed: 27 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
- Documentation: README, DEVELOPMENT.md (#11), CONTRIBUTING.md with contribution policy (#7)
2727
- Pre-commit hooks installation instructions in CONTRIBUTING.md (#7)
2828
- Support for float16, bfloat16, and float32 dtypes
29-
- `FORGE_SOFTMAX_IMPL` softmax mode selection (`auto`, `ref`, `kernel`)
29+
- `softmax_online` backend registry APIs (`register/get/set/list`) with `ref` and `kernel` backends
3030

3131
### Changed
3232
- Modal benchmarks now use strict GPU matching (`!` suffix) for consistent hardware
@@ -38,7 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3838
- Enhanced error messages with device information for better debugging
3939
- Set tolerance to 0 (exact comparison) for transpose correctness tests
4040
- Updated documentation to reflect current three-layer architecture and modern PyTorch patterns
41-
- Added `--impl` to `bench/benchmark_online_softmax.py` and updated benchmark handling for strict kernel mode
41+
- Added `--backend` to `bench/benchmark_online_softmax.py` and aligned benchmark handling with backend registry
42+
- Enforced strict `dim=-1` contract for `softmax_online` (row-wise only)
4243

4344
### Infrastructure
4445
- Package scaffolding with `pyproject.toml` and proper Python 3.13+ support

DEVELOPMENT.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ This enables usage via both `forge_cute_py.ops.op_name()` and
4141
| `copy_transpose` | CuTe DSL | Fully implemented with tile-based shared memory |
4242
| `reduce` | CuTe DSL | Placeholder (sum only) |
4343
| `reduce_sum` | Reference | Placeholder (awaiting benchmarking) |
44-
| `softmax_online` | Reference | Stub with autograd support (kernel TODO, mode-gated via `FORGE_SOFTMAX_IMPL`) |
44+
| `softmax_online` | Reference + CuTe backend | Backend-registry flow (`ref` default, `kernel` optional); row-wise `dim=-1` only |
4545

4646
### Development flow
4747

@@ -128,16 +128,20 @@ non-zero tolerance in tests.
128128
uv run python bench/run.py --suite smoke
129129
uv run python bench/benchmark_copy_transpose.py --tile-size 16
130130
uv run python bench/benchmark_reduce.py
131-
uv run python bench/benchmark_online_softmax.py --impl auto
132-
uv run python bench/benchmark_online_softmax.py --impl kernel
131+
uv run python bench/benchmark_online_softmax.py --backend ref
132+
uv run python bench/benchmark_online_softmax.py --backend kernel
133133
modal run bench/modal_bench.py --suite smoke --out results.json
134134
modal run bench/modal_bench.py --suite smoke --op reduce_sum --out results.json
135135
```
136136

137-
`softmax_online` backend mode is controlled by `FORGE_SOFTMAX_IMPL`:
138-
- `auto` (default): try kernel if present, otherwise fallback to reference.
139-
- `ref`: force reference path.
140-
- `kernel`: require kernel path and fail fast if missing/incomplete.
137+
`softmax_online` backend selection is controlled by:
138+
- Python API: `set_softmax_online_backend("ref")` / `set_softmax_online_backend("kernel")`
139+
- Benchmark CLI: `bench/benchmark_online_softmax.py --backend {ref,kernel}`
140+
141+
Current `softmax_online` constraints:
142+
- Input is 2D CUDA tensor
143+
- Dtype in `float16`, `bfloat16`, `float32`
144+
- `dim=-1` only
141145

142146
> **Warning:** Modal benchmarks incur GPU costs. Review `bench/modal_bench.py`
143147
> and verify timeout/GPU settings before running. Start with `--suite smoke`

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ Run a standalone benchmark:
8484

8585
```bash
8686
uv run python bench/benchmark_copy_transpose.py --tile-size 16
87-
uv run python bench/benchmark_online_softmax.py --impl auto
88-
uv run python bench/benchmark_online_softmax.py --impl kernel
87+
uv run python bench/benchmark_online_softmax.py --backend ref
88+
uv run python bench/benchmark_online_softmax.py --backend kernel
8989
```
9090

9191
Profile a kernel with helper script:
@@ -110,7 +110,7 @@ ncu --set full -o profiles/copy_transpose uv run python bench/benchmark_copy_tra
110110
| copy_transpose | Implemented | tile_size=16/32 | CuTe DSL kernel with tiled shared memory |
111111
| reduce | Implemented (sum only) | - | Placeholder (awaiting benchmarking) |
112112
| reduce_sum | Stub (ref) | - | Placeholder (awaiting benchmarking) |
113-
| softmax_online | Stub (ref) | single-pass | Reference-backed by default; `FORGE_SOFTMAX_IMPL` can force `ref` or strict `kernel` mode |
113+
| softmax_online | Implemented (registry) | ref, kernel | Default backend is `ref`; `kernel` is available for contributor benchmarking and remains non-production |
114114

115115
---
116116

@@ -153,15 +153,19 @@ uv run python bench/run.py --suite smoke # Run benchmark suite
153153
uv run python bench/run.py --suite smoke --out out.json # Save results
154154
uv run python bench/benchmark_copy_transpose.py # Standalone benchmark
155155
uv run python bench/benchmark_reduce.py # Standalone benchmark
156-
uv run python bench/benchmark_online_softmax.py --impl auto # softmax fwd+bwd (fallback allowed)
157-
uv run python bench/benchmark_online_softmax.py --impl kernel # softmax fwd+bwd (hard fail if kernel missing)
156+
uv run python bench/benchmark_online_softmax.py --backend ref # softmax fwd+bwd on reference backend
157+
uv run python bench/benchmark_online_softmax.py --backend kernel # softmax fwd+bwd on CuTe kernel backend
158158
modal run bench/modal_bench.py --suite smoke --out results.json # Remote run on B200 via Modal
159159
```
160160

161-
`softmax_online` mode is controlled by `FORGE_SOFTMAX_IMPL`:
162-
- `auto` (default): try kernel first, then fallback to reference.
163-
- `ref`: force reference implementation.
164-
- `kernel`: require kernel implementation and fail fast if unavailable.
161+
`softmax_online` backend selection is controlled via Python API or benchmark CLI:
162+
- Python API: `set_softmax_online_backend("ref")` or `set_softmax_online_backend("kernel")`
163+
- Benchmark CLI: `bench/benchmark_online_softmax.py --backend {ref,kernel}`
164+
165+
Current softmax contract:
166+
- supported tensors: 2D CUDA
167+
- supported dtypes: `float16`, `bfloat16`, `float32`
168+
- supported dim: `dim=-1` (row-wise only)
165169

166170
### Modal setup (remote benchmarks)
167171
```bash

0 commit comments

Comments
 (0)