Repository navigation
Conversation
The sharding codec refused any prototype other than the one `zarr.config` names, and built shard blobs, the shard index, and empty shard readers from `zarr.config`. The v2 codec built decoded chunks from `zarr.config` too. A read or write that passed a prototype different from the configured one therefore failed (sharded arrays) or decoded through the configured kind (v2 arrays). Codecs now use the prototype in the chunk spec. The shard index stays in host memory whatever the data prototype, because it is consumed as a NumPy array; it is converted to the shard's buffer kind when the shard is assembled. Buffers an inner codec returns in another kind are converted at the shard boundary, so codecs that ignore the prototype keep working. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the pipelines A codec that ignores `chunk_spec.prototype` (for instance one that builds its buffers from `zarr.config`, as codecs from other packages may) could hand a buffer of another kind (host or device memory) to the next codec, the store, or the output array. Converting only at the shard boundary missed inner decode stages, the shard index codecs, and unsharded arrays. `ChunkTransform`, `AsyncChunkTransform` and `BatchedCodecPipeline` now pass every codec's input and output through `_as_prototype_buffer` / `_as_prototype_nd_buffer`, which convert only on a type mismatch, and `scatter_chunk` converts partial-decode output the same way. The sharding codec's own conversions, now redundant, are removed; it keeps the host-memory index spec and converts the encoded index to the shard's kind with `from_bytes`, which on a GPU avoids the slow-path copy `combine` would take. The tests now use a fake device buffer kind that, like CuPy, refuses to mix with host memory, add chains whose last codec ignores the prototype, a bytes-only shard index, a `zarr.config` naming a buffer kind that cannot be built, and direct tests of the chain runners and `scatter_chunk`. Each of 18 single-site reversions of the change fails at least one test. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round-2 review fixes: - `_as_prototype_buffer`/`_as_prototype_nd_buffer` convert only `Buffer` and `NDBuffer` instances; anything else a codec returns (a NumPy array, `bytes`) passes through unchanged, as before. Codecs from other packages that return raw arrays (e.g. icon-ch-vzarr's `EccodesCodec`) failed every read. - Conversion goes through `from_bytes(as_buffer_like())`, so a host-to-GPU conversion takes no slow-path warning and host kinds convert without a copy; the shard index uses the same helper. - Each codec gets its input as the kind its own spec names, and the chain's output is converted to the caller's spec, instead of converting every stage to the caller's prototype. - `test_sharding_use_of_gpu_prototype` no longer expects a slow-path warning: the shard index no longer round-trips through the GPU kind. - `fill_value_or_default` stays importable from `zarr.core.codec_pipeline`. - The extending guide states the prototype contract for codecs. The tests add codecs that return raw arrays and bytes, a codec that names another prototype for the rest of the chain, bytes-side prototype checks next to each prototype-ignoring codec, and restrict numcodecs (host-only) cases to host prototypes. All 48 single-site reversions of the change fail a test. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round-3 review fixes: - `_as_prototype_buffer`/`_as_prototype_nd_buffer` have `Buffer -> Buffer` / `None -> None` overloads instead of `T -> T`, so passing the wrong kind of value is a type error and the declared return type is the real one. - The `ChunkTransform` and `AsyncChunkTransform` docstrings and the extending guide describe per-stage conversion and when it copies. - The raw-value test codecs are sync-capable, so the sync chain runner is run with raw values too; the `V2Codec` unit test runs on every direction, with no numcodecs filters (numcodecs runs on host memory only). Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The raw-value test codecs became sync-capable in the previous commit, which moved the fused pipeline from the async chain runner to the sync one instead of adding it. Parametrize over sync-capable and async-only variants so both runners see raw values. Also rewrap the extending-guide paragraph. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…prototype tests On the big-endian s390x runner, `Delta(dtype="<i4")` declared a byte order different from the array's native int32, so the v3 numcodecs-chain cases read back byte-swapped values. The tests are about buffer kinds, not byte order; use the native `int32`. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
🤖 AI text below 🤖
Reading or writing a sharded array with a buffer prototype other than the one
zarr.confignames no longer fails, and a Zarr format 2 array decodes into the requested prototype's buffer kind. The codec pipelines now hand each codec its input in the buffer kind its chunk spec names and convert aBuffer/NDBufferof another kind that a codec returns, so codecs that build their buffers fromzarr.configkeep working.Related PRs: this unblocks #470, whose CPU-prototype default for
ZarrArrayIObroke every sharded read and write in GPU mode before this change. A third-party codec test suite is being built on top of this branch in a separate session (branchclaude/clever-blackwell-27699d); it will be opened as a draft stacked on this PR. This PR is based onmainand independent of #470.Summary of the change
ShardingCodecbuilds shard blobs and empty shard readers from the shard's prototype (notdefault_buffer_prototype()), drops theNon-default buffer prototypes are not supported within shardserror, and keeps the shard index in host memory (numpy_buffer_prototype()): the index is a few bytes per chunk and is consumed as a NumPy array. The encoded index is converted to the shard's kind when the shard is assembled.V2Codecdecodes intochunk_spec.prototype.nd_buffer, notget_ndbuffer_class().ChunkTransform,AsyncChunkTransformandBatchedCodecPipeline.decode_batch/encode_batchpass each codec's input through_as_prototype_buffer/_as_prototype_nd_buffer(new, inzarr.core.buffer.core) for the codec's own spec, and convert the chain's output to the caller's spec.scatter_chunkconverts partial-decode output the same way. The helpers convert onlyBuffer/NDBufferinstances of another kind (anisinstancecheck; nothing is copied when the kind already matches) and pass any other value through unchanged, so codecs that return raw NumPy arrays orbytesbehave as before.prototype.buffer.from_bytes(buffer.as_buffer_like()): no slow-path warning for host-to-GPU, and no copy between host kinds.Array/AsyncArraydefaults still followzarr.config.docs/user-guide/extending.mdstates the prototype contract for custom codecs.Tests
tests/test_codecs/test_buffer_prototype.pyuses a fake device buffer kind that, like CuPy, refuses to mix with host memory (host buffers refuse its arrays; its arrays refuse to be combined with host arrays; itscombine/from_bufferwarn on host input likegpu.Buffer). Tests:test_codecs_use_the_given_prototype: round trip (partial write into absent shards, full write, partial write, full and partial read) over both pipelines; layouts v3, v3 sharded, v3 sharded with a bytes-only index at the start, nested sharding, v2; chains of zarr codecs, zarr's numcodecs wrappers, an async-only codec, and prototype-ignoring codecs (each next to a checking codec); directions config=device/call=host, config=host/call=device, config=device/call=device. Checks the result's exact array type, the exact buffer type of every stored chunk, and that each test codec ran both ways. numcodecs cases run with a host prototype only (numcodecs is host-only on real CuPy).test_codecs_read_no_buffer_config:zarr.confignames a buffer kind that cannot be built; reads and writes with codecs that follow the prototype still work.test_codec_chains_convert_input_of_another_kind,test_codec_chains_give_each_codec_its_own_specs_kind: the three chain runners directly.test_scatter_chunk_converts_a_chunk_of_another_kind,test_v2_codec_decodes_into_the_given_prototype: the two places where an array read alone would hide a wrong kind.test_codecs_that_return_raw_arrays_and_bytes_keep_working: codecs returning NumPy arrays /bytes(a partial write through them fails onmaintoo, so it is not covered).The change removes an error path and adds none, so there are no error-case tests. Mutation check: each of 48 single-site reversions of the change (every conversion call, own-spec vs caller-spec, the pass-through,
from_bytesvsfrom_buffer, each config read in sharding and v2) fails at least one test. 63 of the first 105 matrix cases fail onmain.test_sharding_use_of_gpu_prototype(GPU CI only) no longer expects a slow-path warning; this could not be run locally (no GPU).Full suite: 13655 passed, 1318 skipped, 9 xfailed. mypy and ruff clean.
Adversarial review record
Fresh reviewer agents were given the diff and files, not the author's conclusions.
Round 1 (two reviewers, on 4ddd33a): no serious finding.
np.array(out_array)in coordinate/vindex reads drops the prototype (array layer, not codecs);cast_valueusesnp.asarrayonas_ndarray_like()(GPU-only, pre-existing).Round 2 (two reviewers, on a045f43): two serious findings, both confirmed and fixed in e4a63ff.
bytes(e.g. MeteoSwiss icon-ch-vzarr'sEccodesCodec) failed every read in the conversion helpers. Reproduced on both pipelines; fixed by passing non-buffer values through.test_sharding_use_of_gpu_prototypewould fail on GPU CI ("DID NOT WARN"): the warning came from crc32c running on the index under the GPU spec. Traced and reproduced with a warning-faithful CPU stand-in; fixed by dropping thepytest.warns.from_bytes(as_buffer_like())(no GPU slow-path warning);fill_value_or_defaultre-export kept; numcodecs/v2 device cases removed (the fake let host-only codecs pass); docs note added.BytesCodecskip the chain's input conversion (only reachable with a store that breaks its prototype contract); the autouse fixture leaves the fake kinds registered (harmless).Round 3 (one reviewer, fix diff e4a63ff only): no serious finding. Fixed in 5735fba:
T -> Thelper signatures hid type errors; nowBuffer -> Buffer/None -> Noneoverloads;ChunkTransform/AsyncChunkTransformdocstrings and the docs' "at the cost of a copy" wording;V2Codecunit test runs on every direction with no numcodecs.Not changed: (a)
ChunkTransform/AsyncChunkTransformhand bytes-to-bytes codecsab_specwhileBatchedCodecPipelinethreads each bytes codec'sresolve_metadata, so the runners disagree if a bytes codec changes the prototype; this divergence predates this PR (it applies to dtype and shape too) and no codec changes the prototype there. (b) Converting between two device buffer classes copies through the host; afrom_bufferbranch for device sources was tried and dropped because it only saves copies in that rare case and cannot be tested without a GPU. (c) A non-contiguousBufferfails to convert (BufferError); theBuffercontract requires contiguous data.Round 4 (one reviewer, fix diff 5735fba only): no serious finding. Fixed in the next commit: making the raw-value codecs sync-capable had dropped async-runner coverage, so the test now runs sync-capable and async-only variants. Nits not changed: the fake device kind checks the array type in
from_buffer/combine(equivalent in this suite, closer togpu.Buffer).Rounds 3 and 4 found nothing serious, so review stopped there.
🤖 Generated with Claude Code