Conversation
Outputs.share() decided how much shared memory the shape/dim/data wires need before deciding what dtype it would store there, and the two did not agree: - shape and dim wires were built from platform-default ints (int32 on Windows) but read back as np.int64, so every share() call failed on Windows with 'buffer is too small'. - the data wire was allocated from the un-promoted nbytes, but the buffer is later viewed with the check_type()-promoted dtype, so any payload whose promoted itemsize exceeds both the input nbytes and the 256-byte floor failed on every platform (e.g. float32/model outputs, lists of strings). - scalar payloads (np.array(5), 'hello') produced a 0-sized shape wire, which SharedMemory rejects, and a 0-d write via [:] which numpy rejects. Compute the wire sizes from the promoted dtype with an int64-explicit shape/dim, floor the shape wire at one int64 so scalars are creatable, and write via ... indexing so 0-d (scalar) and N-d payloads both marshal correctly.
Author
|
@jmplaza could you take a look when you get a chance? This sizes the shared-memory output wires using the promoted dtype so promoted types (e.g. float32->float64) don't overflow their buffers. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #483 and #484.
Outputs.share()decided how much shared memory the shape/dim/data wiresneed before deciding what dtype it would store there, and the two did
not agree:
shapeanddimare built fromplatform-default integers (
np.array(data.shape)→ int32 onWindows), but the buffers are always read back as
np.int64inoutputs.pyandinputs.py. The wire gets 4 bytes and numpy is askedfor an 8-byte view, so every
share()call fails withTypeError: buffer is too small for requested array.un-promoted
data.nbytes, but the buffer is then viewed with thecheck_type()-promoted dtype (int32→int64, float32→float64,U/S→U64). Whenever promotion increases the itemsize past both theinput
nbytesand the 256-byte floor, the view is larger than thebuffer (e.g. a float32 array straight out of a model, or a list of
class labels), and numpy refuses it.
share("Out", 5),share("Out", "hello")) produced a0-sized shape wire, which
SharedMemoryrejects, and then a 0-dwrite through
[:], which numpy rejects.Changes
shape/dimexplicitly asnp.int64, fixing the Windowsint32/int64 mismatch (Outputs.share() fails on Windows: shape/dim wires are sized as int32 but always read as int64 #483).
(
data.size * np.dtype(final_type).itemsize) with the existing256-byte floor, so the later
create_ndbuffer(...)view always fits(Outputs.share() under-allocates the data wire whenever check_type() promotes the dtype #484).
int64so 0-d (scalar) payloads arecreatable, and marshal via
...indexing so 0-d and N-d payloads bothwrite correctly.
Verification
Tested with a real two-process round-trip (writer block process →
reader block process, the architecture the runtime uses) covering
float32,float16,int32,uint8,float64, 2-D arrays, lists ofstrings (
<U64promotion), and both scalar int/string payloads. Allshare/read round-trips now pass on Linux; the shape/dim fixes are the
exact dtypes the reader already expects, which is what makes Windows
work. Previously #484 fails deterministically on Linux for any payload
larger than 256 bytes whose dtype gets promoted.
Note: this branch intentionally leaves formatting untouched so the PR
stays a focused logic fix; the formatting-only PR (#444) on top of
master may need a one-line rebase once this merges.