Support Zstd compression - #3145
Conversation
|
I'd like to benchmark this but I'm having some infra troubles with the server where I usually run these things. I'll post a benchmark in the next ~24 hours. |
|
Here's that benchmark. It just reads a file with (between these two I ran |
|
@epatey and @dragonstyle will these logs be readable by the viewer? |
Currently, no. The viewer currently only implements the standard DEFLATE algorithm right now. It would pretty easy to add, making future versions support it, but log files written with zstd would be unreadable to old inspect view clients, which isn't great. |
|
We could get support for zstd on older Python with this: https://github.com/taisei-project/python-zipfile-zstd It seems like this might be worthwhile given how substantial the savings are! @dragonstyle I am not super worried about older versions of the viewer as generally just to keep up with the latest models users need to upgrade quite frequently. We could include a conversation tool that converts logs to use the older compression which people could run in batch as required. @kerrickstaley I'm more excited about this if we can make it work everywhere (as I think with just the env var it will be very infrequently used). |
|
I've added support within the viewer for decompressing zstd streams here: |
Okay, that is now merged! Here's what I propose:
|
bdb97b7 to
7d46888
Compare
|
@epatey tagging you for review as I know we have other places that we read from zip streams that may need the If other folks have code that cracks our zip files directly I am wondering if our |
46a1318 to
45e4450
Compare
|
@jjallaire done! |
45e4450 to
b5d48d6
Compare
If the env var INSPECT_USE_ZSTD is set (to any non-empty string), we will use Zstd for ZipFile compression. On Python 3.14 this is supported in the stdlib; on Python < 3.14 we use zipfile-zstd which backports this functionality. Note that files written with Zstd will not be readable if the reader is on an older inspect-ai version and is using Python < 3.14. Zstd is much faster (at a given compression ratio) than Zlib's deflate.
b5d48d6 to
81da23c
Compare
Yes, it will, as long as they have run some code path which has imported |
|
Or maybe put it in inspect_ai/log/__init__.py to scope it down a bit more?
(I think if people are explicitly importing log functions it’s fair game)
…On Sun, Feb 1, 2026 at 6:17 PM Kerrick Staley ***@***.***> wrote:
*kerrickstaley* left a comment (UKGovernmentBEIS/inspect_ai#3145)
<#3145 (comment)>
we have other places that we read from zip streams that may need the
**zipfile_compress_kwargs
zipfile_compress_kwargs is just for writing, not reading. Reading will
work transparently on Python 3.14 or if zipfile_zstd has been imported.
I am wondering if our import zipfile_zstd will cover them (since it monkey
patches)
Yes, it will, as long as they have run some code path which has imported
_util/zipfile.py. Maybe we should move the zipfile_zstd import to
src/inspect_ai/__init__.py?
—
Reply to this email directly, view it on GitHub
<#3145 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAZPR6ABQPWJ2XIJGFC4DT4J2CRJAVCNFSM6AAAAACTRYTUPWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTQMZSGI2DSOJWHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
@kerrickstaley, this looks awesome. We do have two additional scenarios that I'll have to tackle.
I should be able to get to them this week. |
Done |
|
@kerrickstaley, if convenient, can you share a few evals that you've created with zstd for my testing. |
|
@kerrickstaley, I've finished the One thing I want to consider is if there's a way to lazy import Thoughts? |
|
Running If we wanted to reduce this I agree we can catch the exception, import, and try again. |
|
@epatey @jjallaire is this OK to merge? Like I mentioned before I think we don't have to do anything about the |
# Conflicts: # src/inspect_ai/log/_recorders/eval.py # uv.lock
If the env var INSPECT_USE_ZSTD is set (to any non-empty string), we will use Zstd for ZipFile compression. On Python versions < 3.14, this will use the zipfile-zstd package which backports support for Zstd in ZipFile.
Zstd is much faster (at a given compression ratio) than Zlib's deflate.
This PR contains:
What is the new behavior?
Reading and writing eval logs is faster and the resultant files are smaller. On my benchmark, reading was slightly faster, writing was 2x faster, and the file size was 60% smaller.
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
Yes. Logs written with a new version of inspect-ai and the env var set will not be readable on old versions of inspect-ai with Python < 3.14. This is easily fixed by upgrading the reader's inspect-ai version (no Python version upgrade required).