Skip to content

feat/fix github actions cache#403

Draft
Theoreticallyhugo wants to merge 4 commits into
mainfrom
feat/fix-github-actions-cache
Draft

feat/fix github actions cache#403
Theoreticallyhugo wants to merge 4 commits into
mainfrom
feat/fix-github-actions-cache

Conversation

@Theoreticallyhugo
Copy link
Copy Markdown
Contributor

@Theoreticallyhugo Theoreticallyhugo commented Mar 30, 2026

for every pre-commit run of our github actions, we rebuild the .venv, which takes long and consumes resources. this pr tries to address that with a mix of better caching and a more sensible choice of dependencies.

main result:
pre-commit runs are about a minute faster.

details:

  • limited the .venv of the pre-commit runs to --only-group cicd. this removes lots of large nvidia and torch libraries and speeds up the .venv creation by about a minute. (previously it was about a minute, now its about a second)
  • changed that the uv cache is bound to the uv.lock file
  • added a comment that would enable us to cache the .venv if we wanted to have a look at that again

@Theoreticallyhugo Theoreticallyhugo force-pushed the feat/fix-github-actions-cache branch from d4f5461 to af06b52 Compare March 30, 2026 16:47
@Theoreticallyhugo Theoreticallyhugo force-pushed the feat/fix-github-actions-cache branch from af06b52 to bcc0a18 Compare March 30, 2026 16:52
@ArneBinder
Copy link
Copy Markdown
Contributor

How much is the decrease in runtime?

@Theoreticallyhugo
Copy link
Copy Markdown
Contributor Author

Theoreticallyhugo commented Mar 30, 2026

How much is the decrease in runtime?

well, I'm still experimenting...
so far i found out that:

  • caching the .venv makes no sense with our default .venv, as all the nvidia and torch dependencies blow it up. (this is actually slower than what we normally do. ~3/~3.5 mins to ~4 mins)
  • something about our uv caching seems to have been wrong, but i don't see any changes in how long building the .venv takes 😅
  • the main issue is our venv being too big, so we could
    • switch the pre-commit run to uv run --only-group cicd ... as this drastically reduces the .venv size. this is safe as the pre-commit requirements don't change. (for this, building the .venv goes from ~1 min to <1sec)
    • switch the pre-commit run to uvx pre-commit ... this would make lots of sense, but is not really possible whilst using mypy. if however we are switching to zuban Feat/switch to zuban from mypy #405, this would work nicely. we could then call uvx prek ... which in turn would call uvx zuban and everything would be clean...
    • switch the pytest run to uv run --only-group pytest-cicd .... if such group was created, it may break in the future if a test is added that requires a package that is not in the cicd group. i'm not entirely sure i would wanna do that trade (any packages for normal execution as well as the "not slow" tests in cicd would then live in the normal group as well as cicd i think)

@Theoreticallyhugo Theoreticallyhugo force-pushed the feat/fix-github-actions-cache branch 2 times, most recently from 7800ed8 to 0d3d36f Compare March 30, 2026 17:54
@ArneBinder
Copy link
Copy Markdown
Contributor

ArneBinder commented Mar 30, 2026

side note: pre-commit on CI seems to take 165s (see here)

@Theoreticallyhugo
Copy link
Copy Markdown
Contributor Author

Theoreticallyhugo commented Mar 31, 2026

side note: pre-commit on CI seems to take 165s (see here)

as this pr doesn't aim to change anything about pre-commit speeds, i only measure the .venv setup that comes before it.

usually, setting up the .venv took about a minute, as shown here:

