File size: 1,389 Bytes
f7a97bc
 
 
 
 
a587dc4
 
f7a97bc
bf471c5
f7a97bc
bf471c5
 
 
 
f7a97bc
bf471c5
f7a97bc
 
bf471c5
 
 
f7a97bc
bf471c5
f7a97bc
 
 
bf471c5
 
f7a97bc
bf471c5
 
 
 
f7a97bc
 
 
 
399abd7
 
f7a97bc
 
bf471c5
f7a97bc
 
 
 
 
 
 
 
 
 
 
 
bf471c5
 
 
f7a97bc
 
bf471c5
f7a97bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
tags:
- jax
- flax
- flax-nnx
- diffusion
library_name: diffuse
---
---

## Mnist Generation
Flow matching diffusion model trained for mnist generation.
Use with [**diffuse**](https://github.com/jcopo/diffuse), a JAX/Flax sampling library.
Light enough to run on CPU

---

## Model Details
* **Framework:** JAX/Flax (NNX)
* **Format:** msgpack
* **Prediction Type:** Velocity (Flow Matching)

---

## Usage

### Download and Load Model

```python
import os

import jax
import jax.numpy as jnp
from flax import nnx, serialization
from huggingface_hub import hf_hub_download

# Download model weights and config
model_path = hf_hub_download(repo_id="jcopo/mnist", filename="model.msgpack")
config_path = hf_hub_download(repo_id="jcopo/mnist", filename="config.py")

# Load config to get model architecture
import importlib.util
spec = importlib.util.spec_from_file_location("model_config", config_path)
config_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(config_module)

# Initialize model from config
model = config_module.model

# Load weights
with open(model_path, "rb") as f:
    state_dict = serialization.from_bytes(None, f.read())

# Restore weights into model
graphdef, state = nnx.split(model)
state.replace_by_pure_dict(state_dict)
model = nnx.merge(graphdef, state)
model.eval()  # Set to evaluation mode

print("✅ Model loaded successfully!")
```