Benchmarks¶
The benchmarks fit five models to the American Community Survey’s 2019-2023 Public Use Microdata Sample, the people aged 25 to 64 (7,994,026, of whom 5,885,502 have a wage), in a random order, so that the first n rows are a random sample of n. Every predictor is a set of indicators.
Model |
What is fitted |
Compared with |
|---|---|---|
Wage |
a lasso of the log hourly wage on about 2,000 indicators (every predictor, the job’s included), the penalty by 5-fold cross-validation over 100 penalties; and the same with the 2,462 PUMAs absorbed |
scikit-learn’s |
Gender gap |
post-double-selection for the effect of |
R’s hdm ( |
Employment |
a lasso logit of employment on 153 indicators, 5-fold cross-validation over 100 penalties |
scikit-learn’s |
Class of worker |
a lasso multinomial logit of the class of worker (private for-profit, private nonprofit, government, self-employed) of the 5,871,734 workers with a wage, on 16 predictors of a person, 5-fold cross-validation over 100 penalties, by the streamed and the in-memory solver; with the grouped penalty; and with the PUMAs absorbed |
scikit-learn’s |
Educational attainment |
a lasso ordered logit of educational attainment (less than high school, high school, some college, bachelor’s, graduate degree) on 18 predictors of a person, 5-fold cross-validation over 100 penalties; and with the PUMAs absorbed |
R’s ordinalNet ( |
Each configuration runs in its own process, from a Parquet file of the n
rows. The time includes reading the data and building the design (a library
that needs the data in memory reads the file first); the memory is the
process’s peak resident memory. A configuration that runs out of memory or
exceeds its time limit (an hour for the wage and gap models, six hours for
the logit models) is not run at larger sizes. The scripts are in the
repository’s benchmarks/ folder.
Tolerances and accuracy¶
The multinomial and ordered fits use a convergence tolerance of 1e-7 in
penalized-stream and the same value for glmnet’s thresh, which tests the
same thing. glmnet and ordinalNet fit all 100 penalties, without ending the
path early. ordinalNet’s tolerances test something different and keep their
defaults.
The same tolerance does not give the same accuracy, because each solver stops when its own test is met. To show what each fit reaches, every library fits the path on all the rows at the same 100 penalties with the benchmark’s settings, and its deviance is compared with a fit converged to 1e-12.
At 100,000 rows, the relative difference of each fit’s deviance from the converged path’s, over the 100 penalties:
model |
library |
settings |
largest |
median |
|---|---|---|---|---|
class of worker |
penalized-stream, streamed |
|
8.3e-6 |
3.8e-6 |
class of worker |
penalized-stream, in memory |
|
1.6e-5 |
3.1e-6 |
class of worker |
glmnet |
|
9.7e-5 |
4.3e-5 |
educational attainment |
penalized-stream |
|
4.6e-6 |
2.3e-7 |
educational attainment |
ordinalNet |
its defaults |
7.2e-6 |
2.4e-8 |
Every library’s fit is close to the exact path; at the same tolerance,
glmnet’s coordinate descent stops about ten times further from it than
penalized-stream’s streamed Newton steps, and the in-memory solver in
between. The numbers are in benchmarks/results/accuracy.csv
(benchmarks/accuracy.py).
Machine¶
Every benchmark ran on an Amazon EC2 instance with an Intel Xeon 6975P-C
(8 cores, 16 threads) and local NVMe disk: a c8id.4xlarge (32 GB of memory)
for the wage and gap models, and an m8id.4xlarge (64 GB) for the employment,
class-of-worker and educational-attainment models, each benchmark process
limited to 96% of the memory. The versions were penalized-stream 0.1.0,
hdfe-stream 0.13.2, logit-stream 0.7.0 (0.8.0 for the multinomial and
ordered models), scikit-learn 1.9.1, and R 4.5.3 with glmnet 5.0, biglasso
1.6.1, hdm 0.3.2 and ordinalNet 2.14 (benchmarks/results/machine.json,
wage-gap_machine.json, class_machine.json and schooling_machine.json
have the full list).
Lasso with cross-validation: the wage model¶
A lasso of the log hourly wage on about 2,000 indicators, its penalty chosen by 5-fold cross-validation over 100 penalties:
rows |
penalized-stream |
with PUMA fixed effects |
glmnet |
scikit-learn |
biglasso |
|---|---|---|---|---|---|
10,000 |
4.9 s, 1.5 GB |
4.6 s, 1.8 GB |
3.6 s, 0.4 GB |
65 s, 0.3 GB |
107 s, 0.5 GB |
30,000 |
6.2 s, 2.4 GB |
6.4 s, 3.1 GB |
9.4 s, 0.5 GB |
253 s, 0.4 GB |
275 s, 0.9 GB |
100,000 |
8.1 s, 6.7 GB |
9.3 s, 4.3 GB |
33 s, 0.9 GB |
967 s, 0.5 GB |
1,429 s, 2.1 GB |
300,000 |
13 s, 8.5 GB |
19 s, 4.1 GB |
170 s, 1.9 GB |
3,053 s, 0.9 GB |
3,178 s, 5.4 GB |
1,000,000 |
32 s, 8.6 GB |
47 s, 4.1 GB |
797 s, 4.9 GB |
over 1 h |
over 1 h |
3,000,000 |
82 s, 8.6 GB |
134 s, 4.9 GB |
2,688 s, 15.6 GB |
||
5,885,502 |
154 s, 8.9 GB |
259 s, 5.1 GB |
over 1 h |
On every worker, penalized-stream took 2.6 minutes, and 4.3 minutes with the 2,462 PUMAs absorbed. glmnet took 45 minutes at 3 million workers and did not finish all 5.9 million within the hour.
From 30,000 workers up, penalized-stream is the fastest, by 4 times at 100,000 and 33 times at 3 million. At 10,000, glmnet is faster (3.6 s against 4.9 s).
penalized-stream’s memory levels off at about 8.6 GB from 300,000 workers up: that is its default memory budget for forming the cross-products, not the data. The in-memory libraries use less at small sizes and grow with the data, glmnet to 15.6 GB at 3 million.
Post-double-selection: the gender gap¶
Post-double-selection for the effect of female on the log hourly wage,
with the plug-in penalty and heteroskedasticity-robust standard errors:
rows |
penalized-stream |
with PUMA fixed effects |
hdm |
estimate (penalized-stream) |
difference from hdm |
|---|---|---|---|---|---|
10,000 |
4.9 s, 0.9 GB |
4.4 s, 1.0 GB |
21 s, 1.8 GB |
−0.1855 (0.0251) |
1.2e-4 |
30,000 |
6.6 s, 1.9 GB |
6.4 s, 1.8 GB |
42 s, 4.6 GB |
−0.1618 (0.0137) |
4e-16 |
100,000 |
14 s, 2.7 GB |
14 s, 3.4 GB |
150 s, 15.3 GB |
−0.1732 (0.0075) |
0.016[1] |
300,000 |
35 s, 4.1 GB |
41 s, 3.2 GB |
out of memory |
−0.1904 (0.0044) |
|
1,000,000 |
109 s, 5.5 GB |
122 s, 3.7 GB |
−0.1884 (0.0024) |
||
3,000,000 |
328 s, 6.7 GB |
384 s, 4.8 GB |
−0.1841 (0.0014) |
||
5,885,502 |
658 s, 7.5 GB |
803 s, 5.4 GB |
−0.1840 (0.0010) |
penalized-stream fitted every worker in 11 minutes in 7.5 GB, and with the PUMAs absorbed in 13 minutes. hdm ran out of memory at 300,000 workers, on a 32 GB machine.
Where both ran, penalized-stream was 4 to 11 times faster, with the same estimate at 10,000 and 30,000 workers.
Lasso logit: employment¶
A lasso logit of employment on 153 indicators, 5-fold cross-validation over 100 penalties:
rows |
penalized-stream (streamed) |
penalized-stream (in memory) |
glmnet |
scikit-learn |
|---|---|---|---|---|
10,000 |
2.8 s, 0.6 GB |
1.5 s, 0.6 GB |
2.1 s, 0.4 GB |
27 s, 0.3 GB |
30,000 |
4.1 s, 0.7 GB |
2.8 s, 0.7 GB |
5.5 s, 0.6 GB |
89 s, 0.3 GB |
100,000 |
8.6 s, 0.9 GB |
7.9 s, 0.9 GB |
20 s, 0.8 GB |
221 s, 0.4 GB |
300,000 |
23 s, 1.0 GB |
31 s, 1.0 GB |
85 s, 1.7 GB |
650 s, 0.7 GB |
1,000,000 |
67 s, 1.7 GB |
116 s, 1.7 GB |
390 s, 4.9 GB |
2,191 s, 1.6 GB |
3,000,000 |
190 s, 2.9 GB |
445 s, 3.1 GB |
1,205 s, 13.8 GB |
5,001 s, 4.1 GB |
5,885,502 |
376 s, 3.1 GB |
977 s, 5.2 GB |
2,473 s, 26.8 GB |
10,331 s, 7.7 GB |
7,994,026 |
510 s, 3.2 GB |
1,354 s, 7.0 GB |
3,521 s, 35.9 GB |
16,663 s, 10.3 GB |
The figure’s “penalized-stream” line is the streamed solver; the in-memory
solver is its own line. solver="auto" uses the in-memory solver for this
model up to 200,000 rows and the streamed one beyond.
On all 8 million people, penalized-stream took 8.5 minutes and 3.2 GB; glmnet took 59 minutes and 36 GB, and scikit-learn 4.6 hours.
The in-memory solver is the fastest library up to 100,000 people (1.5 s against glmnet’s 2.1 s at 10,000). From about 150,000 rows the streamed solver is faster: its passes use every thread, while the in-memory solver runs one thread per model, and on all 8 million people it is 2.7 times as fast and needs half the memory.
The streamed solver is faster than glmnet from 30,000 people up (7 times at 8 million). Its fit reads the data about 330 times, a few reads per penalty for each of the six models fitted together, and its time grows in proportion to the rows.
Lasso multinomial logit: class of worker¶
A lasso multinomial logit of the class of worker (four classes) on 16 predictors of a person, 5-fold cross-validation over 100 penalties:
rows |
penalized-stream (streamed) |
penalized-stream (in memory) |
glmnet |
scikit-learn |
|---|---|---|---|---|
10,000 |
9.8 s, 0.6 GB |
5.2 s, 0.6 GB |
7.7 s, 0.7 GB |
69 s, 0.3 GB |
30,000 |
17 s, 0.8 GB |
12 s, 0.8 GB |
20 s, 1.7 GB |
146 s, 0.3 GB |
100,000 |
39 s, 1.0 GB |
44 s, 1.0 GB |
78 s, 4.5 GB |
381 s, 0.4 GB |
300,000 |
99 s, 1.2 GB |
161 s, 1.2 GB |
295 s, 12.8 GB |
1,048 s, 0.7 GB |
1,000,000 |
323 s, 1.6 GB |
651 s, 2.6 GB |
1,200 s, 40.9 GB |
4,213 s, 1.5 GB |
3,000,000 |
1,042 s, 1.8 GB |
2,640 s, 5.9 GB |
out of memory |
13,101 s, 4.0 GB |
5,871,734 |
2,104 s, 1.8 GB |
6,040 s, 9.9 GB |
With the grouped penalty (a predictor’s indicators enter or leave every class’s equation together), and with the 2,462 PUMAs absorbed:
rows |
penalized-stream (grouped) |
glmnet (grouped) |
penalized-stream (PUMA fixed effects) |
|---|---|---|---|
10,000 |
36 s, 0.6 GB |
30 s, 0.7 GB |
49 s, 1.5 GB |
30,000 |
39 s, 0.8 GB |
79 s, 1.7 GB |
63 s, 1.4 GB |
100,000 |
64 s, 0.9 GB |
395 s, 4.5 GB |
117 s, 1.4 GB |
300,000 |
121 s, 1.2 GB |
1,731 s, 12.7 GB |
253 s, 1.5 GB |
1,000,000 |
343 s, 1.5 GB |
6,152 s, 40.9 GB |
706 s, 1.5 GB |
3,000,000 |
937 s, 1.7 GB |
over 6 hours |
1,981 s, 1.6 GB |
5,871,734 |
The figure’s “penalized-stream” line is the streamed solver. solver="auto"
uses the in-memory solver for this model up to about 98,000 rows, while one
model’s per-row state fits in the processor’s cache, and the streamed one
beyond.
On all 5.9 million workers, penalized-stream’s streamed solver took 35 minutes and 1.8 GB. glmnet ran out of 64 GB at 3 million workers, and its grouped fit did not finish within 6 hours; scikit-learn took 3.6 hours at 3 million.
The in-memory solver is the fastest library at 10,000 and 30,000 workers. From 100,000 up the streamed solver is the fastest, 2 to 4 times faster than glmnet and 10 to 13 times faster than scikit-learn, with a fraction of glmnet’s memory.
The grouped penalty costs penalized-stream little beyond the ungrouped fit at large sizes (937 s against 1,042 s at 3 million); glmnet’s grouped fit is 5 times slower than its ungrouped one, and 18 times slower than penalized-stream’s at 1 million.
Where both ran, penalized-stream’s and glmnet’s cross-validated deviances agree to within 0.1%.
Lasso ordered logit: educational attainment¶
A lasso ordered logit of educational attainment (five levels) on 18 predictors of a person, 5-fold cross-validation over 100 penalties, and the same model with the 2,462 PUMAs absorbed:
rows |
penalized-stream |
penalized-stream (PUMA fixed effects) |
ordinalNet |
|---|---|---|---|
10,000 |
3.9 s, 0.6 GB |
15 s, 0.6 GB |
428 s, 0.7 GB |
30,000 |
6.2 s, 0.7 GB |
45 s, 0.7 GB |
1,460 s, 1.3 GB |
100,000 |
14 s, 1.0 GB |
81 s, 0.9 GB |
4,732 s, 3.4 GB |
300,000 |
37 s, 1.1 GB |
216 s, 1.2 GB |
14,694 s, 8.3 GB |
1,000,000 |
117 s, 1.6 GB |
601 s, 1.5 GB |
over 6 hours |
3,000,000 |
350 s, 1.8 GB |
1,960 s, 1.6 GB |
not run |
5,885,502 |
670 s, 1.9 GB |
3,809 s, 1.7 GB |
not run |
7,994,026 |
918 s, 1.8 GB |
5,097 s, 1.5 GB |
not run |
On all 8 million people, penalized-stream took 15 minutes and 1.8 GB, and with the PUMAs absorbed 85 minutes and 1.5 GB. Its memory barely grows with the rows.
Where both ran, penalized-stream was 110 to 400 times faster than ordinalNet, and the gap widens with the rows. ordinalNet took 4.1 hours at 300,000 people and did not finish within 6 hours at 1 million, so it was not run on more.
The two select about the same covariates (71 against 73 at 10,000, 102 against 101 at 300,000), and their cross-validated deviances agree to 0.1% or better.
What the results show¶
Large data. On every model, penalized-stream is the fastest library from about 100,000 rows up, and it fitted every model on all the rows: 2.6 minutes for the wage lasso on 5.9 million workers, 8.5 minutes for the employment logit on 8 million people, 35 minutes for the multinomial logit and 15 for the ordered logit. Its memory stays under 9 GB however many rows there are, because it streams the data rather than holding it.
Where the others ran out. glmnet did not finish the wage lasso on 5.9 million workers within an hour, and ran out of 64 GB on the multinomial logit at 3 million. biglasso and scikit-learn’s
LassoCVpassed an hour at 1 million, hdm ran out of 32 GB at 300,000 workers, and ordinalNet passed 6 hours at 1 million.Where the others win. On small data the differences are seconds: glmnet is faster on the wage lasso at 10,000 workers (3.6 s against 4.9 s), and its grouped multinomial at 10,000 (30 s against 36 s). The in-memory libraries also use less memory at small sizes; penalized-stream’s wage lasso reserves its memory budget for forming the cross-products even when the data are small.
Absorbed fixed effects (the 2,462 PUMAs) are something none of the other libraries offer. They cost penalized-stream from almost nothing (the wage lasso) to about 6 times the fit without them (the ordered logit).
Reproducing¶
pip install -e ".[benchmark]"
micromamba create -p benchmarks/external/.r -f benchmarks/external/environment.yml
python benchmarks/prepare_acs.py # the ACS download (2.2 GB) and the sample
python benchmarks/acs_benchmark.py # every model, every size
python benchmarks/plot_benchmarks.py # the figures
benchmarks/README.md describes the harness, the options and the R setup.