Datasets¶
samudra.datasets
¶
InferenceDataset(source, prognostic_var_names, boundary_var_names, input_steps, output_steps, normalize_before_mask, masked_fill_value, long_rollout)
¶
Bases: Dataset
Dataset of overlapping windows used for autoregressive inference.
Each window contains input_steps historical states followed by
output_steps target states. Consecutive windows advance by
output_steps so that every model output becomes the newest part of the
next input history. For example::
input_steps=1, output_steps=1: [0 | 1], [1 | 2], [2 | 3]
input_steps=2, output_steps=2: [0, 1 | 2, 3], [2, 3 | 4, 5]
input_steps=2, output_steps=1: [0, 1 | 2], [1, 2 | 3], [2, 3 | 4]
The values before | are inputs and those after it are targets.
Source code in src/samudra/datasets.py
to(device)
¶
Move the dataset's context tensors to the specified device.
Call this before using the dataset for inference to ensure tensors are on the correct device (GPU).
Source code in src/samudra/datasets.py
HostBatch(dataset_id)
¶
Source code in src/samudra/datasets.py
append(input_, boundary, label)
¶
Add a prognostic input, boundary, and prognostic label as the last step.
ModelBatch(ctx)
¶
A single batch of training data.
A single batch contains multiple steps worth of RolloutStep entries, each
of which is a (prognostic_input, boundary_input, label) triple. The
prognostic and boundary tensors are carried separately because the
samudra-multi model encodes them separately (Samudra just concatenates them later).
Source code in src/samudra/datasets.py
append(prognostic_input, boundary_input, label)
¶
Add another RolloutStep as a new step.
TorchTrainDataset(input_source, label_source, prognostic_var_names, boundary_var_names, input_steps, output_steps, steps, normalize_before_mask, masked_fill_value, stride=1, concurrent_compute_=False)
¶
Bases: Dataset[HostBatch]
This class is used for training and validation.
It creates rolling indices to keep track of histories/past states. But different from InferenceDataset, as it creates rolling indices based on stride. By default, the sliding window / stride is 1.
We make use of ModelBatch class to store a single sample.
For example, Hist=0 ; step=0->[0, 1]; step=1->[1, 2]; step=2->[2, 3]; step=3->[3, 4] Hist=1 ; step=0->[[0, 1], [2, 3]]; step=1->[[2, 3], [4, 5]]; step=2->[[4, 5], [6, 7]]; step=3->[[6, 7], [8, 9]] Hist=2 ; step=0->[[0, 1, 2], [3, 4, 5]]; step=1->[[3, 4, 5], [6, 7, 8]]; step=2->[[6, 7, 8], [9, 10, 11]]; step=3->[[9, 10, 11], [12, 13, 14]]
Source code in src/samudra/datasets.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
to_model_batch(host_batch, device)
¶
Convert HostBatch to ModelBatch, moving tensors to the specified device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host_batch
|
HostBatch
|
CPU data from worker process |
required |
device
|
device
|
Target device (typically GPU) to move tensors to |
required |
Returns:
| Type | Description |
|---|---|
ModelBatch
|
ModelBatch with tensors on the target device |
Source code in src/samudra/datasets.py
BatchLoader(host_loader, datasets, device)
¶
Wrapper around a torch DataLoader that handles GPU post-processing.
This class wraps a DataLoader[HostBatch] and converts the raw data to ModelBatch by applying GPU-based normalization and masking. This allows the data loading process to handle I/O while the main process handles GPU operations.
Since the data samples flow from one process to the other, we want to tie
them back to the dataset they came from which knows how to do that second
half once they're in the main process which has GPU access set up. To do that,
each data sample (which could come from a different dataset) has a dataset ID
-- datasets maps from those IDs to the original datasets.
Source code in src/samudra/datasets.py
__iter__()
¶
Iterate over the dataloader, converting HostBatch to ModelBatch.
Source code in src/samudra/datasets.py
__getitem__(index)
¶
Access a single item by index, converting HostBatch to ModelBatch.
Note: This bypasses the DataLoader's sampling/batching and directly accesses the underlying dataset for test purposes.