Sidharthan commited on
Commit
6615bae
·
verified ·
1 Parent(s): 4edd1ca

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +33 -3
  2. config.json +21 -23
  3. configuration_qadit.py +3 -1
  4. modelling_qadit.py +13 -0
README.md CHANGED
@@ -41,18 +41,31 @@ out = model.generate(
41
  "Rain falls heavily on a metal roof with distant thunder",
42
  num_inference_steps=50,
43
  guidance_scale=4.0,
44
- generator=torch.Generator(device=model.device).manual_seed(0),
45
  )
46
 
47
  sf.write("rain.wav", out.audios[0], out.sampling_rate)
48
  ```
49
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  ### Useful `generate` knobs
51
 
52
  | Argument | Default | Meaning |
53
  |---|---|---|
54
  | `num_inference_steps` | 50 | DDIM steps |
55
  | `guidance_scale` | 4.0 | CFG scale (try 5–7 for crisper AudioCaps-style prompts) |
 
56
  | `output_type` | `"np"` | `"np"` / `"pt"` / `"latent"` |
57
  | `generator` | `None` | `torch.Generator` for reproducibility |
58
 
@@ -63,15 +76,32 @@ Prompts work best in AudioCaps style: short concrete sound events.
63
  From the research repo:
64
 
65
  ```bash
 
66
  python qadit_hf/convert_checkpoint.py \
67
  --ckpt path/to/ckpt_0023999.pt \
68
- --cache path/to/precompute_cache \
69
  --out ./qadit-export \
70
  --push-to-hub USER/qadit
 
 
 
 
 
 
71
  ```
72
 
73
  This writes `config.json`, `model.safetensors`, and the remote-code `.py` files.
74
- `latent_scale` is taken from `cache/train/meta.json` (must match training).
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  ## Files
77
 
 
41
  "Rain falls heavily on a metal roof with distant thunder",
42
  num_inference_steps=50,
43
  guidance_scale=4.0,
44
+ seed=0, # same default as the original audio_dit/sample.py
45
  )
46
 
47
  sf.write("rain.wav", out.audios[0], out.sampling_rate)
48
  ```
49
 
50
+ To reproduce an existing `audio_dit/sample.py` result, use the **same prompt,
51
+ steps, CFG scale and seed**. For example, the original high-guidance test was:
52
+
53
+ ```python
54
+ out = model.generate(
55
+ "Rain falls heavily on a roof top with distant thunder",
56
+ num_inference_steps=200,
57
+ guidance_scale=16.0,
58
+ seed=0,
59
+ )
60
+ ```
61
+
62
  ### Useful `generate` knobs
63
 
64
  | Argument | Default | Meaning |
65
  |---|---|---|
66
  | `num_inference_steps` | 50 | DDIM steps |
67
  | `guidance_scale` | 4.0 | CFG scale (try 5–7 for crisper AudioCaps-style prompts) |
68
+ | `seed` | 0 | Initial latent noise seed; set it for reproducible A/B tests |
69
  | `output_type` | `"np"` | `"np"` / `"pt"` / `"latent"` |
70
  | `generator` | `None` | `torch.Generator` for reproducibility |
71
 
 
76
  From the research repo:
77
 
78
  ```bash
79
+ # DDP checkpoints already embed train meta — no cache needed
80
  python qadit_hf/convert_checkpoint.py \
81
  --ckpt path/to/ckpt_0023999.pt \
 
82
  --out ./qadit-export \
83
  --push-to-hub USER/qadit
84
+
85
+ # Or pass the known scale explicitly (from your training log, e.g. 0.9503)
86
+ python qadit_hf/convert_checkpoint.py \
87
+ --ckpt path/to/ckpt_0023999.pt \
88
+ --latent-scale 0.9503 \
89
+ --out ./qadit-export
90
  ```
91
 
92
  This writes `config.json`, `model.safetensors`, and the remote-code `.py` files.
