""" Track B: submit `model.py` + `weights.safetensors`. Track A (ONNX) asks you to export a frozen graph. This track asks you for code, which is more flexible -- runtime branching, custom sampling, anything Python can express -- and is run inside a locked-down container on our side. Your `model.py` must define a class named exactly `Drawer` that subclasses `RoguesDrawer` and implements two methods: class Drawer(RoguesDrawer): def load(self, weights): ... # weights: dict[str, np.ndarray] def draw(self, prompt_embed, noise): ... # -> (512, 512) float32 The I/O contract is identical to track A, so a model can move between tracks without changing its interface: prompt_embed float32 (1, T, 3584) the frozen text embedding noise float32 (1, 16, 64, 64) your only source of randomness return float32 (512, 512) in [0,1], 0 = black ink Rules that are enforced, not suggested: * **All randomness comes from `noise`.** Your model is run twice on identical inputs and rejected if the images differ. Seed any generator you create from `noise` itself, and leave dropout off in eval. * **No network access.** The container runs with networking disabled. Fetching a checkpoint at runtime will not fail gracefully -- it will hang and then time out. Everything you need must be in your weights file. * **No writing outside the output directory.** The filesystem is read-only apart from a scratch space we pass you. * **One wall-clock budget per image.** Spending more compute is allowed right up until it costs you the limit. `load()` receives plain NumPy arrays rather than a file path on purpose: we read the safetensors ourselves, so your code never parses an untrusted file, and you never have to care where it was stored. """ from __future__ import annotations import abc from spec import EMBED_DIM, IMAGE_SIZE, NOISE_SHAPE class RoguesDrawer(abc.ABC): """Base class every track-B entry subclasses. Deliberately not an `nn.Module`: the interior is yours, and requiring a torch base class would quietly exclude a JAX or NumPy entry that is otherwise perfectly valid. """ #: shapes your methods will be handed, for reference EMBED_DIM = EMBED_DIM NOISE_SHAPE = NOISE_SHAPE IMAGE_SIZE = IMAGE_SIZE @abc.abstractmethod def load(self, weights: dict) -> None: """Take your trained tensors. Args: weights: every tensor from your safetensors file, as NumPy arrays keyed by the names you saved them under. Called exactly once, before any call to `draw`. Do setup here rather than in `draw` -- the time budget is per image, and construction work repeated per call will spend it for nothing. """ @abc.abstractmethod def draw(self, prompt_embed, noise): """Draw one picture. Args: prompt_embed: float32 (1, T, 3584). T varies with caption length. noise: float32 (1, 16, 64, 64). The only entropy you are given. Returns: float32 (512, 512) in [0, 1], where 0 is black ink and 1 is white paper. A (1, 512, 512) array is also accepted and squeezed. Must be deterministic given identical arguments. """