Buckets:
| import os | |
| import click | |
| import torch | |
| from safetensors.torch import load_file | |
| from autoencoder import QwenAutoencoder | |
| from encoder import Qwen3VLConditioner, TextEncoderConfig | |
| from mmdit import SingleMMDiTConfig, SingleStreamDiT | |
| from sampling import sample | |
| single_mmdit_large_wide = SingleMMDiTConfig( | |
| features=6144, | |
| tdim=256, | |
| txtdim=2560, | |
| heads=48, | |
| kvheads=12, | |
| multiplier=4, | |
| layers=28, | |
| patch=2, | |
| channels=16, | |
| txtheads=20, | |
| txtkvheads=20, | |
| txtlayers=12, | |
| ) | |
| qwen3_vl_4b = TextEncoderConfig(model_id="Qwen/Qwen3-VL-4B-Instruct") | |
| checkpoints = { | |
| "oss_raw": os.environ.get("OSS_RAW"), | |
| "oss_turbo": os.environ.get("OSS_TURBO"), | |
| } | |
| def _pipeline( | |
| mmdit_config=single_mmdit_large_wide, | |
| text_encoder_config=qwen3_vl_4b, | |
| checkpoint="oss_raw", | |
| device="cuda", | |
| dtype=torch.bfloat16, | |
| ): | |
| """Build the autoencoder, text encoder, and MMDiT, load weights, and move to GPU.""" | |
| ae = QwenAutoencoder() | |
| encoder = Qwen3VLConditioner( | |
| text_encoder_config.model_id, | |
| text_encoder_config.max_length, | |
| select_layers=text_encoder_config.select_layers, | |
| ) | |
| # Build on meta, load to passed device | |
| with torch.device("meta"): | |
| mmdit = SingleStreamDiT(mmdit_config) | |
| ckpt = checkpoints[checkpoint] | |
| mmdit.load_state_dict(load_file(ckpt), strict=True, assign=True) | |
| mmdit = mmdit.to(device=device, dtype=dtype).eval().requires_grad_(False) | |
| ae = ae.to(device=device, dtype=dtype).eval().requires_grad_(False) | |
| encoder = encoder.to(device=device, dtype=dtype).eval().requires_grad_(False) | |
| return mmdit, ae, encoder | |
| def main( | |
| prompt, steps, cfg, y1, y2, width, height, num_images, seed, checkpoint, output, mu | |
| ): | |
| dit, ae, encoder = _pipeline(checkpoint=checkpoint) | |
| images = sample( | |
| dit, | |
| ae, | |
| encoder, | |
| [prompt] * num_images, | |
| width=width, | |
| height=height, | |
| steps=steps, | |
| guidance=cfg, | |
| seed=seed, | |
| y1=y1, | |
| y2=y2, | |
| mu=mu, | |
| ) | |
| for i, image in enumerate(images): | |
| out = f"{output}_{i}.png" | |
| image.save(out) | |
| click.echo(f"saved {out}") | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 3.45 kB
- Xet hash:
- 8dee9fe2a9396d709aa6141b916c2c2ad91e67f261fb9ec906f1b03c76e72b2d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.