Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

[Tutorial] Provide tutorials for TransferQueue usage#141

Merged
0oshowero0 merged 9 commits into
devfrom
han/tutorial
Dec 20, 2025
Merged

[Tutorial] Provide tutorials for TransferQueue usage#141
0oshowero0 merged 9 commits into
devfrom
han/tutorial

Conversation

@0oshowero0

@0oshowero0 0oshowero0 commented Dec 18, 2025

Copy link
Copy Markdown
Member

This pull request introduces comprehensive tutorial scripts for TransferQueue, significantly enhancing the documentation and onboarding experience for new users. It adds detailed, runnable Python scripts that demonstrate the core components, controller behavior, and key features of TransferQueue. Additionally, a new update is added to the README.md to announce the release of the official tutorial.

Summary by CodeRabbit

  • Documentation
    • Added four new comprehensive tutorials covering TransferQueue fundamentals: core components and architecture, metadata system and operations, controller features including partition isolation and dynamic expansion, and custom sampling strategy implementation
    • Updated README with Dec 20, 2025 tutorial release announcement

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: 0oshowero0 <[email protected]>
Signed-off-by: 0oshowero0 <[email protected]>
Copilot AI review requested due to automatic review settings December 18, 2025 03:08
@coderabbitai

coderabbitai Bot commented Dec 18, 2025

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

A comprehensive tutorial suite is added to TransferQueue, consisting of four new Python modules demonstrating core components, metadata concepts, controller functionality, and custom sampling strategies. The README is updated to note the official tutorial release on December 20, 2025. Each tutorial includes setup helpers, demonstration functions, and end-to-end workflow examples with Ray, TensorDict, and OmegaConf.

Changes

Cohort / File(s) Summary
Documentation Update
README.md
Added update bullet noting official tutorial release on Dec 20, 2025
Tutorial: Core Components
tutorial/01_core_components.py
New tutorial demonstrating TransferQueue core components (Controller, StorageBackend, Client) with data workflow patterns (put → get metadata → get data → verify → clear) and Ray/Torch integration
Tutorial: Metadata Concepts
tutorial/02_metadata_concepts.py
New tutorial introducing FieldMeta, SampleMeta, and BatchMeta data structures with demonstration functions covering creation, readiness checks, field selection, union, concatenation, and reordering operations
Tutorial: Controller Understanding
tutorial/03_understanding_controller.py
New tutorial demonstrating TransferQueue controller features including partition isolation, dynamic row/column expansion, and sequential sampling with independent task tracking
Tutorial: Custom Samplers
tutorial/04_custom_sampler.py
New tutorial introducing RandomSamplerWithReplacement, RandomSamplerWithoutReplacement, and PrioritySampler implementations with demonstration workflows showing integration with TransferQueue

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Sampler implementations (04_custom_sampler.py): Verify sampling logic, probability normalization, and edge case handling (None/overly-long priority arrays)
  • Metadata operations (02_metadata_concepts.py): Confirm FieldMeta, SampleMeta, and BatchMeta interactions and operation semantics
  • Controller setup patterns (03_understanding_controller.py): Validate partition isolation and dynamic expansion workflows
  • Ray lifecycle management: Ensure consistent initialization and cleanup (ray.shutdown, client.close) across all tutorials

Poem

🐰 Four tales of queues now come to light,
With samplers, metadata, controllers—all just right!
From core components to custom delight,
The tutorials hop on, making TransferQueue bright! ✨


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

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.

Pull request overview

This PR adds two comprehensive tutorials for the TransferQueue library, demonstrating core components and metadata system usage. The tutorials provide hands-on examples with detailed explanations to help users understand how to use TransferQueue for distributed data transfer workflows.

Key Changes:

  • New tutorial introducing TransferQueue's three core components (Controller, Storage Backend, Client)
  • New tutorial demonstrating the metadata system (FieldMeta, SampleMeta, BatchMeta)
  • Both tutorials include practical examples with actual TransferQueue API usage

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
tutorial/01_core_components.py Introduces TransferQueue architecture and demonstrates basic put/get/clear workflow with SimpleStorageUnit backend
tutorial/02_metadata_concepts.py Demonstrates metadata classes (FieldMeta, SampleMeta, BatchMeta) with operations like chunk, concat, union, and select

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tutorial/02_metadata_concepts.py Outdated
Comment thread tutorial/01_core_components.py Outdated
parent_dir = Path(__file__).resolve().parent.parent
sys.path.append(str(parent_dir))

