benc0 commited on
Commit
915bd94
Β·
verified Β·
1 Parent(s): 81bab4d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +45 -17
README.md CHANGED
@@ -1,8 +1,10 @@
1
  ---
2
  license: apache-2.0
3
  library_name: mlx
 
4
  tags:
5
  - mlx
 
6
  - mlx-swift
7
  - super-resolution
8
  - image-upscaling
@@ -12,30 +14,56 @@ tags:
12
  pipeline_tag: image-to-image
13
  ---
14
 
15
- # SeedVR2-7B-sharp (MLX-Swift) β€” int8
16
 
17
- **int8-quantized** MLX-Swift weights for **SeedVR2-7B** (ByteDance, ICLR 2026) β€” one-step
18
- diffusion **super-resolution**. ~Half the size of fp16, near-lossless. For the
19
- [`seedvr2-mlx-swift`](https://github.com/xocialize/seedvr2-mlx-swift) package.
20
- fp16 base: [`SeedVR2-7B-mlx`](https://huggingface.co/benc0/SeedVR2-7B-sharp-mlx).
21
 
22
- - **Quantization:** transformer DiT Linears int8, group size 64 (the small `vid_in.proj` and the VAE are kept fp16). Declared in `config.json` (`"quantization": {"bits": 8, "group_size": 64}`); the loader applies it automatically.
23
- - **Files:** `transformer.safetensors` (int8, ~8.5 GB vs 16.5 GB fp16) Β· `vae.safetensors` (fp16) Β· `pos_emb.safetensors` Β· `config.json`.
24
- - **Quality:** int8 `t_out` cosine vs fp16 = **0.9997755** (the sharp fine-tune has heavier-tailed weights than the standard checkpoint's 0.9999481, costing slightly more under group quantization); end-to-end image vs the fp16 pipeline = **54.9 dB PSNR** (visually lossless; device noise alone measures ~60 dB). Reload round-trip **bit-exact (cosine 1.0)**. (int4 degrades this model family badly β€” use int8 on-device.)
 
25
 
26
- ## Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  ```swift
29
- import SeedVR2MLX
30
  let upscaler = try SeedVR2Upscaler(directory: weightsDir) // detects int8 from config, applies quantize on load
31
- let out = upscaler.upscale(processedImage: img, seed: 42)
32
  ```
33
 
 
 
 
 
 
 
 
 
34
  ## Provenance & license
35
 
36
- **ByteDance Seed** (*SeedVR2*, ICLR 2026, [ByteDance-Seed/SeedVR](https://github.com/ByteDance-Seed/SeedVR), **Apache-2.0**)
37
- β†’ fp16 [`numz/SeedVR2_comfyUI`](https://huggingface.co/numz/SeedVR2_comfyUI) (verified bitwise against
38
- ByteDance's original fp32 `.pth`, 1128/1128 tensors)
39
- β†’ MLX ref [`filipstrand/mflux`](https://github.com/filipstrand/mflux) β†’ export + int8 conversion via
40
- [`xocialize/seedvr2-mlx`](https://github.com/xocialize/seedvr2-mlx) tooling. Format/precision-converted
41
- weights (not a new model); Apache-2.0 applies.
 
1
  ---
2
  license: apache-2.0
3
  library_name: mlx
4
+ base_model: ByteDance-Seed/SeedVR2-7B
5
  tags:
6
  - mlx
7
+ - mflux
8
  - mlx-swift
9
  - super-resolution
10
  - image-upscaling
 
14
  pipeline_tag: image-to-image
15
  ---
16
 
17
+ # SeedVR2-7B-sharp (MLX) β€” int8
18
 
19
+ Runtime-agnostic **int8-quantized** MLX-format weights for **SeedVR2-7B-sharp**, the **sharp** variant of ByteDance's one-step diffusion **super-resolution / restoration** model (ICLR 2026) β€” tuned for stronger detail sharpening, for on-device upscaling on Apple Silicon.
 
 
 
20
 
21
+ Not tied to any single package β€” these load into:
22
+ - [`mflux`](https://github.com/filipstrand/mflux) (Python MLX, actively maintained; also the parity reference these weights were validated against),
23
+ - [`seedvr2-mlx-swift`](https://github.com/xocialize/seedvr2-mlx-swift) (MLX-Swift; **archived/read-only since Jun 2026** but functional β€” MIT-licensed and forkable),
24
+ - or any MLX code that reconstructs the same module tree (see **Format notes** below).
25
 
26
+ fp16 base: [`SeedVR2-7B-sharp-mlx`](https://huggingface.co/benc0/SeedVR2-7B-sharp-mlx) Β· standard checkpoint: [`SeedVR2-7B-mlx`](https://huggingface.co/benc0/SeedVR2-7B-mlx) Β· 3B family: [`mlx-community/SeedVR2-3B-mlx`](https://huggingface.co/mlx-community/SeedVR2-3B-mlx)
27
+
28
+ - **Files:** `transformer.safetensors` (DiT, int8, ~8.8 GB vs 16.5 GB fp16) Β· `vae.safetensors` (3D-causal-conv VAE, fp16) Β· `pos_emb.safetensors` (precomputed text embedding) Β· `config.json`.
29
+ - **Architecture (vs 3B):** vid_dim 3072 (2560), 24 heads (20), 36 layers (32), all layers multimodal, plain MLP (SwiGLU), rope_dim 64.
30
+ - **Quality:** int8 `t_out` cosine vs fp16 = **0.9997755** (the sharp fine-tune has heavier-tailed weights than the standard checkpoint's 0.9999481, costing slightly more under group quantization); **end-to-end image vs the fp16 pipeline = 54.9 dB PSNR** (visually lossless β€” device noise alone measures ~60 dB). Reload round-trip **bit-exact**. (int4 degrades this model family badly β€” use int8 on-device.)
31
+
32
+ ## Usage β€” Python (MLX / mflux)
33
+
34
+ ```python
35
+ import json, mlx.core as mx, mlx.nn as nn
36
+ from mlx.utils import tree_unflatten
37
+ from mflux.models.seedvr2.model.seedvr2_transformer.transformer import SeedVR2Transformer
38
+ from mflux.models.seedvr2.weights.seedvr2_weight_definition import SeedVR2WeightDefinition
39
+
40
+ cfg = json.load(open("config.json"))
41
+ tx = SeedVR2Transformer(**cfg["transformer_overrides"])
42
+ q = cfg["quantization"] # {"bits": 8, "group_size": 64}
43
+ nn.quantize(tx, group_size=q["group_size"], bits=q["bits"],
44
+ class_predicate=SeedVR2WeightDefinition.quantization_predicate)
45
+ tx.update(tree_unflatten(list(mx.load("transformer.safetensors").items())))
46
+ mx.eval(tx.parameters())
47
+ ```
48
+
49
+ The full pipeline (VAE, scheduler, pre/post-processing) lives in mflux: `mflux-upscale-seedvr2 --model seedvr2-7b --image-path input.png --resolution 2x` (note: mflux's built-in downloader fetches the PyTorch source weights and converts on the fly; loading *these* pre-converted files uses the snippet above).
50
+
51
+ ## Usage β€” Swift
52
 
53
  ```swift
54
+ import SeedVR2MLX // github.com/xocialize/seedvr2-mlx-swift (archived/read-only, MIT β€” fork to maintain)
55
  let upscaler = try SeedVR2Upscaler(directory: weightsDir) // detects int8 from config, applies quantize on load
56
+ let out = upscaler.upscale(processedImage: img, seed: 42) // [-1,1], dims padded to /16
57
  ```
58
 
59
+ ## Format notes (for other MLX runtimes)
60
+
61
+ - **Key naming:** mflux module hierarchy, flattened with `mlx.utils.tree_flatten` (e.g. `blocks.17.attn.proj_qkv_vid.weight`). Deterministic mapping back to ByteDance's original PyTorch names: mflux `src/mflux/models/seedvr2/weights/seedvr2_weight_mapping.py`.
62
+ - **Layouts:** MLX conventions throughout β€” VAE conv weights are `(O, *K, I)`.
63
+ - **Config:** `config.json["transformer_overrides"]` carries the 7B dims (vid_dim 3072, heads 24, num_layers 36, mm_layers 36, rope_dim 64, …) and must be passed to the transformer constructor.
64
+ - **Conditioning:** `pos_emb.safetensors` (58Γ—5120, fp16) is the precomputed embedding of the fixed prompt β€” the text encoder is eliminated from this port, so it is a mandatory `txt` input.
65
+ - **Quantization format:** standard MLX affine group quantization (bits 8, group 64). Each quantized Linear stores packed `weight` (U32) + `scales`/`biases` (F16). Only Linears with in-dim divisible by 64 are quantized β€” `vid_in.proj` (in-dim 132) and the whole VAE stay fp16. Declared in `config.json` so loaders can rebuild the module structure before `update()`.
66
+
67
  ## Provenance & license
68
 
69
+ Chain: **ByteDance Seed** β€” *SeedVR2: One-Step Video Restoration via Diffusion Adversarial Post-Training* (ICLR 2026, [arXiv:2506.05301](https://arxiv.org/abs/2506.05301)), [ByteDance-Seed/SeedVR](https://github.com/ByteDance-Seed/SeedVR), **Apache-2.0** β†’ PyTorch fp16 redistribution [`numz/SeedVR2_comfyUI`](https://huggingface.co/numz/SeedVR2_comfyUI) (`seedvr2_ema_7b_sharp_fp16.safetensors`; independently verified **bitwise** against ByteDance's original fp32 `seedvr2_ema_7b_sharp.pth` β€” all 1128 tensors identical after fp32β†’fp16 cast) β†’ MLX reference impl [`filipstrand/mflux`](https://github.com/filipstrand/mflux) β†’ export + int8 conversion via [`xocialize/seedvr2-mlx`](https://github.com/xocialize/seedvr2-mlx) tooling. These are format/precision-converted weight artifacts (not a new model); Apache-2.0 applies. Credit ByteDance Seed (original), cite the paper.