You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Optimize AMICATorchNG per-iteration cost (pow hot spot + CPU threading) #63
Follow-up from the #59 benchmark. On the CPU float64 parity path, NG is ~3.2x slower than Fortran single-threaded and ~7.3x at 8 threads (Fortran even handicapped by Rosetta here). Two root causes, from a cProfile of a 20-iter fit (see #59):
1. pow is ~49% of runtime
2.55s of 5.15s is Tensor.pow, from the generalized-Gaussian |z|^rho (fractional exponent, single-threaded). It is evaluated separately in _log_pdf_and_deriv (core.py:94) and _score (core.py:159), so the density and its derivative each pay a fractional pow.
Proposals (all must stay bit-exact vs the Fortran z0/fp tests in test_ng_pdf_families.py):
Compute absz_pow = |z|**rho once and derive the score from it (fp ~ rho * absz_pow / z) instead of a second fractional pow.
Special-case rho == 2 (square) and rho == 1 (abs) to skip pow entirely for those PDF families.
Consider caching log|z| where |z|^rho = exp(rho*log|z|) is reused across pdf/score/rho-update.
2. NG does not parallelize on CPU
Going 1 -> 8 torch threads moves per-iter only 219 -> 204 ms (~7%), while Fortran OpenMP scales 68 -> 28 ms (~2.4x). The per-block Python loop dispatches many small elementwise kernels; intra-op threading cannot amortize that.
Investigate larger/vectorized block handling to give torch bigger ops to thread.
Activity
perf: drop dead dpdf + dedup |y|^rho in E-step (#63)
perf: block_size default 512 + GPU benchmark & findings (#63)
perf: warmup in gpu benchmark + correct CUDA numbers (#63)
perf: drop dead dpdf + dedup |y|^rho in E-step (#63) (#69)