dagloop5 commited on
Commit
690fc2b
·
verified ·
1 Parent(s): b7e495d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -19
app.py CHANGED
@@ -44,7 +44,7 @@ GPU_SIZE = os.environ.get("H3_GPU_SIZE", "xlarge")
44
  # against an earlier release of the same lineage.
45
  CUSTOM_TRANSFORMER_REPO = os.environ.get("H3_CUSTOM_TRANSFORMER_REPO", "SexGod1979/PinkCherry_MiniMax-H3")
46
  CUSTOM_TRANSFORMER_FILE = os.environ.get(
47
- "H3_CUSTOM_TRANSFORMER_FILE", "v1-final-fl2va/PinkCherry_v1_fp16_fla2va_H3.safetensors"
48
  )
49
 
50
  LORA_REPO = os.environ.get("H3_LORA_REPO", "dagloop5/LoRA")
@@ -507,27 +507,57 @@ def load_models() -> str | None:
507
  custom_transformer = MiniMaxH3Transformer3DModel.from_config(config)
508
  base_shapes = {k: tuple(v.shape) for k, v in custom_transformer.state_dict().items()}
509
 
510
- custom_path = hf_hub_download(CUSTOM_TRANSFORMER_REPO, CUSTOM_TRANSFORMER_FILE)
511
- with safe_open(custom_path, framework="pt") as handle:
512
- raw = {k: handle.get_tensor(k) for k in handle.keys()}
513
- converted = _convert_full_checkpoint(raw, base_shapes)
514
- if os.environ.get("H3_DEBUG_COMPARE", "0") == "1":
515
- from huggingface_hub import hf_hub_download as _dl
 
 
 
516
  import json as _json
517
-
518
- index_path = _dl(MODEL_REPO, "transformer/diffusion_pytorch_model.safetensors.index.json")
 
 
519
  with open(index_path) as handle:
520
  index = _json.load(handle)
