Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files415 unmodified lines416417418419420421422423424425426427428429430431432433434435436437438439415 unmodified linestiling_config = TilingConfig.default()video_chunks_number = get_video_chunks_number(num_frames, tiling_config)# >>> SET the LoRA descriptor strength at runtimetry:# lora_descriptor was created at module scope during initlora_descriptor.strength = float(lora_strength)print(f"[LoRA] set strength = {lora_descriptor.strength}")except Exception as e:# Defensive: if the descriptor isn't present, continue quietlyprint(f"[LoRA] could not set strength: {e}")# >>> FORCE transformer rebuild so LoRA strength updatestry:# Clear cached transformer so new LoRA strength is appliedif hasattr(pipeline.model_ledger, "_transformer"):pipeline.model_ledger._transformer = Noneprint("[LoRA] transformer cache cleared")except Exception as e:print(f"[LoRA] transformer reset failed: {e}")log_memory("before pipeline call")video, audio = pipeline(415 unmodified lines416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513415 unmodified linestiling_config = TilingConfig.default()video_chunks_number = get_video_chunks_number(num_frames, tiling_config)# >>> RUNTIME LoRA application (robust, multi-fallback)# We cannot rely on mutating the original descriptor (some implementations are immutable),# so create a fresh runtime descriptor and try multiple ways to install it.runtime_strength = float(lora_strength)replaced = False# 1) Try simple approach: build a new LoraPathStrengthAndSDOpsruntime_lora = LoraPathStrengthAndSDOps(lora_path, runtime_strength, LTXV_LORA_COMFY_RENAMING_MAP)print(f"[LoRA] attempting to apply runtime LoRA (strength={runtime_strength})")# Try a few likely places to replace the descriptor used by the pipeline/ledger.try:# common attribute on pipelineif hasattr(pipeline, "loras"):try:pipeline.loras = [runtime_lora]replaced = Trueprint("[LoRA] replaced pipeline.loras")except Exception as e:print(f"[LoRA] pipeline.loras assignment failed: {e}")except Exception:passtry:# common attribute on the model ledgerif hasattr(pipeline, "model_ledger") and hasattr(pipeline.model_ledger, "loras"):try:pipeline.model_ledger.loras = [runtime_lora]replaced = Trueprint("[LoRA] replaced pipeline.model_ledger.loras")except Exception as e:print(f"[LoRA] pipeline.model_ledger.loras assignment failed: {e}")except Exception:passtry:# some internals use a private _loras listif hasattr(pipeline, "model_ledger") and hasattr(pipeline.model_ledger, "_loras"):try:pipeline.model_ledger._loras = [runtime_lora]replaced = Trueprint("[LoRA] replaced pipeline.model_ledger._loras")except Exception as e:print(f"[LoRA] pipeline.model_ledger._loras assignment failed: {e}")except Exception:pass# 2) If we succeeded replacing the descriptor in-place, clear transformer cache so it will rebuildif replaced:try:if hasattr(pipeline.model_ledger, "_transformer"):pipeline.model_ledger._transformer = None# also clear potential caches named similar to 'transformer_cache' if presentif hasattr(pipeline.model_ledger, "transformer_cache"):try:pipeline.model_ledger.transformer_cache = {}except Exception:passprint("[LoRA] in-place descriptor replacement done; transformer cache cleared")except Exception as e:print(f"[LoRA] replacement succeeded but cache clearing failed: {e}")# 3) FINAL FALLBACK - if none of the in-place replacements worked, rebuild the pipelineif not replaced:print("[LoRA] in-place replacement FAILED; rebuilding pipeline with runtime LoRA (this is slow)")try:# Rebuild pipeline object with the new LoRA descriptor# NOTE: this replaces the global `pipeline`. We must declare global to reassign it.global pipelinepipeline = LTX23DistilledA2VPipeline(distilled_checkpoint_path=checkpoint_path,spatial_upsampler_path=spatial_upsampler_path,gemma_root=gemma_root,loras=[runtime_lora],quantization=QuantizationPolicy.fp8_cast(),)# After rebuilding, we *do not* re-run the original module-level preloads here,# because re-pinning may be complex; the rebuilt pipeline will construct its# own ledger as part of the first call. This is slower but reliable.# Clear any transformer caches if they exist on the new ledger as well.try:if hasattr(pipeline.model_ledger, "_transformer"):pipeline.model_ledger._transformer = Noneexcept Exception:passprint("[LoRA] pipeline rebuilt with runtime LoRA")except Exception as e:print(f"[LoRA] pipeline rebuild FAILED: {e}")# Finally, log memory then proceedlog_memory("before pipeline call")video, audio = pipeline(
app.py+90-16