packmem 0.2.0: one memory-mapped table for every worker
packmem 0.2.0 is on PyPI and npm. A saved table can now be memory-mapped and read in place, so every process on a machine reads one copy of the data. In a PyTorch DataLoader with 4 workers over 665,298 LLaVA records, that took the whole machine from 16.0 GB with a Python list, and 1,810 MB with Hugging Face datasets, to 1,144 MB.
save() and open()
pip install -U packmemimport packmem
packmem.load_json("annotations.json").save("annotations.pkm") # once
rows = packmem.open("annotations.pkm") # milliseconds, whatever the size
rows[0]["conversations"][0]["value"]open() maps the file and reads rows, filters and JSON output straight from it. The process that opens it costs almost no memory of its own: the pages belong to the page cache, shared by every process that maps the file. Pickling an opened table sends only its path, so workers that receive it map the same pages.
Also in 0.2.0
share()tables are read in place by the processes that receive them, and by the process that shared them: the data exists once, in the file's pages, instead of once per worker.Table.__getitems__fetches a batch of records in one call; PyTorch's DataLoader uses it when it is there.- Node:
Table#share(),Table.fromShared(handle)andunshare()let worker threads read one table without a copy. Native builds also takePACKMEM_LOAD_THREADS=1for the file loaders.
npm install packmem@0.2.0// main thread
import { Worker } from "node:worker_threads"
import { loadJsonl } from "packmem"
const rows = loadJsonl("logs.jsonl")
new Worker("./worker.js", { workerData: rows.share() })
// worker.js
import { workerData } from "node:worker_threads"
import { Table } from "packmem"
const shared = Table.fromShared(workerData) // the same table, no copy
shared.count({ status: 404 })Upgrading
The byte form changed so arrays are aligned and can be read in place: pickles, share() files and to_bytes output from 0.1.x cannot be read by 0.2.0, and the reverse. Rebuild saved data from its source after upgrading. On Windows, save over a file that is open anywhere fails with an explanation; close the tables that have it open first.
Next
On main and not yet released: lists of records (the turns of a conversation) stored as sub-columns, the layout Arrow uses for a list of structs, with pandas-style operations on them; an opt-in hint="compact" that compresses long text with Zstandard; and conversion to and from Arrow tables. The full list is in the changelog, and the measurements behind this post are in RESULT_0.2.0.md.