521
- probe_key = "transformer_blocks.0.attn.to_q.weight"
522
- shard_name = index["weight_map"][probe_key]
523
- shard_path = _dl(MODEL_REPO, f"transformer/{shard_name}")
524
- with safe_open(shard_path, framework="pt") as official_handle:
525
- official_tensor = official_handle.get_tensor(probe_key)
526
- converted_tensor = converted[probe_key]
527
- print(f"[debug-compare] official {probe_key}: mean={official_tensor.float().mean():.6f} std={official_tensor.float().std():.6f} first5={official_tensor.flatten()[:5].tolist()}", flush=True)
528
- print(f"[debug-compare] converted {probe_key}: mean={converted_tensor.float().mean():.6f} std={converted_tensor.float().std():.6f} first5={converted_tensor.flatten()[:5].tolist()}", flush=True)
529
- print(f"[debug-compare] allclose: {torch.allclose(official_tensor, converted_tensor)}", flush=True)
530
- custom_transformer.load_state_dict(converted, strict=True, assign=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
531
 
532
  # `rope.inv_freq` is a *non-persistent* buffer (`persistent=False` in `MiniMaxH3RotaryPosEmbed`) —
533
  # excluded from `state_dict()` entirely, which is exactly why `strict=True` above never complained
 
44
  # against an earlier release of the same lineage.
45
  CUSTOM_TRANSFORMER_REPO = os.environ.get("H3_CUSTOM_TRANSFORMER_REPO", "SexGod1979/PinkCherry_MiniMax-H3")
46
  CUSTOM_TRANSFORMER_FILE = os.environ.get(
47
+ "H3_CUSTOM_TRANSFORMER_FILE", "v1-final-fl2va/PinkCherry_v1_bf16_fla2va_H3.safetensors"
48
  )
49
 
50
  LORA_REPO = os.environ.get("H3_LORA_REPO", "dagloop5/LoRA")
 
507
  custom_transformer = MiniMaxH3Transformer3DModel.from_config(config)
508
  base_shapes = {k: tuple(v.shape) for k, v in custom_transformer.state_dict().items()}
509
 
510
+ if os.environ.get("H3_DEBUG_OFFICIAL_VIA_META", "0") == "1":
511
+ # Isolates the meta-device + `assign=True` loading mechanism from `_convert_full_checkpoint`'s
512
+ # own conversion logic: loads the official, diffusers-native shards — no renaming, no splitting,
513
+ # nothing converted at all — through the exact same path the custom-checkpoint loader uses. If
514
+ # this *also* produces the same corrupted output, the bug is in the mechanism itself (meta
515
+ # construction, `assign=True`, the fp32 upcast, or something in between), independent of
516
+ # anything the conversion does, since no conversion happens here at all. If this loads clean,
517
+ # the bug is narrowed back to `_convert_full_checkpoint` specifically, despite everything
518
+ # checked against it so far.
519
  import json as _json
520
+
521
+ index_path = hf_hub_download(
522
+ MODEL_REPO, "transformer/diffusion_pytorch_model.safetensors.index.json"
523
+ )
524
  with open(index_path) as handle:
525
  index = _json.load(handle)
526
+ shard_names = sorted(set(index["weight_map"].values()))
527
+ official_state_dict = {}
528
+ for shard_name in shard_names:
529
+ shard_path = hf_hub_download(MODEL_REPO, f"transformer/{shard_name}")
530
+ with safe_open(shard_path, framework="pt") as shard_handle:
531
+ for key in shard_handle.keys():
532
+ official_state_dict[key] = shard_handle.get_tensor(key)
533
+ custom_transformer.load_state_dict(official_state_dict, strict=True, assign=True)
534
+ print(
535
+ "[gen] loaded the OFFICIAL weights via the meta+assign path, bypassing "
536
+ "_convert_full_checkpoint entirely — diagnostic only",
537
+ flush=True,
538
+ )
539
+ else:
540
+ custom_path = hf_hub_download(CUSTOM_TRANSFORMER_REPO, CUSTOM_TRANSFORMER_FILE)
541
+ with safe_open(custom_path, framework="pt") as handle:
542
+ raw = {k: handle.get_tensor(k) for k in handle.keys()}
543
+ converted = _convert_full_checkpoint(raw, base_shapes)
544
+ if os.environ.get("H3_DEBUG_COMPARE", "0") == "1":
545
+ from huggingface_hub import hf_hub_download as _dl
546
+ import json as _json
547
+
548
+ index_path = _dl(MODEL_REPO, "transformer/diffusion_pytorch_model.safetensors.index.json")
549
+ with open(index_path) as handle:
550
+ index = _json.load(handle)
551
+ probe_key = "transformer_blocks.0.attn.to_q.weight"
552
+ shard_name = index["weight_map"][probe_key]
553
+ shard_path = _dl(MODEL_REPO, f"transformer/{shard_name}")
554
+ with safe_open(shard_path, framework="pt") as official_handle:
555
+ official_tensor = official_handle.get_tensor(probe_key)
556
+ converted_tensor = converted[probe_key]
557
+ print(f"[debug-compare] official {probe_key}: mean={official_tensor.float().mean():.6f} std={official_tensor.float().std():.6f} first5={official_tensor.flatten()[:5].tolist()}", flush=True)
558
+ print(f"[debug-compare] converted {probe_key}: mean={converted_tensor.float().mean():.6f} std={converted_tensor.float().std():.6f} first5={converted_tensor.flatten()[:5].tolist()}", flush=True)
559
+ print(f"[debug-compare] allclose: {torch.allclose(official_tensor, converted_tensor)}", flush=True)
560
+ custom_transformer.load_state_dict(converted, strict=True, assign=True)
561
 
562
  # `rope.inv_freq` is a *non-persistent* buffer (`persistent=False` in `MiniMaxH3RotaryPosEmbed`) —
563
  # excluded from `state_dict()` entirely, which is exactly why `strict=True` above never complained