mirror of
https://github.com/kohya-ss/sd-scripts.git
synced 2026-04-10 15:00:23 +00:00
16 lines
488 B
Python
16 lines
488 B
Python
def maybe_sample_params(optimizer):
|
|
"""
|
|
Returns parameter sampling context for IVON optimizers, otherwise returns no-op context.
|
|
|
|
pip install ivon-opt
|
|
|
|
Args:
|
|
optimizer: PyTorch optimizer instance.
|
|
|
|
Returns:
|
|
Context manager for parameter sampling if optimizer supports it, otherwise nullcontext().
|
|
"""
|
|
from contextlib import nullcontext
|
|
|
|
return optimizer.sampled_params(train=True) if hasattr(optimizer, "sampled_params") else nullcontext()
|