Skip to content

kumo-pytorch ingest fails with "Too many open files" at the default limit #372

Closed

Description

@anle2024

Type: bug
Area: DiskGraph ingest through DiskGraphEngine (the in-process diskgraph.ingest call)
Found on: NVIDIA/kumo-engine main 58eac88 with the DiskGraph CI wheel from 2f7171f, Linux x86_64, Python 3.12, in scale runs. The repro ran on 08a0e9c (PR 353 head), Linux aarch64, Python 3.12, with a DiskGraph wheel built from the same commit.

What happens

On large inputs, DiskGraph picks many shards, and ingest then needs more open files than the default Linux soft limit of 1024. Ingest stops at once with Too many open files (os error 24), and kumo-pytorch cannot build the index. In scale runs, 11 cases at the 10B scale ran at this limit, and all 11 failed in ingest. Kumo Engine ingests the same data on the same machines without this error.

Reproduce

Run this script with kumo-pytorch and diskgraph installed. It sets 256 shards, so a small input needs as many files as a large one.

import resource
import tempfile
from pathlib import Path

import pyarrow as pa
import pyarrow.parquet as pq

from kumo.pytorch import api

I64 = api.DType("int64")
TS = api.DType("timestamp", unit="s", timezone="UTC")
USERS, EVENTS, SHARDS = 20000, 200000, 256

schema = api.DataSchema(
    (
        api.TableSpec("users", "user_id", {"user_id": I64}, time_column=api.NON_TEMPORAL),
        api.TableSpec("events", "event_id", {"event_id": I64, "user_id": I64, "at": TS, "ts": TS}, time_column="at"),
    ),
    (api.RelationSpec("user_events", "users", "user_id", "events", "user_id"),),
)
rows = api.Rows(("user_events",), api.TimeWindow("at"))
sample = api.SampleSpec(api.EntitySpec("users"), entity_values={"mode_ts": api.Aggregate(rows, "mode", "ts", dtype=TS)})
fields = (api.Encode(field="mode_ts", encoding=api.Raw()),)
batch = api.BatchSpec({"entity": api.Input(api.EntitySource(), api.Fields(fields=fields), api.Separate())})
contract = api.DataLoaderSpec(schema, sample, batch)


def ingest(root):
    users = pa.table({"user_id": pa.array(range(USERS), pa.int64())})
    events = pa.table(
        {
            "event_id": pa.array(range(EVENTS), pa.int64()),
            "user_id": pa.array([i % USERS for i in range(EVENTS)], pa.int64()),
            "at": pa.array([1700000000 + i for i in range(EVENTS)], pa.timestamp("s")),
            "ts": pa.array([1700000000 + i % 7 for i in range(EVENTS)], pa.timestamp("s")),
        }
    )
    pq.write_table(users, root / "users.parquet")
    pq.write_table(events, root / "events.parquet")
    dataset = api.Dataset({"users": api.Parquet(str(root / "users.parquet")), "events": api.Parquet(str(root / "events.parquet"))})
    engine = api.DiskGraphEngine(index=root / "index", num_threads=1, num_shards=SHARDS)
    with api.prepare(contract, dataset, engine):
        pass


soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
for limit in (1024, hard):
    resource.setrlimit(resource.RLIMIT_NOFILE, (limit, hard))
    with tempfile.TemporaryDirectory() as tmp:
        try:
            ingest(Path(tmp))
            print(f"soft limit {limit}, {SHARDS} shards: ingest ok")
        except Exception as error:
            print(f"soft limit {limit}, {SHARDS} shards: {type(error).__name__}: {error}")
print("expected: ingest succeeds at the default soft limit 1024, as the same ingest does through Kumo Engine")

Output:

soft limit 1024, 256 shards: DiskgraphSystemError: Ingest failed: Too many open files (os error 24)
soft limit 1048576, 256 shards: ingest ok
expected: ingest succeeds at the default soft limit 1024, as the same ingest does through Kumo Engine

DiskGraph also prints two cleanup warnings on stderr. They are left out because they contain local paths.

In the scale runs, 10 of the 11 failed runs show DiskgraphSystemError: Ingest failed: node writer failed: Too many open files (os error 24). One run shows node writer channel error: sending on a closed channel. A comment at packages/diskgraph/diskgraph-ingest/src/lib.rs:14234-14236 says that this message can hide a writer error such as EMFILE. DiskGraph chose 33 to 127 shards from the memory budget there, although the runs asked for 1.

Expected

Kumo Engine raises the limit before every ingest, so the same input does not fail there:

  • packages/kumo-core/src/kumo_core/utils/nofile.py:19 says "Raise the soft RLIMIT_NOFILE to the hard limit, once per process." packages/kumo-engine/kumo/engine/init.py:160 calls ensure_nofile().
  • packages/diskgraph/diskgraph-ingest/src/bin/ingest.rs:216 calls increase_nofile_limit(); at the start of the ingest binary.
  • A comment at packages/kumo-core/src/kumo_core/diskgraph/runner.py:611-613 names this failure. Encode holds one temp file per table and shard, so the default limit of 1024 can fail.

kumo-pytorch builds the same kind of index, so it must handle the same limit.

Cause

  • The encode phase opens a writer per table and shard, and keeps it open until the phase ends (packages/diskgraph/diskgraph-ingest/src/lib.rs:14314-14357). Each writer holds a data file, a primary key file and two files per foreign key.
  • On one 10B scale case, ingest held about 65 open files per shard. So 33 shards need about 2100 files.
  • The shard count is the larger of the requested count and a memory floor (packages/diskgraph/diskgraph-ingest/src/lib.rs:652-654). Large inputs get a high floor.
  • kumo-pytorch calls the Python binding in its own process (src/kumo/pytorch/materialization.py:142). Neither kumo-pytorch nor the binding (packages/diskgraph/diskgraph-pybind/src/lib.rs:1496) raises the limit.

Possible fix

kumo-pytorch can raise the soft limit to the hard limit before it calls diskgraph.ingest, as kumo-core does. Another option is to raise the limit inside the DiskGraph library, so every caller gets it. DiskGraph can also compare the limit with the planned file count and fail early with a clear message.

Scope

  • The failure needs shards times files per shard to go above the soft limit. With about 65 files per shard, 16 shards are enough.
  • In the scale runs, all 11 cases at 10B that ran at limit 1024 failed. All 12 cases at 10B passed after the limit was raised.
  • A raised hard limit alone does not help, because the soft limit stays at 1024.

Activity

  1. added a commit that references this issue on Nov 20, 2026
    d433752
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions