Skip to content

Keep nested directories in merge_index shard paths - #23

Merged
avgvi merged 2 commits into
mainfrom
fix/983-merge-index-nested-dirs
Oct 10, 2026
Merged

avgvi merged 2 commits into
mainfrom
fix/983-merge-index-nested-dirs

Conversation

@avgvi

@avgvi avgvi commented Oct 10, 2026

Copy link
Copy Markdown
Member

merge_index dropped intermediate directories from shard paths when MDS partitions sat more than one level below the merge root: _merge_index_from_list rebuilt each merged basename as os.path.join(os.path.basename(p.parent), basename), which keeps exactly one directory level, so a partition at out/group1/subdir2/ was listed as subdir2/shard.00000.mds and the merged dataset could not find its shards. This imports mosaicml/streaming#983 by @discobot with the original commit kept so the author stays credited, and addresses upstream issue mosaicml/streaming#959.

  • Add _get_partition_dirname(index_file_url, out), which resolves each partition's directory relative to the merge root (local against the local root, remote against the remote root, same scheme and bucket only) and returns None when the partition is not under out.
  • Use it in _merge_index_from_list; partitions outside out fall back to the previous single-level behaviour, so existing one-level layouts are unchanged.
  • Add test_get_partition_dirname (local, remote, tuple, root-level, cross-bucket and outside-root cases) and test_merge_index_from_root_local_nested, which writes four partitions at out/group{1,2}/subdir{1,2}, merges, and checks the basenames and a StreamingDataset read.

Checked locally on Python 3.12: SKIP=pyright pre-commit run --files streaming/base/util.py tests/test_util.py is clean; pytest tests/test_util.py -k "merge_index or partition_dirname" gives 12 passed for the two new tests, and the nested test fails on main with expected 4 shard files but got 2; the pre-existing Spark-backed test_merge_index_from_list_local and test_merge_index_from_root_local matrices (26 cases) could not run here because the only JDK present (Homebrew OpenJDK 26) is rejected by PySpark 3.5, so those rely on CI.

discobot and others added 2 commits June 11, 2026 18:50
merge_index prefixed each shard basename with only the immediate parent
directory of its partition index, so partitions nested more than one level
under the merge root ended up with shard paths that do not exist, breaking
downstream streaming with 404s (issue #959). Resolve each partition's
directory relative to the merge root instead, falling back to the previous
single-level behavior when a partition does not reside under the root.
Add a spark-free nested-layout regression test and unit tests for the new
path resolution helper.
@avgvi
avgvi merged commit 7589154 into main Oct 10, 2026
12 of 13 checks passed
@avgvi
avgvi deleted the fix/983-merge-index-nested-dirs branch October 10, 2026 02:37
@avgvi avgvi mentioned this pull request Oct 11, 2026
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