Skip to content

Conversation

@s3alfisc
Copy link
Member

We add a cupy backend https://docs.cupy.dev/en/latest/index.html to run FWL on the GPU.

Strategy: "direct" FWL OLS residualization instead of iterative solver.

Should help with problems with slow convergence.

Only tested on CPU via scipy, where results are matching. Cannot test on GPU as no Mac / no access to Cuda GPU.

Note: we can build a backend using a similar strategy via JAX and torch.

import pyfixest as pf

data = pf.get_data()

fit_rust = pf.feols("Y ~ X1 + X2  | f1", data = data, demeaner_backend="rust")
fit_cupy = pf.feols("Y ~ X1 + X2  | f1", data = data, demeaner_backend="cupy")

(pf.etable([fit_rust, fit_cupy], type = "md", digits = 8))
index                    est1             est2
------------  ---------------  ---------------
depvar                      Y                Y
----------------------------------------------
X1            -0.94952557***   -0.94952557***
                 (0.06637281)     (0.06637281)
X2            -0.17422527***   -0.17422527***
                 (0.01759569)     (0.01759569)
f1                          x                x
----------------------------------------------
Observations              997              997
----------------------------------------------
S.E. type                 iid              iid
R2                 0.48899391       0.48899391
R2 Within          0.23875790       0.23875790
----------------------------------------------

@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 25.56391% with 99 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pyfixest/estimation/cupy/demean_cupy_.py 20.86% 91 Missing ⚠️
pyfixest/estimation/backends.py 60.00% 4 Missing ⚠️
pyfixest/estimation/demean_.py 42.85% 4 Missing ⚠️
Flag Coverage Δ
core-tests 75.30% <25.56%> (-1.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pyfixest/estimation/estimation.py 90.80% <ø> (ø)
pyfixest/estimation/literals.py 87.50% <100.00%> (ø)
pyfixest/estimation/backends.py 75.00% <60.00%> (-8.34%) ⬇️
pyfixest/estimation/demean_.py 52.41% <42.85%> (-0.98%) ⬇️
pyfixest/estimation/cupy/demean_cupy_.py 20.86% <20.86%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@s3alfisc
Copy link
Member Author

TODO

  • add tests
  • create GPU env
  • maybe fix numpy to pandas to sparse array conversion? could lead to poor performance

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.

pyfixest is MUCH slower than (Stata + Julia) reghdfejl

2 participants