from transfer_queue import ( # noqa: E402 # noqa: E402

Copilot AI Dec 18, 2025

Copy link

Choose a reason for hiding this comment

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

Duplicate noqa comment. The second "noqa: E402" comment is redundant.

Suggested change
from transfer_queue import ( # noqa: E402 # noqa: E402
from transfer_queue import ( # noqa: E402

Copilot uses AI. Check for mistakes.
Comment thread tutorial/01_core_components.py Outdated
Comment thread tutorial/02_metadata_concepts.py Outdated
Comment on lines +298 to +385
ray.init()

# Setup TransferQueue
config = OmegaConf.create(
{
"global_batch_size": 8,
"num_data_storage_units": 2,
}
)

storage_units = {}
for i in range(2):
storage_units[i] = SimpleStorageUnit.remote(storage_unit_size=100)

controller = TransferQueueController.remote()
controller_info = process_zmq_server_info(controller)
storage_unit_infos = process_zmq_server_info(storage_units)

client = TransferQueueClient(
client_id="TutorialClient",
controller_info=controller_info,
)

tq_config = OmegaConf.create({}, flags={"allow_objects": True})
tq_config.controller_info = controller_info
tq_config.storage_unit_infos = storage_unit_infos
config = OmegaConf.merge(tq_config, config)

client.initialize_storage_manager(manager_type="AsyncSimpleStorageManager", config=config)

print("[Step 1] Putting data into TransferQueue...")
input_ids = torch.randint(0, 1000, (8, 512))
attention_mask = torch.ones(8, 512)

data_batch = TensorDict(
{
"input_ids": input_ids,
"attention_mask": attention_mask,
},
batch_size=8,
)

partition_id = "demo_partition"
batch_meta = client.put(data=data_batch, partition_id=partition_id)
print(f"✓ Put {data_batch.batch_size[0]} samples into partition '{partition_id}', got BatchMeta back {batch_meta}.")

print("[Step 2] Try to get metadata from TransferQueue from other places...")
batch_meta = client.get_meta(
data_fields=["input_ids", "attention_mask"],
batch_size=8,
partition_id=partition_id,
task_name="demo_task", # TransferQueueController prevents same task_name from getting data repeatedly
)
print("✓ Got BatchMeta from TransferQueue:")
print(f" Number of samples: {len(batch_meta)}")
print(f" Global indexes: {batch_meta.global_indexes}")
print(f" Field names: {batch_meta.field_names}")
print(f" Partition ID: {batch_meta.samples[0].partition_id}")
print(f" Sample structure: {batch_meta.samples[0]}")

print("[Step 3] Retrieve samples with specific fields..")
selected_meta = batch_meta.select_fields(["input_ids"])
print("✓ Selected 'input_ids' field only:")
print(f" New field names: {selected_meta.field_names}")
print(f" Samples still have same global indexes: {selected_meta.global_indexes}")
retrieved_data = client.get_data(batch_meta)
print(f" Retrieved data keys: {list(retrieved_data.keys())}")

print("[Step 4] Select specific samples from the retrieved BatchMeta...")
partial_meta = batch_meta.select_samples([0, 2, 4, 6])
print("✓ Selected samples at indices [0, 2, 4, 6]:")
print(f" New global indexes: {partial_meta.global_indexes}")
print(f" Number of samples: {len(partial_meta)}")
retrieved_data = client.get_data(partial_meta)
print(f" Retrieved data samples: {retrieved_data}, all the data samples: {data_batch}")

print("[Step 5] Demonstrate chunk operation...")
chunks = batch_meta.chunk(2)
print(f"✓ Chunked into {len(chunks)} parts:")
for i, chunk in enumerate(chunks):
print(f" Chunk {i}: {len(chunk)} samples, indexes={chunk.global_indexes}")
chunk_data = client.get_data(chunk)
print(f" Chunk {i}: Retrieved chunk data: {chunk_data}")

# Cleanup
client.clear(partition_id=partition_id)
client.close()
ray.shutdown()

Copilot AI Dec 18, 2025

Copy link

Choose a reason for hiding this comment

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

Potential resource leak if an exception occurs between ray.init() and ray.shutdown(). The function should use try-finally or a context manager to ensure Ray is properly shutdown even if an exception occurs. Consider wrapping the main logic in a try-finally block with ray.shutdown() in the finally clause.

Copilot uses AI. Check for mistakes.
Signed-off-by: 0oshowero0 <[email protected]>
Signed-off-by: 0oshowero0 <[email protected]>
@0oshowero0 0oshowero0 marked this pull request as ready for review December 20, 2025 01:57
@0oshowero0 0oshowero0 requested a review from Copilot December 20, 2025 01:57
Signed-off-by: 0oshowero0 <[email protected]>
@0oshowero0

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 20, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 14 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tutorial/04_custom_sampler.py Outdated
Comment thread tutorial/04_custom_sampler.py Outdated
Comment thread tutorial/04_custom_sampler.py Outdated
Comment thread tutorial/04_custom_sampler.py
Comment thread tutorial/03_understanding_controller.py Outdated
Comment thread tutorial/04_custom_sampler.py Outdated
Comment thread tutorial/04_custom_sampler.py
Comment thread tutorial/03_understanding_controller.py Outdated
Comment thread tutorial/01_core_components.py Outdated
Comment thread tutorial/04_custom_sampler.py
Signed-off-by: 0oshowero0 <[email protected]>
Signed-off-by: 0oshowero0 <[email protected]>

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 11 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tutorial/04_custom_sampler.py
Comment thread README.md Outdated
Comment thread tutorial/04_custom_sampler.py Outdated
Comment thread tutorial/04_custom_sampler.py
Comment thread tutorial/03_understanding_controller.py Outdated
Comment thread .github/workflows/tutorial.yml Outdated
Comment thread tutorial/04_custom_sampler.py Outdated
Comment thread tutorial/01_core_components.py Outdated
Comment thread .github/workflows/tutorial.yml Outdated
Comment thread tutorial/03_understanding_controller.py
Signed-off-by: 0oshowero0 <[email protected]>
Signed-off-by: 0oshowero0 <[email protected]>
@0oshowero0 0oshowero0 merged commit d406229 into dev Dec 20, 2025
3 checks passed
@0oshowero0 0oshowero0 deleted the han/tutorial branch December 20, 2025 03:04
@0oshowero0 0oshowero0 mentioned this pull request Dec 21, 2025
22 tasks
0oshowero0 added a commit that referenced this pull request Dec 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants