Text-to-Image
Diffusers
Safetensors
English
Flux2KleinPipeline
flux
flux2-klein
quantization
sdnq
4-bit precision
dynamic-quantization
low-vram
google-colab
t4
batch-image-edit
background-removal
Instructions to use codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
| import torch | |
| import torch.nn as nn | |
| from diffusers import ModelMixin, ConfigMixin | |
| class Flux2Transformer2DModel(ModelMixin, ConfigMixin): | |
| config_name = "config.json" | |
| def __init__(self, **kwargs): | |
| super().__init__() | |
| # Store config | |
| self.register_to_config(**kwargs) | |
| # Internal storage (safe for arbitrary keys) | |
| self._sd = {} | |
| # ----------------------------- | |
| # LOAD: accept ANY state dict | |
| # ----------------------------- | |
| def load_state_dict(self, state_dict, strict=False): | |
| """ | |
| Store raw tensors exactly as-is. | |
| No validation, no structure assumptions. | |
| """ | |
| self._sd = {} | |
| for k, v in state_dict.items(): | |
| if isinstance(v, torch.Tensor): | |
| self._sd[k] = v.contiguous() | |
| else: | |
| self._sd[k] = v | |
| # Pretend everything matched | |
| return torch.nn.modules.module._IncompatibleKeys([], []) | |
| # ----------------------------- | |
| # SAVE: return original weights | |
| # ----------------------------- | |
| def state_dict(self, *args, **kwargs): | |
| return dict(self._sd) | |
| # ----------------------------- | |
| # Required by diffusers internals | |
| # ----------------------------- | |
| def _convert_deprecated_attention_blocks(self, state_dict): | |
| # Diffusers sometimes calls this | |
| return state_dict | |
| # ----------------------------- | |
| # Forward (dummy) | |
| # ----------------------------- | |
| def forward(self, *args, **kwargs): | |
| raise RuntimeError( | |
| "Flux2Transformer2DModel is a stub loader. " | |
| "It cannot run inference." | |
| ) |