Skip to content

[Refactor] Move custom_meta to SampleMeta and custom_backend_meta to FieldMeta#30

Closed
Evelynn-V wants to merge 4 commits into
Ascend:mainfrom
Evelynn-V:custom_meta
Closed

[Refactor] Move custom_meta to SampleMeta and custom_backend_meta to FieldMeta#30
Evelynn-V wants to merge 4 commits into
Ascend:mainfrom
Evelynn-V:custom_meta

Conversation

@Evelynn-V

@Evelynn-V Evelynn-V commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Background

This PR refactors the metadata storage architecture to embed metadata directly where it logically belongs:
custom_meta (user-defined sample annotations) → moved from BatchMeta to SampleMeta
backend_meta (storage-specific field metadata) → moved from BatchMeta to FieldMeta

Changes

  1. Modified transfer_queue/metadata.py, moved custom_meta from BatchMeta to SampleMeta, and moved custom_backend_meta from BatchMeta to FieldMeta.
  2. Modified tests/test_metadata.py, adapted to the new metadata structure and passed the tests.
  3. Modified transfer_queue/storage/managers/base.py and transfer_queue/controller.py to prevent access to custom_meta and custom_backend_meta, which no longer exist in BatchMeta

Signed-off-by: Evelynn-V <liwenlin0223l@gmail.com>
Signed-off-by: Evelynn-V <liwenlin0223l@gmail.com>
Signed-off-by: Evelynn-V <liwenlin0223l@gmail.com>
Signed-off-by: Evelynn-V <liwenlin0223l@gmail.com>
Comment on lines +205 to +216

for global_idx, field_metas in custom_backend_meta.items():
template = SampleMeta(
partition_id="",
global_index=global_idx,
fields={
fname: FieldMeta(name=fname, dtype=None, shape=None, _custom_backend_meta=meta)
for fname, meta in field_metas.items()
},
custom_meta={},
)
next((s for s in metadata.samples if s.global_index == global_idx), None).union(template, validate=False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code appears multiple times; can it be refactored into a function?

Comment on lines +317 to +319
if sample.global_index == global_index:
sample.custom_meta = copy.deepcopy(meta_dict)
break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we prove the [sample.global_index for sample in self.samples] is Monotonically increasing? If we can, methods like binary search would be much faster.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is $O(N)$. If smaples is sorted by global_index, we can use binary search to optimize to $O(logN)$

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +354 to +358
for global_index, meta_dict in new_meta.items():
for sample in self.samples:
if sample.global_index == global_index:
sample.custom_meta.update(copy.deepcopy(meta_dict))
break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above. btw, we can even replace these codes with a 'method'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is $O(n^2)$, please use two points to merge or hash/binary search to find.

@0oshowero0 0oshowero0 closed this Mar 23, 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.

3 participants