nemo_automodel.components.datasets.diffusion.multi_tier_bucketing#
Module Contents#
Classes#
Calculate resolution buckets constrained by a maximum pixel budget. Supports various aspect ratios, each scaled to fit within the pixel budget. |
Data#
API#
- nemo_automodel.components.datasets.diffusion.multi_tier_bucketing.logger#
βgetLogger(β¦)β
- class nemo_automodel.components.datasets.diffusion.multi_tier_bucketing.MultiTierBucketCalculator(
- quantization: int = 64,
- max_pixels: Optional[int] = None,
- debug_mode: bool = False,
Calculate resolution buckets constrained by a maximum pixel budget. Supports various aspect ratios, each scaled to fit within the pixel budget.
Initialization
- Parameters:
quantization β Resolution must be multiple of this (64 for Flux)
max_pixels β Maximum pixel count for buckets (default: 256*256 = 65536)
- ASPECT_RATIOS#
[(1, 2), (9, 16), (2, 3), (3, 4), (4, 5), (1, 1), (5, 4), (4, 3), (3, 2), (16, 10), (5, 3), (16, 9),β¦
- RESOLUTION_PRESETS#
None
- _generate_all_buckets() List[Dict][source]#
Generate all unique resolution buckets within the pixel budget.
- _calculate_max_resolution(
- aspect_ratio: float,
Calculate the maximum resolution for an aspect ratio within the pixel budget.
For a given aspect ratio r = w/h, and pixel budget P: w * h <= P w = r * h r * h * h <= P h <= sqrt(P / r)
Then w = r * h
- get_bucket_for_image(
- image_width: int,
- image_height: int,
Get the best bucket for an image.
- Parameters:
image_width β Original image width
image_height β Original image height
max_pixels β Override max pixels for this query (deprecated, use constructor)
- Returns:
Bucket dictionary with resolution and metadata
- get_bucket_by_resolution(
- width: int,
- height: int,
Get bucket by exact resolution.
- resize_and_crop(
- image,
- target_width: int,
- target_height: int,
- crop_mode: str = 'center',
Resize and crop image to target resolution.
- Parameters:
image β PIL Image or numpy array
target_width β Target width
target_height β Target height
crop_mode β βcenterβ, βrandomβ, or βsmartβ
- Returns:
(resized_image, crop_offset_x, crop_offset_y)
- get_dynamic_batch_size(
- resolution: Tuple[int, int],
- base_batch_size: int = 32,
- base_resolution: Tuple[int, int] = (512, 512),
Calculate dynamic batch size based on resolution. Larger images get smaller batches to maintain GPU memory usage.
- Parameters:
resolution β (width, height)
base_batch_size β Batch size for base resolution
base_resolution β Reference resolution
- Returns:
Recommended batch size
- classmethod from_preset(
- preset: str,
- quantization: int = 64,
Create calculator from a named preset.
- Parameters:
preset β One of β256pβ, β512pβ, β768pβ, β1024pβ, β1536pβ
quantization β Resolution quantization
- Returns:
MultiTierBucketCalculator instance