sgl-project/sglang · error · AttributeError
Subclasses of BaseScheduler must define '{attr}' property
Error message
Subclasses of BaseScheduler must define '{attr}' property What it means
BaseScheduler.__init__ enforces that every subclass defines the properties timesteps, order, and num_train_timesteps (typically as @property). If a subclass sets none of them in __init__ and does not define the properties, the abstract-contract check raises AttributeError immediately at construction.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/schedulers/base.py:21
# SPDX-License-Identifier: Apache-2.0
from abc import ABC, abstractmethod
import torch
class BaseScheduler(ABC):
timesteps: torch.Tensor
order: int
num_train_timesteps: int
def __init__(self, *args, **kwargs) -> None:
# Check if subclass has defined all required properties
required_attributes = ["timesteps", "order", "num_train_timesteps"]
for attr in required_attributes:
if not hasattr(self, attr):
raise AttributeError(
f"Subclasses of BaseScheduler must define '{attr}' property"
)
@abstractmethod
def set_shift(self, shift: float) -> None:
pass
@abstractmethod
def set_timesteps(self, *args, **kwargs) -> None:
pass
@abstractmethod
def scale_model_input(
self, sample: torch.Tensor, timestep: int | None = None
) -> torch.Tensor:
pass
View on GitHub (pinned to 0132848349)
Solutions
- Define timesteps, order, and num_train_timesteps as attributes or @property on the subclass
- Call super().__init__() AFTER assigning the required attributes in the subclass __init__ (the check uses hasattr on self)
- Initialize them to None only if the property is defined — a plain missing attribute will fail; prefer explicit property definitions
- Add a quick construction smoke test for each new scheduler
Example fix
// before
class MySched(BaseScheduler):
def __init__(self):
super().__init__() # fails: attrs not set yet
self.num_train_timesteps = 1000
// after
class MySched(BaseScheduler):
num_train_timesteps: int = 1000
order = 1
def __init__(self):
self.timesteps = None
super().__init__() Defensive patterns
Strategy: type-guard
Validate before calling
required = {'timesteps', 'order', 'num_train_timesteps'}
assert all(hasattr(sched, a) for a in required), f'scheduler missing: {required - set(dir(sched))}' Type guard
def satisfies_base_scheduler(s: type) -> bool:
return all(any(a in vars(c) for c in s.__mro__) for a in ('timesteps', 'order', 'num_train_timesteps')) Try / catch
try:
sched = MyScheduler(...)
except AttributeError as e:
raise TypeError(f'{type(sched).__name__} incomplete BaseScheduler impl') from e Prevention
- Set required attributes before calling super().__init__() in subclass __init__
- Define the three as @property so the contract is always satisfiable
- Add a construction smoke test per scheduler subclass
When it happens
Trigger: Subclassing BaseScheduler (e.g. a custom flow-match scheduler) and overriding __init__ without calling super().__init__() AFTER setting self.timesteps/etc., or simply not defining the three properties/attributes at all.
Common situations: Writing a custom scheduler for a new diffusion model; refactoring an existing scheduler so timesteps becomes a lazily-computed property and the attribute is removed; forgetting super().__init__() ordering (check runs before attributes exist if super is called first).
Related errors
- {output_batch.error}
- action policy returned no output
- Expected {request_count} outputs, got {output_count} from sc
- denoising_strength must be positive
- Must pass a value for `mu` when `use_dynamic_shifting` is Tr
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/46c8ace7024771db.
Report an issue: GitHub.