Skip to content

Fix multi-node append duplicating existing chunks in index.json - #866

Open
eeshsaxena wants to merge 1 commit into
Lightning-AI:mainfrom
eeshsaxena:fix-multinode-append-duplicate-chunks
Open

Fix multi-node append duplicating existing chunks in index.json#866
eeshsaxena wants to merge 1 commit into
Lightning-AI:mainfrom
eeshsaxena:fix-multinode-append-duplicate-chunks

Conversation

@eeshsaxena

Copy link
Copy Markdown

Fixes #865.

When you run optimize(mode="append") across more than one node, the existing dataset chunks end up repeated once per node in the final index.json.

The cause is in the two-stage merge. Each node calls _merge_no_wait(node_rank, existing_index) in _done, and _merge_no_wait prepends existing_index["chunks"] to that node's {node_rank}-index.json. So every node's index file already contains the existing chunks. The last node then merges all of those per-node files together, and the existing chunks come along once for each node:

existing [A, B], node 0 adds [C], node 1 adds [D]
  node 0 -> 0-index.json = [A, B, C]
  node 1 -> 1-index.json = [A, B, D]
  final merge -> [A, B, C, A, B, D]   # wanted [A, B, C, D]

The fix adds the existing index only once. The single-node path is unchanged: it still folds the existing index in at the node-level merge. For multiple nodes, the per-node merges now carry only their own new chunks, and the existing index is folded in at the final cross-node merge instead:

  node 0 -> 0-index.json = [C]
  node 1 -> 1-index.json = [D]
  final merge (with existing) -> [A, B, C, D]

I added a test in tests/streaming/test_writer.py that walks both patterns: it shows the old per-node folding produces [A, B, C, A, B, D], and the new final-merge folding produces [A, B, C, D]. It passes locally.

With optimize(mode="append") and num_nodes > 1, every node folded the
existing index into its own {node_rank}-index.json. The final cross-node
merge then concatenated all of those, so the existing chunks ended up in the
result once per node: existing [A, B] with new [C] and [D] across two nodes
came out as [A, B, C, A, B, D] instead of [A, B, C, D].

Add the existing index only once. For a single node it still goes in at the
node-level merge as before. For multiple nodes the per-node merges now carry
only their own new chunks, and the existing index is folded in at the final
merge that combines the per-node files.
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.

Multi-node optimize(mode="append") duplicates existing dataset chunks N times in index.json

1 participant