pymc-devs / pymc-devs/pytensor
Add specialized float32 numba dispatches for transcendental functions
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 644
- Forks
- 208
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 16
Description
Description
tanh, cos, sin, exp, and erfc admit polynomial approximations that offer nice speedups over what we currently have. Numbers from a very quick claude session:
float32, 12.6M elements, single-threaded, min of 15
┌──────┬──────────────────┬─────────────────┬─────────┬─────────┬─────────────┐
│ op │ now (numba libm) │ with polynomial │ speedup │ saved │ error │
├──────┼──────────────────┼─────────────────┼─────────┼─────────┼─────────────┤
│ cos │ 67.50 ms │ 7.79 ms │ 8.66x │ 59.7 ms │ 5.5 ULP abs │
├──────┼──────────────────┼─────────────────┼─────────┼─────────┼─────────────┤
│ sin │ 61.25 ms │ 7.21 ms │ 8.50x │ 54.0 ms │ 5.9 ULP abs │
├──────┼──────────────────┼─────────────────┼─────────┼─────────┼─────────────┤
│ erfc │ 102.58 ms │ 45.42 ms │ 2.26x │ 57.2 ms │ 4.0 ULP rel │
├──────┼──────────────────┼─────────────────┼─────────┼─────────┼─────────────┤
│ tanh │ 48.67 ms │ 12.61 ms │ 3.86x │ 36.1 ms │ 2.7 ULP rel │
├──────┼──────────────────┼─────────────────┼─────────┼─────────┼─────────────┤
│ exp │ 17.70 ms │ 5.69 ms │ 3.23x │ 12.0 ms │ 2.3 ULP rel │
└──────┴──────────────────┴─────────────────┴─────────┴─────────┴─────────────┘
These functions show up in e.g. machine learning where we want to do float32, so it might be nice to implement these. On the other hand, they are less accurate, especially erfc/exp in the tails. I could do them as specialty dispatches in pytensor-ml, but I thought they might be more broadly interesting hence this issue first.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing Numba/libm dispatch path for tanh, cos, sin, exp, and erfc and review how float32 inputs are handled. Define acceptable accuracy, tail behavior, and benchmark expectations for each polynomial implementation; done means the specialized dispatches are integrated and their speed and error are validated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100