[fix] Fix BatchMeta.union semantics#95
Conversation
Signed-off-by: 0oshowero0 <[email protected]>
CLA Signature Pass0oshowero0, thanks for your pull request. All authors of the commits have signed the CLA. 👍 |
There was a problem hiding this comment.
Pull request overview
This PR changes BatchMeta.union from “deduplicate by global_index” semantics to “merge field schemas for the same samples”, requiring identical global_indexes and partition_ids and combining metadata/flags accordingly. It updates the tutorial to reflect the new meaning of union vs concat and adds tests covering the revised behavior.
Changes:
- Redefined
BatchMeta.unionto require matching indices/partitions and to mergefield_schema,production_status,extra_info, and per-sample metadata. - Updated the metadata tutorial example and explanation to match the new “append columns/fields” union semantics.
- Added unit tests validating success cases, overlap behavior, conservative readiness merging, and mismatch errors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tutorial/03_metadata_concepts.py | Updates tutorial example/output to demonstrate field-merge union semantics. |
| transfer_queue/metadata.py | Reimplements BatchMeta.union to merge fields for identical samples and adds validation. |
| tests/test_metadata.py | Adds tests for the new union behavior and validation errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if self.global_indexes != other.global_indexes: | ||
| raise ValueError( | ||
| f"BatchMeta.union: global_indexes do not match. " | ||
| f"self.global_indexes={self.global_indexes}, " | ||
| f"other.global_indexes={other.global_indexes}" | ||
| ) | ||
|
|
||
| if not unique_indices_in_other: | ||
| return self | ||
| if self.partition_ids != other.partition_ids: | ||
| raise ValueError( | ||
| f"BatchMeta.union: partition_ids do not match. " | ||
| f"self.partition_ids={self.partition_ids}, " | ||
| f"other.partition_ids={other.partition_ids}" | ||
| ) |
Signed-off-by: 0oshowero0 <[email protected]>
CLA Signature Pass0oshowero0, thanks for your pull request. All authors of the commits have signed the CLA. 👍 |
BatchMeta.union functionalityBatchMeta.union semantics
Problem
PR https://gitcode.com/Ascend/TransferQueue/pull/28 incorrectly rewrote
BatchMeta.unionto behave likeconcatwith global_index deduplication.global_indexes(row-aligned, column-expanded).otherwhoseglobal_indexesare not present inself.This broke the design boundary between
union(same rows, merge columns) andconcat(same columns, append rows).Changes
1. Restore
BatchMeta.union(transfer_queue/metadata.py)size,global_indexes, andpartition_ids.field_schemawithotheroverridingselfon name conflicts.production_statusconservatively vianp.bitwise_and(both sides must report ready).extra_info,custom_meta, and_custom_backend_metaper sample.2. Update tutorial (
tutorial/03_metadata_concepts.py)attention_maskpresent in both batches) to demonstrate the override behavior.concat(append rows) vsunion(merge columns).3. Update unit tests (
tests/test_metadata.py)