-
Notifications
You must be signed in to change notification settings - Fork 78
: v1: value_mesh non materializing ctors #1475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shayne-fletcher
wants to merge
4
commits into
meta-pytorch:main
Choose a base branch
from
shayne-fletcher:export-D84259628
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
: v1: value_mesh non materializing ctors #1475
shayne-fletcher
wants to merge
4
commits into
meta-pytorch:main
from
shayne-fletcher:export-D84259628
+798
−27
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@shayne-fletcher has exported this pull request. If you are a Meta employee, you can view the originating Diff in D84259628. |
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 9, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 9, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 9, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 9, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 9, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
8fe0eb9
to
be4f6ca
Compare
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 9, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 9, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 9, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 9, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 9, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
Summary: a land race broke the build. this unbreaks it. e.g. https://github.com/meta-pytorch/monarch/actions/runs/18395814024/job/52415081024?fbclid=IwY2xjawNVc1lleHRuA2FlbQIxMQBicmlkETF6NEVEYjFJYkd2TllBN0Z1AR6M9_nr0nZHZkhPEGCEN78p5vksKkAo4l3NTVipFZg7eRVyiTlURMebon7Dsw_aem_ARCzhbyLDhs42dlnUovZsg Reviewed By: samlurye, dcci Differential Revision: D84323033
Summary: this diff introduces a v0 basic run-length-encoded (RLE) internal representation for `ValueMesh<T>` and updates all APIs to operate transparently over either dense or compressed data. the compression support is purely additive. public semantics are unchanged: a mesh still represents a complete mapping from rank -> value, and iteration, slicing, and region order behave identically (note: complexity of `get()` is O(log k) in compressed mode vs O(1) dense). the compressed form is lossless and idempotent. compression is manual in rust because automatic detection isn't possible in a fully generic type. i originally considered doing it automatically, but rust provides no specialization or reflection to determine whether a given `T` has meaningful equality semantics. for many types (e.g. futures, closures) equality doesn't even exist. because of that, compression must be explicitly invoked via `compress_adjacent_in_place()` or `compress_adjacent_in_place_by(pred)` when the caller knows adjacent elements can be merged. in python, compression happens automatically on construction. for `Py<PyAny>`, equality is defined by pointer identity (`a.as_ptr() == b.as_ptr()`), so adjacent references to the same python object are coalesced into RLE runs. this will produce savings for sentinel-rich, categorical, or boolean data (e.g. repeated `None`, booleans, cpython-interned small integers and strings) but will have little effect for freshly allocated numbers or dynamic objects. Differential Revision: D84169361
Summary: this change enables serde serialization and deserialization for `ValueMesh<T>` and its internal representations. it introduces a stable wire format for run-length encoded (RLE) meshes by defining a `Run` struct (`u64` bounds, `u32` id) to avoid platform-dependent `usize` encoding. both dense and compressed representations serialize deterministically and retain their form on round trips Reviewed By: dulinriley Differential Revision: D84197759
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
be4f6ca
to
930c6eb
Compare
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 10, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 10, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 10, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 10, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 10, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
shayne-fletcher
added a commit
to shayne-fletcher/monarch-1
that referenced
this pull request
Oct 10, 2025
Summary: add a set of `ValueMesh` constructors equivalent to the `RankedValues` initialization paths. `from_single` and `from_default` create compressed single-run meshes without allocating a dense vector, `from_ranges_with_default` builds a compact RLE mesh from sparse overrides on a default value, and `from_dense` constructs from a dense vector and compresses adjacent equal elements. includes tests for correctness, edge cases, and internal structure. completes the construction half of the `ValueMesh` parity plan before adding `ValueOverlay` and merge support. Differential Revision: D84259628
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Differential Revision: D84259628