93
+ Only `latent_scale` is needed beyond the checkpoint weights/config; architecture
94
+ comes from `ckpt["config"]`.
95
+
96
+ Verify the Hub/export weights and settings against the original checkpoint:
97
+
98
+ ```bash
99
+ python qadit_hf/verify_parity.py \
100
+ --ckpt path/to/ckpt_0023999.pt \
101
+ --model USER/qadit
102
+ ```
103
+
104
+ Add `--forward --device cuda` for a full numerical DiT forward comparison.
105
 
106
  ## Files
107
 
config.json CHANGED
@@ -1,38 +1,36 @@
1
  {
2
- "architectures": [
3
- "QaDiTModel"
4
- ],
5
  "auto_map": {
6
  "AutoConfig": "configuration_qadit.QaDiTConfig",
7
  "AutoModel": "modelling_qadit.QaDiTModel"
8
  },
9
- "depth": 12,
10
- "dtype": "float32",
11
- "duration_s": 10.24,
12
- "guidance_scale": 4.0,
13
- "hidden_size": 768,
14
  "latent_channels": 8,
15
- "latent_freq": 16,
16
- "latent_scale": 0.9503,
17
  "latent_time": 256,
18
- "load_auxiliaries": true,
19
- "logit_normal_mean": 0.0,
20
- "logit_normal_std": 1.0,
21
- "mlp_ratio": 4.0,
22
- "model_type": "qadit",
23
- "num_heads": 12,
24
- "num_inference_steps": 50,
25
- "num_train_timesteps": 1000,
26
  "patch_size": 2,
 
 
 
 
27
  "repa_layer": 4,
28
- "sample_rate": 16000,
29
- "schedule": "cosine",
30
  "text_dim": 1024,
31
  "text_max_length": 64,
32
- "text_model": "google/flan-t5-large",
33
- "transformers_version": "5.14.1",
34
  "vae_model": "cvssp/audioldm-s-full-v2",
35
  "vae_subfolder": "vae",
36
  "vocoder_model": "cvssp/audioldm-s-full-v2",
37
- "vocoder_subfolder": "vocoder"
 
 
 
 
 
 
 
 
 
 
 
38
  }
 
1
  {
2
+ "architectures": ["QaDiTModel"],
3
+ "model_type": "qadit",
 
4
  "auto_map": {
5
  "AutoConfig": "configuration_qadit.QaDiTConfig",
6
  "AutoModel": "modelling_qadit.QaDiTModel"
7
  },
 
 
 
 
 
8
  "latent_channels": 8,
 
 
9
  "latent_time": 256,
10
+ "latent_freq": 16,
11
+ "latent_scale": 0.9503493000009796,
 
 
 
 
 
 
12
  "patch_size": 2,
13
+ "hidden_size": 768,
14
+ "depth": 12,
15
+ "num_heads": 12,
16
+ "mlp_ratio": 4.0,
17
  "repa_layer": 4,
18
+ "text_model": "google/flan-t5-large",
 
19
  "text_dim": 1024,
20
  "text_max_length": 64,
 
 
21
  "vae_model": "cvssp/audioldm-s-full-v2",
22
  "vae_subfolder": "vae",
23
  "vocoder_model": "cvssp/audioldm-s-full-v2",
24
+ "vocoder_subfolder": "vocoder",
25
+ "sample_rate": 16000,
26
+ "duration_s": 10.24,
27
+ "num_train_timesteps": 1000,
28
+ "schedule": "cosine",
29
+ "logit_normal_mean": 0.0,
30
+ "logit_normal_std": 1.0,
31
+ "num_inference_steps": 50,
32
+ "guidance_scale": 4.0,
33
+ "load_auxiliaries": true,
34
+ "torch_dtype": "float32",
35
+ "transformers_version": "4.40.0"
36
  }
