Spaces:
Paused
Paused
Update app.py
Browse files254 unmodified lines2552562572582592602612629 unmodified lines272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352254 unmodified lines# Model reposLTX_MODEL_REPO = "Lightricks/LTX-2.3"GEMMA_REPO ="Lightricks/gemma-3-12b-it-qat-q4_0-unquantized"GEMMA_ABLITERATED_REPO = "Sikaworld1990/gemma-3-12b-it-abliterated-sikaworld-high-fidelity-edition-Ltx-2"GEMMA_ABLITERATED_FILE = "gemma-3-12b-it-abliterated-sikaworld-high-fidelity-edition.safetensors"# Download model checkpointsprint("=" * 80)9 unmodified linesPENDING_LORA_STATE: dict[str, torch.Tensor] | None = NonePENDING_LORA_STATUS: str = "No LoRA state prepared yet."weights_dir = Path("weights")weights_dir.mkdir(exist_ok=True)checkpoint_path = hf_hub_download(repo_id="SulphurAI/Sulphur-2-base",filename="sulphur_distil_bf16.safetensors",local_dir=str(weights_dir),local_dir_use_symlinks=False,)print("[Gemma] Setting up abliterated Gemma text encoder...")MERGED_WEIGHTS = "/tmp/abliterated_gemma_merged.safetensors"gemma_root = "/tmp/abliterated_gemma"os.makedirs(gemma_root, exist_ok=True)gemma_official_dir = snapshot_download(repo_id=GEMMA_REPO,ignore_patterns=["*.safetensors", "*.safetensors.index.json"],)for fname in os.listdir(gemma_official_dir):src = os.path.join(gemma_official_dir, fname)dst = os.path.join(gemma_root, fname)if os.path.isfile(src) and not fname.endswith(".safetensors") and fname != "model.safetensors.index.json":if not os.path.exists(dst):os.symlink(src, dst)if os.path.exists(MERGED_WEIGHTS):print("[Gemma] Using cached merged weights")else:abliterated_weights_path = hf_hub_download(repo_id=GEMMA_ABLITERATED_REPO,filename=GEMMA_ABLITERATED_FILE,)index_path = hf_hub_download(repo_id=GEMMA_REPO,filename="model.safetensors.index.json")with open(index_path) as f:weight_index = json.load(f)vision_keys = {}for key, shard in weight_index["weight_map"].items():if "vision_tower" in key or "multi_modal_projector" in key:vision_keys[key] = shardneeded_shards = set(vision_keys.values())shard_paths = {}for shard_name in needed_shards:shard_paths[shard_name] = hf_hub_download(repo_id=GEMMA_REPO,filename=shard_name)_fp8_types = {torch.float8_e4m3fn, torch.float8_e5m2}raw = load_file(abliterated_weights_path)merged = {}for key, tensor in raw.items():t = tensor.to(torch.bfloat16) if tensor.dtype in _fp8_types else tensormerged[f"language_model.{key}"] = tdel rawfor key, shard_name in vision_keys.items():with safe_open(shard_paths[shard_name], framework="pt") as f:merged[key] = f.get_tensor(key)save_file(merged, MERGED_WEIGHTS)del mergedgc.collect()weight_link = os.path.join(gemma_root, "model.safetensors")if os.path.exists(weight_link):os.remove(weight_link)os.symlink(MERGED_WEIGHTS, weight_link)print(f"[Gemma] Root ready: {gemma_root}")spatial_upsampler_path = hf_hub_download(repo_id=LTX_MODEL_REPO, filename="ltx-2.3-spatial-upscaler-x2-1.1.safetensors")gemma_root = snapshot_download(repo_id=GEMMA_REPO)254 unmodified lines2552562572582592609 unmodified lines270271272273274275276254 unmodified lines# Model reposLTX_MODEL_REPO = "Lightricks/LTX-2.3"GEMMA_REPO ="Lightricks/gemma-3-12b-it-qat-q4_0-unquantized"# Download model checkpointsprint("=" * 80)9 unmodified linesPENDING_LORA_STATE: dict[str, torch.Tensor] | None = NonePENDING_LORA_STATUS: str = "No LoRA state prepared yet."checkpoint_path = hf_hub_download(repo_id="SulphurAI/Sulphur-2-base", filename="sulphur_distil_bf16.safetensors")spatial_upsampler_path = hf_hub_download(repo_id=LTX_MODEL_REPO, filename="ltx-2.3-spatial-upscaler-x2-1.1.safetensors")gemma_root = snapshot_download(repo_id=GEMMA_REPO)
app.py+1-77