Mon, 30 Mar 2026 14:26:58 GMT
Run uv run --group cicd pre-commit run -a
Mon, 30 Mar 2026 14:26:59 GMT Using CPython 3.10.20 interpreter at: /opt/hostedtoolcache/Python/3.10.20/x64/bin/python3.10
Mon, 30 Mar 2026 14:26:59 GMT Creating virtual environment at: .venv
Mon, 30 Mar 2026 14:26:59 GMT    Building kibad-llm @ file:///home/runner/work/kibad-llm/kibad-llm
Mon, 30 Mar 2026 14:26:59 GMT Downloading uvloop (3.5MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading scipy (35.9MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading transformers (11.4MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading mypy (12.9MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading babel (9.7MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading pycountry (6.0MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading sympy (6.0MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading virtualenv (5.7MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading fonttools (4.6MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading cryptography (4.3MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading psycopg2-binary (4.0MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading mkdocs (3.7MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading numba (3.6MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading hf-xet (3.2MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading tokenizers (3.1MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading pdfminer-six (6.3MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-cuda-nvrtc-cu12 (84.0MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-nvjitlink-cu12 (37.4MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-cudnn-cu12 (674.0MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading llvmlite (40.4MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-cublas-cu12 (566.8MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-cusparselt-cu12 (273.9MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-cufft-cu12 (184.2MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-cusolver-cu12 (255.1MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading pymupdf (23.0MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-curand-cu12 (60.7MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-nccl-cu12 (307.4MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-cuda-cupti-cu12 (9.8MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading numpy (16.0MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-cusparse-cu12 (274.9MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading matplotlib (8.3MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading pandas (12.2MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading notebook (13.8MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-nvshmem-cu12 (118.9MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading cupy-cuda12x (107.0MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading mistral-common (6.2MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading jupyterlab (11.8MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading pillow (6.7MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading cuda-bindings (15.6MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading opencv-python-headless (59.6MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading vllm (444.9MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading triton (162.4MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading nvidia-cutlass-dsl (55.9MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading torch (858.1MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading ray (68.8MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading pyarrow (45.3MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading llama-index-core (11.4MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading flashinfer-python (6.7MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading xgrammar (8.5MiB)
Mon, 30 Mar 2026 14:26:59 GMT Downloading torchvision (7.7MiB)
Mon, 30 Mar 2026 14:27:02 GMT  Downloaded tokenizers
Mon, 30 Mar 2026 14:27:02 GMT  Downloaded hf-xet
Mon, 30 Mar 2026 14:27:02 GMT Downloading sqlalchemy (3.1MiB)
Mon, 30 Mar 2026 14:27:02 GMT Downloading debugpy (2.9MiB)
Mon, 30 Mar 2026 14:27:02 GMT  Downloaded mkdocs
Mon, 30 Mar 2026 14:27:02 GMT  Downloaded uvloop
Mon, 30 Mar 2026 14:27:02 GMT Downloading pypdfium2 (2.9MiB)
Mon, 30 Mar 2026 14:27:02 GMT Downloading llguidance (2.9MiB)
Mon, 30 Mar 2026 14:27:03 GMT  Downloaded psycopg2-binary
Mon, 30 Mar 2026 14:27:03 GMT Downloading openai-harmony (2.8MiB)
Mon, 30 Mar 2026 14:27:03 GMT  Downloaded numba
Mon, 30 Mar 2026 14:27:03 GMT Downloading outlines-core (2.2MiB)
Mon, 30 Mar 2026 14:27:03 GMT  Downloaded cryptography
Mon, 30 Mar 2026 14:27:03 GMT  Downloaded fonttools
Mon, 30 Mar 2026 14:27:03 GMT Downloading pydantic-core (2.0MiB)
Mon, 30 Mar 2026 14:27:03 GMT Downloading widgetsnbextension (2.1MiB)
Mon, 30 Mar 2026 14:27:04 GMT  Downloaded virtualenv
Mon, 30 Mar 2026 14:27:04 GMT Downloading torchaudio (2.0MiB)
Mon, 30 Mar 2026 14:27:04 GMT  Downloaded pycountry
Mon, 30 Mar 2026 14:27:04 GMT Downloading apache-tvm-ffi (2.0MiB)
Mon, 30 Mar 2026 14:27:04 GMT  Downloaded pdfminer-six
Mon, 30 Mar 2026 14:27:04 GMT  Downloaded mistral-common
Mon, 30 Mar 2026 14:27:04 GMT Downloading nvidia-cudnn-frontend (1.9MiB)
Mon, 30 Mar 2026 14:27:04 GMT  Downloaded debugpy
Mon, 30 Mar 2026 14:27:04 GMT  Downloaded sqlalchemy
Mon, 30 Mar 2026 14:27:04 GMT Downloading networkx (1.6MiB)
Mon, 30 Mar 2026 14:27:04 GMT Downloading aiohttp (1.6MiB)
Mon, 30 Mar 2026 14:27:04 GMT Downloading kiwisolver (1.6MiB)
Mon, 30 Mar 2026 14:27:04 GMT  Downloaded pydantic-core
Mon, 30 Mar 2026 14:27:05 GMT Downloading jedi (1.5MiB)
Mon, 30 Mar 2026 14:27:05 GMT  Downloaded pypdfium2
Mon, 30 Mar 2026 14:27:05 GMT  Downloaded outlines-core
Mon, 30 Mar 2026 14:27:05 GMT  Downloaded llguidance
Mon, 30 Mar 2026 14:27:05 GMT Downloading pygments (1.2MiB)
Mon, 30 Mar 2026 14:27:05 GMT Downloading nltk (1.4MiB)
Mon, 30 Mar 2026 14:27:05 GMT Downloading sentencepiece (1.3MiB)
Mon, 30 Mar 2026 14:27:05 GMT  Downloaded widgetsnbextension
Mon, 30 Mar 2026 14:27:05 GMT  Downloaded openai-harmony
Mon, 30 Mar 2026 14:27:05 GMT Downloading nvidia-cufile-cu12 (1.1MiB)
Mon, 30 Mar 2026 14:27:05 GMT Downloading tiktoken (1.1MiB)
Mon, 30 Mar 2026 14:27:05 GMT  Downloaded pillow
Mon, 30 Mar 2026 14:27:05 GMT Downloading setuptools (1.0MiB)
Mon, 30 Mar 2026 14:27:05 GMT  Downloaded torchvision
Mon, 30 Mar 2026 14:27:05 GMT Downloading openai (1.0MiB)
Mon, 30 Mar 2026 14:27:05 GMT  Downloaded sympy
Mon, 30 Mar 2026 14:27:05 GMT  Downloaded torchaudio
Mon, 30 Mar 2026 14:27:06 GMT  Downloaded nvidia-cufile-cu12
Mon, 30 Mar 2026 14:27:06 GMT  Downloaded apache-tvm-ffi
Mon, 30 Mar 2026 14:27:06 GMT  Downloaded tiktoken
Mon, 30 Mar 2026 14:27:06 GMT  Downloaded kiwisolver
Mon, 30 Mar 2026 14:27:06 GMT  Downloaded aiohttp
Mon, 30 Mar 2026 14:27:06 GMT  Downloaded sentencepiece
Mon, 30 Mar 2026 14:27:06 GMT  Downloaded nvidia-cudnn-frontend
Mon, 30 Mar 2026 14:27:06 GMT  Downloaded pygments
Mon, 30 Mar 2026 14:27:06 GMT  Downloaded matplotlib
Mon, 30 Mar 2026 14:27:06 GMT  Downloaded xgrammar
Mon, 30 Mar 2026 14:27:07 GMT  Downloaded nltk
Mon, 30 Mar 2026 14:27:07 GMT  Downloaded networkx
Mon, 30 Mar 2026 14:27:07 GMT  Downloaded setuptools
Mon, 30 Mar 2026 14:27:07 GMT  Downloaded flashinfer-python
Mon, 30 Mar 2026 14:27:07 GMT  Downloaded nvidia-cuda-cupti-cu12
Mon, 30 Mar 2026 14:27:07 GMT  Downloaded babel
Mon, 30 Mar 2026 14:27:09 GMT  Downloaded transformers
Mon, 30 Mar 2026 14:27:09 GMT  Downloaded openai
Mon, 30 Mar 2026 14:27:10 GMT  Downloaded jupyterlab
Mon, 30 Mar 2026 14:27:10 GMT    Building antlr4-python3-runtime==4.9.3
Mon, 30 Mar 2026 14:27:10 GMT  Downloaded llama-index-core
Mon, 30 Mar 2026 14:27:10 GMT  Downloaded pandas
Mon, 30 Mar 2026 14:27:11 GMT  Downloaded jedi
Mon, 30 Mar 2026 14:27:11 GMT  Downloaded notebook
Mon, 30 Mar 2026 14:27:12 GMT  Downloaded mypy
Mon, 30 Mar 2026 14:27:13 GMT  Downloaded cuda-bindings
Mon, 30 Mar 2026 14:27:13 GMT  Downloaded numpy
Mon, 30 Mar 2026 14:27:13 GMT       Built antlr4-python3-runtime==4.9.3
Mon, 30 Mar 2026 14:27:16 GMT       Built kibad-llm @ file:///home/runner/work/kibad-llm/kibad-llm
Mon, 30 Mar 2026 14:27:16 GMT  Downloaded pymupdf
Mon, 30 Mar 2026 14:27:18 GMT  Downloaded scipy
Mon, 30 Mar 2026 14:27:19 GMT  Downloaded nvidia-nvjitlink-cu12
Mon, 30 Mar 2026 14:27:19 GMT  Downloaded llvmlite
Mon, 30 Mar 2026 14:27:23 GMT  Downloaded nvidia-curand-cu12
Mon, 30 Mar 2026 14:27:23 GMT  Downloaded opencv-python-headless
Mon, 30 Mar 2026 14:27:23 GMT  Downloaded nvidia-cutlass-dsl
Mon, 30 Mar 2026 14:27:24 GMT  Downloaded pyarrow
Mon, 30 Mar 2026 14:27:26 GMT  Downloaded nvidia-cuda-nvrtc-cu12
Mon, 30 Mar 2026 14:27:29 GMT  Downloaded nvidia-nvshmem-cu12
Mon, 30 Mar 2026 14:27:29 GMT  Downloaded cupy-cuda12x
Mon, 30 Mar 2026 14:27:30 GMT  Downloaded ray
Mon, 30 Mar 2026 14:27:33 GMT  Downloaded triton
Mon, 30 Mar 2026 14:27:34 GMT  Downloaded nvidia-cufft-cu12
Mon, 30 Mar 2026 14:27:38 GMT  Downloaded nvidia-cusolver-cu12
Mon, 30 Mar 2026 14:27:39 GMT  Downloaded nvidia-cusparselt-cu12
Mon, 30 Mar 2026 14:27:39 GMT  Downloaded nvidia-cusparse-cu12
Mon, 30 Mar 2026 14:27:40 GMT  Downloaded nvidia-nccl-cu12
Mon, 30 Mar 2026 14:27:44 GMT  Downloaded vllm
Mon, 30 Mar 2026 14:27:44 GMT  Downloaded nvidia-cublas-cu12
Mon, 30 Mar 2026 14:27:45 GMT  Downloaded nvidia-cudnn-cu12
Mon, 30 Mar 2026 14:27:54 GMT  Downloaded torch
Mon, 30 Mar 2026 14:27:57 GMT Installed 312 packages in 3.72s

with the changes proposed in this pr, this setup time goes down to about one second.

Mon, 30 Mar 2026 17:55:08 GMT
Run uv run --only-group cicd pre-commit run -a
Mon, 30 Mar 2026 17:55:08 GMT Using CPython 3.10.20 interpreter at: /opt/hostedtoolcache/Python/3.10.20/x64/bin/python3.10
Mon, 30 Mar 2026 17:55:08 GMT Creating virtual environment at: .venv
Mon, 30 Mar 2026 17:55:08 GMT Downloading virtualenv (5.7MiB)
Mon, 30 Mar 2026 17:55:08 GMT Downloading pygments (1.2MiB)
Mon, 30 Mar 2026 17:55:08 GMT Downloading mypy (12.9MiB)
Mon, 30 Mar 2026 17:55:08 GMT  Downloaded virtualenv
Mon, 30 Mar 2026 17:55:08 GMT  Downloaded pygments
Mon, 30 Mar 2026 17:55:09 GMT  Downloaded mypy
Mon, 30 Mar 2026 17:55:09 GMT Installed 26 packages in 59ms

now you might be wondering why both cicd runs took about two minutes forty for the pre-commit section. if we look closely, we can see that on one of the runs, mypy is a full minute slower than on the other. this is a separate issue that i am therefore addressing in #405.

conclusion:

i would commit the changes as proposed here, but maybe make one more change in the future:
whilst i need to test this further, i think it would make sense to switch from uv run pre-commit ... to uvx prek and uvx zuban eventually, as this would cleanly separate our dependencies.
EDIT: no i would not wanna switch to uvx. tried it and its a hassle.

@ArneBinder
Copy link
Copy Markdown
Contributor

Thanks a lot for the detailed breakdown, I think this is convincing. But please distill a complete PR description from your comments (guiding questions: what/why/how changes and are there side effects).

@Theoreticallyhugo Theoreticallyhugo marked this pull request as ready for review March 31, 2026 10:36
@Theoreticallyhugo Theoreticallyhugo marked this pull request as draft March 31, 2026 11:38
@Theoreticallyhugo
Copy link
Copy Markdown
Contributor Author

I have come to realise that some of these changes don't really make sense in the grand scheme of things.

limiting the package install for our cicd pipeline to those packages that are needed technically makes sense. in an ideal world we would only need the cicd tools like prek and zuban and the stubs packages that allow zuban to typecheck everything.

sadly however, not all packages supply stubs, and even more sadly it's the packages with the largest dependencies. this means that we still need to install all the torch and nvidia stuff, blowing up the cicd venv. (thanks nvidia and facebook...)

so, because of these select few packages that are massive but required, we either spend lots of time on building a .venv, or lots of time on mypy building the same exact venv before it checks the code.
i had thought that the speedy tiny venv in combination with zuban would be blazing fast, and zuban is very fast, but we still need the .venv to be build the slow way.

so, we now have two choices:

  • basically close this pr and maybe eventually find a different way to speed this up (can't think of one right now)
  • merge this pr, and maintain the cicd package group in uv in such a way that it contains all dependencies zuban needs to check the types, which results in packages being in both the normal dependencies, as well as the cicd dependencies. (check out Feat/switch to zuban from mypy #405 to see what that would look like)

regardless of what we choose, this pr won't bring a big improvement in speed as hoped...

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.

2 participants