configuration_qadit.py CHANGED
@@ -19,7 +19,9 @@ class QaDiTConfig(PretrainedConfig):
19
  latent_channels: int = 8,
20
  latent_time: int = 256,
21
  latent_freq: int = 16,
22
- latent_scale: float = 1.0,
 
 
23
  # DiT-B (~160M)
24
  patch_size: int = 2,
25
  hidden_size: int = 768,
 
19
  latent_channels: int = 8,
20
  latent_time: int = 256,
21
  latent_freq: int = 16,
22
+ # Exact scale embedded in the released step-23999 training checkpoint.
23
+ # Converted checkpoints override this from their own train metadata.
24
+ latent_scale: float = 0.9503493000009796,
25
  # DiT-B (~160M)
26
  patch_size: int = 2,
27
  hidden_size: int = 768,
modelling_qadit.py CHANGED
@@ -656,6 +656,7 @@ class QaDiTModel(PreTrainedModel):
656
  encoder_attention_mask: Optional[torch.Tensor] = None,
657
  num_inference_steps: Optional[int] = None,
658
  guidance_scale: Optional[float] = None,
 
659
  generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
660
  eta: float = 0.0,
661
  output_type: str = "np",
@@ -673,16 +674,26 @@ class QaDiTModel(PreTrainedModel):
673
  DDIM steps (default from config).
674
  guidance_scale:
675
  Classifier-free guidance scale (default from config).
 
 
 
676
  output_type:
677
  ``"np"`` → numpy waveforms, ``"pt"`` → torch waveforms,
678
  ``"latent"`` → scaled latents only (no VAE/vocoder).
679
  """
680
  cfg = self.config
681
  device = self.device
 
 
 
682
  steps = num_inference_steps or cfg.num_inference_steps
683
  guidance = (
684
  guidance_scale if guidance_scale is not None else cfg.guidance_scale
685
  )
 
 
 
 
686
 
687
  if encoder_hidden_states is None:
688
  if prompt is None:
@@ -713,6 +724,8 @@ class QaDiTModel(PreTrainedModel):
713
  cfg.latent_freq,
714
  )
715
 
 
 
716
  if isinstance(generator, list):
717
  if len(generator) != B:
718
  raise ValueError(
 
656
  encoder_attention_mask: Optional[torch.Tensor] = None,
657
  num_inference_steps: Optional[int] = None,
658
  guidance_scale: Optional[float] = None,
659
+ seed: Optional[int] = 0,
660
  generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
661
  eta: float = 0.0,
662
  output_type: str = "np",
 
674
  DDIM steps (default from config).
675
  guidance_scale:
676
  Classifier-free guidance scale (default from config).
677
+ seed:
678
+ Random seed used when ``generator`` is not supplied. Defaults to
679
+ 0, matching the original ``audio_dit/sample.py`` CLI.
680
  output_type:
681
  ``"np"`` → numpy waveforms, ``"pt"`` → torch waveforms,
682
  ``"latent"`` → scaled latents only (no VAE/vocoder).
683
  """
684
  cfg = self.config
685
  device = self.device
686
+ # from_pretrained() normally returns eval mode, but make generation
687
+ # invariant to callers having toggled train() in the same process.
688
+ self.eval()
689
  steps = num_inference_steps or cfg.num_inference_steps
690
  guidance = (
691
  guidance_scale if guidance_scale is not None else cfg.guidance_scale
692
  )
693
+ if cfg.latent_scale <= 0:
694
+ raise ValueError(
695
+ f"config.latent_scale must be positive, got {cfg.latent_scale}"
696
+ )
697
 
698
  if encoder_hidden_states is None:
699
  if prompt is None:
 
724
  cfg.latent_freq,
725
  )
726
 
727
+ if generator is None and seed is not None:
728
+ generator = torch.Generator(device=device.type).manual_seed(seed)
729
  if isinstance(generator, list):
730
  if len(generator) != B:
731
  raise ValueError(