--- library_name: diffusers language: - en license: mit pipeline_tag: text-to-image tags: - smd - lens - diffusion-distillation - lora - text-to-image - few-step - image-generation - 4-step --- # Lens and SMD-Lens Generate with **original Lens** or either **four-step SMD-Lens student** from one self-contained model repository. The Lens base, text encoder, tokenizer, VAE, adapters and inference code are included. The SMD training repository is not required for inference. [Training code](https://github.com/zjwfufu/SMD) · [SMD collection](https://huggingface.co/collections/zjwfufu/smd-6ac5f4b53c26548a75672189) ## Choose a model | `--variant` | Model | Denoising steps | Guidance | Weights | |---|---|---:|---:|---| | `base` | Original Lens | 20 | CFG 5.0 | Root pipeline (~30.56 GB including encoder and VAE) | | `teacher-lens` | Lens student distilled from Lens | 4 | 1.0 | Shared base + ~1.82 GB adapter | | `teacher-flux2-9b` | Lens student distilled from FLUX.2 Klein 9B | 4 | 1.0 | Shared base + ~1.82 GB adapter | The student variants use the same Lens architecture and base. The teacher name identifies the distillation teacher; it is not an additional model to download. ## Quickstart Use Linux, Python 3.12 and an NVIDIA GPU with CUDA support. These runners were exercised on an A100 80 GB using model CPU offload. The GPT-OSS encoder is stored in MXFP4 and dequantized to BF16 at load time; allow sufficient host RAM for the expanded encoder and model components. ```bash python3.12 -m venv .venv source .venv/bin/activate python -m pip install huggingface-hub hf auth login hf download zjwfufu/SMD-Lens --local-dir SMD-Lens --exclude "base/*" "*/lora/lora.safetensors" cd SMD-Lens python -m pip install -r requirements.txt # Original Lens python infer.py --variant base --output outputs/base # Four-step Lens student python infer.py --variant teacher-lens --output outputs/teacher-lens # Four-step student distilled from FLUX.2 Klein 9B python infer.py --variant teacher-flux2-9b --output outputs/teacher-flux2-9b ``` The command excludes legacy duplicate weights. To download only the original Lens base, add `"teacher-lens/*" "teacher-lens.safetensors" "teacher-flux2-9b/*" "teacher-flux2-9b.safetensors"` to the existing `--exclude` list; keep the root `model_index.json`, `scheduler/`, `text_encoder/`, `tokenizer/`, `transformer/` and `vae/`. For a single student, exclude only the other student’s directory and root safetensors file. Use `--prompt "your description"` and `--seed 42` to generate another image. Each run writes `sample.png` and `generation.json`, which records the prompt, seed, dimensions, model variant and output SHA-256. The default example is 1024 × 1024. ## Reproducible example **Prompt:** A kraft paper parcel on a wooden table, partly open with a blue ceramic vase inside. A white shipping label on the box reads "SMD". Warm window light, natural product photography. **Seed:** 42. **Resolution:** 1024 × 1024. The following images were generated by the included standalone runner using the same prompt, seed and resolution. Original Lens uses 20 steps; both SMD students use 4 steps. | Original Lens · 20 steps | SMD · Lens teacher · 4 steps | SMD · FLUX.2 teacher · 4 steps | |---|---|---| | ![Original Lens](base/examples/sample.png) | ![SMD Lens teacher](teacher-lens/examples/sample.png) | ![SMD FLUX.2 teacher](teacher-flux2-9b/examples/sample.png) | Case metadata and generation receipts are stored alongside each image: [Original Lens](base/examples/generation.json), [Lens teacher](teacher-lens/examples/generation.json), [FLUX.2 teacher](teacher-flux2-9b/examples/generation.json). Small numerical differences are possible across GPU architectures and dependency versions. ## Loading and sampling details `lens/` provides `LensPipeline`, `LensGptOssEncoder` and `LensTransformer2DModel`. `infer.py` reads the root `model_index.json` and loads the complete pipeline from the repository root; it does not require a custom remote-code import or the SMD training package. The original `base/` pipeline and nested adapter weights remain available for existing integrations. The runner falls back to `base/` when the root pipeline index is absent; `--base` still accepts an explicit legacy or custom pipeline path. The student loader prefers `.safetensors` at the root and falls back to `/lora/lora.safetensors`. Root and legacy weights are byte-identical. Each adapter contains LoRA matrices and two saved replacement tensors. The supplied loader validates and applies both, using the precision recorded in `/lora/adapter_config.json`. A generic LoRA loader that omits the replacement tensors will not reproduce the released student. Student sampling uses four Euler segments. The final raw segment has relative size 0.5, followed by Lens's empirical time shift with the 50-step reference setting. External classifier-free guidance is disabled. `/sampling.json` and the supplied scheduler retain these settings; changing only `num_inference_steps` in a base pipeline is insufficient. ## License Lens code and model weights are provided under the MIT license; see [LICENSE](LICENSE). Original copyright notices are retained. Bundled components retain their respective upstream terms. The SMD inference helper's Apache-2.0 notice is retained in its source.