From fe4ff9c20c2cc8bb375625d1534f5673a737d1be Mon Sep 17 00:00:00 2001 From: ukr8b3g-cmyk Date: Sun, 30 Aug 2026 02:46:02 +0900 Subject: [PATCH] Release v3.7.0 refinement foundation --- AGENTS.md | 3 +- CHANGELOG.md | 14 + MANIFEST.sha256 | 67 ++--- PACKAGE_INFO_JA.txt | 13 +- PACKAGE_VALIDATION.txt | 15 +- PROJECT_STATE.md | 33 ++- README.md | 26 +- README_JA.md | 26 +- WORKLOG.md | 52 ++++ guide_timeline.py | 357 +++++++++++++++++++++++++ metadata.ini | 2 +- model_patch.py | 206 +++++++++++++- nodes.py | 2 + pyproject.toml | 2 +- run_storage.py | 80 +++++- tests/test_model_patch.py | 70 +++++ tests/test_release_metadata.py | 2 +- tests/test_v217_stable_facade.py | 2 +- tests/test_v2_prompts.py | 135 ++++++++++ tests/test_v2_terminal_merge.py | 45 ++++ tests/test_v31_run_storage.py | 197 +++++++++++++- tests/test_v35_compact_ui_frontend.py | 118 ++++++++ tests/test_v35_hires_fix.py | 3 + tests/test_v35_refine_context.py | 66 +++++ tests/test_v35_second_pass_sampling.py | 56 ++++ tests/test_v37_guide_production.py | 328 +++++++++++++++++++++++ tests/test_v37_guide_timeline.py | 151 +++++++++++ tests/test_v37_refine_schedule.py | 119 +++++++++ tools/verify_runtime.py | 2 + v2/nodes.py | 2 + v2/sequence.py | 151 ++++++++++- v3/driving_nodes.py | 93 +++++++ v3/hires_fix_nodes.py | 2 + v3/nodes.py | 4 + v3/refine_context.py | 48 +++- v3/refine_schedule.py | 214 +++++++++++++++ v3/second_pass.py | 27 +- v3/second_pass_nodes.py | 2 + version.py | 2 +- web/project_id.js | 29 +- 40 files changed, 2681 insertions(+), 85 deletions(-) create mode 100644 guide_timeline.py create mode 100644 tests/test_v37_guide_production.py create mode 100644 tests/test_v37_guide_timeline.py create mode 100644 tests/test_v37_refine_schedule.py create mode 100644 v3/refine_schedule.py diff --git a/AGENTS.md b/AGENTS.md index b2357e9..91967f9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,7 +1,7 @@ # AGENTS.md ## Scope -MiniMax H3 Continuum V3.6.1 for ComfyUI. Treat V3.6 as the current Production baseline; preserve V3.5.3/V3.4 node IDs, public contracts, and saved-workflow loading without letting legacy controls change current behavior. +MiniMax H3 Continuum V3.7.0 for ComfyUI. Treat the accepted V3.6 generation defaults as the current Production baseline; preserve V3.6.1/V3.5.3/V3.4 node IDs, public contracts, and saved-workflow loading without letting legacy or Experimental controls change current behavior. Still Image Guide remains Experimental / Production HOLD. ## Non-negotiable rules - Follow ComfyUI Core behavior for user-facing validation. Continuum-only prompt restrictions, model allowlists, compatibility gates, and policy-based execution stops are prohibited. @@ -47,6 +47,7 @@ GPU checks must cover Sage only, Sage+Sol, Sage+Spectrum, and Sage+Sol+Spectrum - Source repository: `D:\Codex\_git_push_work\ComfyUI-H3-Continuum` - Primary tested runtime: `D:\StabilityMatrix\Data\Packages\ComfyUI_W\custom_nodes\ComfyUI-H3-Continuum` - Secondary runtime: `D:\StabilityMatrix\Data\Packages\ComfyUI_WAN\custom_nodes\ComfyUI-H3-Continuum` +- Restart ComfyUI_W with `D:\StabilityMatrix\Data\Packages\ComfyUI_W\venv\Scripts\python.exe`. Do not launch the base executable reported by `Get-Process.Path`; it omits the venv dependencies even though it is the resolved process image. - Reuse the repository's existing pytest configuration and helper scripts instead of rediscovering paths on every task. - Read this file before each task. Record durable project decisions, paths, commands, failure causes, and validation methods here so later work reuses them instead of restarting from zero. - GitHub authentication for this repository is already configured. Do not request a new login or token unless an actual authentication command fails. diff --git a/CHANGELOG.md b/CHANGELOG.md index 7af9e93..424c4fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,21 @@ # Changelog +## 3.7.0 + +- Added `H3 Continuum Sampler V3.7` with one optional Still Image Guide input while preserving the V3.6 required-input schema, Production defaults, and saved-workflow compatibility. +- Generalized the Second Pass Conditioning Adapter so First/Last images, continuation context, and an owned Still Image Guide can be rebuilt at target latent geometry. Physical-group and Long Terminal Merge ownership remain intact. +- Added the internal schema-v1 `RefineSchedule` contract with `External`, `Full`, `Tail`, and `Partial` modes. Existing SIGMAS input remains compatible, and Tail/Partial use exact ranges from the source schedule. +- GPU-validated the internal Tail 6 suffix at 704×704 against the prior external Tail 6 path, with decoded Video SSIM `0.982936` and bit-exact decoded Audio PCM. +- Completed a 1152×1152 Conditioning correctness gate in which the original Still Image Guide source was reencoded at target geometry without changing the first-pass Audio contract. +- Added explicit source-role ownership so a Still Guide sharing the same frame as First/Last is not replaced by the endpoint image, and restricted Still Image Guide input to exactly one IMAGE. +- Added V3.7 compact-frontend parity for project identity, hidden internal widgets, Run Storage controls, queue normalization, diagnostics, and permanent Reference Audio sockets. +- Kept Still Image Guide **Experimental / Production HOLD**. Core hard-anchor semantics can cause an abrupt trajectory change at the Guide frame and redirect later motion; it is not a smooth transition control. +- Preserved V3.6/V3.5/V3.4 node IDs, public Second Pass schemas, Core PackedLayout/RoPE construction, Run Storage compatibility, and Production generation defaults. + ## 3.6.1 +- Canonicalized an absent Last Frame hash as `""` and added a narrowly scoped compatibility path for V3.6.1 caches whose old final chunk stored `"none"`. Extending a normal no-Last-Frame run from two to three chunks now reuses both stored chunks, while a real Last Frame and Long Terminal Merge still invalidate/regenerate their required sampling units. +- When Run Storage is turned Off, the compact frontend now resets hidden `Regenerate From` to `Auto` and `Variation Nonce` to `0`; the backend rejection remains as a non-UI safety check. - Added non-blocking mixed Prompt syntax diagnostics. Timeline mode now ignores standalone `---` separator lines with `H3C-P105`, while preserving existing uncovered-chunk fallback and Fixed-prompt fail-open behavior. - Prevented V3.6 Standard continuation from stopping when Audio Continuity is enabled with Fast 5, Strong 39, or Auto. These modes now resolve to the accepted Reference Context transport before Run Storage identity is created; Balanced 22 continues to use Masked AV. - Kept Standard with Audio Continuity disabled on Masked Video, and kept Compatibility on Reference Context for every Continuity mode. diff --git a/MANIFEST.sha256 b/MANIFEST.sha256 index d5198a0..5ebf12a 100644 --- a/MANIFEST.sha256 +++ b/MANIFEST.sha256 @@ -1,12 +1,13 @@ dca65fb1393e67f59c6f81f9411e3e745eb8f1097e9a2adf7ffc6f4e3901ca9f __init__.py 4f6feeb2f63a9285b0e76fb2e2618058c7d7c279af1632e1a6ccabcc9ec9a45a .github/workflows/tests.yml 0a2f69d4cec89d440f5d5aa1ec68a7c9a741382d313f80dcddf96d13f70b3e68 .gitignore -53c4968d636bf5196cf0b54ca23c4c0994721476c3c7257ca5865b4db900db2f AGENTS.md -8bc35ff12ac4a53ccf0f2821b03cf78d9e30ec3b095efb7a630e8daa0869a63c CHANGELOG.md +53bab1717a2e87602a45837a13998ac3f251cda354e1f547a23f8631bd5f2456 AGENTS.md +972c437a560f4fa096a663498b39688f98e68078bfd14c54342cf98ee5cc046e CHANGELOG.md e97e47c7585e81d9ec5fd32c0ca0b64699fd4610cd03e9d6575a91c30a10ca4e compatibility.py 4d62508f900af9f93ec320afb900c27cc9a300d1e0c0a94714258498c5ede5fc conditioning.py 64967f4987e3ad9316f3a47f0dcf582eeff39ee0c3485f4184d3532d495534ae constants.py cf255b8a635471229aebadc926acfdcacb65963adbcb9e0f9505d04eada2c6b5 continuation.py +bf0556b076dbaca67c3405a7d86c333ca7fdf3d4381529b0a9edc906519943e9 guide_timeline.py f9375629fa1a2c4d3538442f0c3192d7ba2f46fe9544fb2e21f0c144b53d608c docs/AB_TEST_LOG_JA.md c93a3e52e4deabe5ef0db7f34a7605856a543089574ba17227e697e9a2c0139a docs/ARCHITECTURE.md 7660570840229b6fcbe62f0fbb52966d0099d64d7e6f01a739fbf9899293c8e4 docs/FUTURE_ROADMAP.md @@ -69,21 +70,21 @@ d74073e7ee292ebeba913af4288284f9f197cd91fceed6c62bf6c66b784c7cec install_window 6aa3f5780baa7bb0c0672b5f01a2f77e5f209da93f6373468cb274ea2f643d4b layout_adapter.py c44abbd789091bbead01250dbd5453e60539d2665c69f162335fdbd2936019c2 LICENSE d3e213005670e94dee33a240349a4d245cf9a3b6602099f11ed30cf5a32e2c21 media.py -e2b2049a29c2a4f4b273a3283551c5bc4c25add3918570f21f249056eac83e60 metadata.ini -ef705a476e3f5bbd05559e7a0e7d3dfb9275badef0f8f65fb1a36ce27fbcb537 model_patch.py -069149bbdc9a2d610ce43212d2f57714f22829988e863cd72a3e04095ab93f70 nodes.py -f456a678af61f0feeae009bce89db763b60c820444d75ff5d2a30bb74991c66b PACKAGE_INFO_JA.txt -9fdc3ec8af3b048b668451b2604db5248c2fd1a99e92a567f6db315fe7f928e6 PACKAGE_VALIDATION.txt +3b3ed9c27bb29b9d77f146c4aada1ce20adb9ffc551465cdcad699971869c256 metadata.ini +b08f4deb90628aa2cd6e219f59c3109fdda8c1e9a6571ba784a560d55b2b7f9d model_patch.py +9332e48af66e5a179e142c377abd830a2b9f0e5baef0640d8ac907be33120cf2 nodes.py +d2b235868cf6c21971f9ec7620c487382f3fb83c7cf7cbf87af0ed1cc0cdbd38 PACKAGE_INFO_JA.txt +ddc9ec3c96cf8f00dc082e0c4576cbf4952f79d8a6990c2e69901cc45fa33c98 PACKAGE_VALIDATION.txt b470819f16fc179654dc1600721a63f0a5a14e777f4c004d574b499da6886ba5 public_api.py -97415d587e8ab835f1c22a375fe64d73541440f86f11afeace15fed69c1ae839 pyproject.toml +1840e43c3cdcea05c098a579e2dc9df4562f0aa0f00e12c42dd5bc5bb1efb8af pyproject.toml 94fdc2d545b2d4077a4d70229fd22ba3ccac21d49d1097d2873f76d04e9a3c7a pytest.ini -c9000b17f8cb5b6e19bb08c74b9aba26166e6a4950b11da52b0c4c951fe4b14e README_JA.md -ad802d64cf8fa4c4d35c349e30c56de72792cb06337033f990d282799717ac8c README.md +a2df354b9fccd7cf26c20dc917179ca8859b42a5cdb6891c05f73f6b5f8f1658 README_JA.md +0f7062f802fc7e623ddf4dedb65688e3095ce1e800dbdab87dd52007c4deb374 README.md 5d89c366b4f076fa73a2695557e0af749bf95df1dad0d55dbb2fe5b1c2519ad7 reference_audio.py a0266ab4434b8e9844219d2b6dd8a168d198dd8f142775be01a39b81dc196b91 reference_video.py 564f5f2bf29665059845a98b9ca3e9a1309566aab73bcaa96f95fab8251ab06c reference.py 467edb2c188d024c2392aafe7423b3f835e16b10f570da76e2f7dda8a962c1c5 requirements.txt -30ac248e4675e4fd15284de90d6f6dc6ee68ace2c4d3abe425c906e08cb89708 run_storage.py +f28afe2c0033f1aa0ef3053e9005badd51242d4431a6d191af375ab2a59f50b3 run_storage.py 6056de6c0a5322a8a51ba5a114538dca2ef67788cd1afba10fedd483b95f6afa state_io.py 3a359a0467725cc292ccb4c86cf0c3d30bb6a114d01f5345792b09ea3d45441d state.py 43ec4023dc06c941e5d7a04db4b8a89fb58d744ceb986f6eb9bf534d4fdcb87b temporal.py @@ -92,7 +93,7 @@ a0266ab4434b8e9844219d2b6dd8a168d198dd8f142775be01a39b81dc196b91 reference_vide 875ac33b5458ec5e8d845850ed495707c394436aaadb668a44f36f6a1b73764d tests/test_conditioning_modes.py 2be669b6d21ec40a8b0e172b8ab431f82681f3c97c7de0935d87ad43b0ae8b4e tests/test_context_diagnostics.py c058f189d8e58fd48a80c20c0a857969737a8b13960eee60e5c17db2b9288bc1 tests/test_layout_adapter.py -e480c599daf0ede07bba8b90efbae627461c1797a5ebacf228630fd74ebc48d4 tests/test_model_patch.py +2dddf05bbb91b7aa803959a7a8ed78489792ea9c35c5634bfb7d5b1a6c81880f tests/test_model_patch.py 45e8839cd82fd955df344b3bc6efa20092b8870ea378b0c898b073665d3e47d7 tests/test_nodes_logic.py b635d404ca67df69894c4fcf80d8782cc5699e946bfb55ae4c44fff9d930b018 tests/test_p20_file_backed_tensor_poc.py 69a6155d3719d75bc9783d55c327100ca3097b2a8d71e6b82c1e5daf5191a568 tests/test_p21_memory_attribution.py @@ -103,78 +104,82 @@ d2a02c120e01d360ddca17a92d5bc53b12c9f0734d06440b3fc2fad2e754e549 tests/test_p23 403a0ff300330ac1f97642bf0681e80b83eec18e8911c03952ddf203ce794e5a tests/test_p46a_reference_video_memory.py 1ae0369943ba2fb13f21ad0cf56ee58621ba09bf20174379595e157a1775c7fd tests/test_public_api.py 892d3e3e022a527652dd995508c8bbb650c370caf9ee66fa3eb1f7fd288bba38 tests/test_public_workflow_integrity.py -336a7f1b04c28f2814fb3f039e1b0b97727b942f026e34e6d578a886de4ea62c tests/test_release_metadata.py +7681e942fea293e863ae28aee11ba9e69af2e0b7e1f99ac2c9e82cbe77c10ff1 tests/test_release_metadata.py d4c53d2c260b635d70fa211029d608f63776e0a56c20253475fa47c58363f8a7 tests/test_state_io.py 5af6a16a2337e3483bb0f9197fe04756decd309e4737520c5557b527d68d51bb tests/test_state.py a1f60f01e9d86c1f2a010752612e373e85112c7054ffc31185b9b459eb2b34a5 tests/test_temporal.py 970e8206c033c60d241732fc86f37018ffad2d66483ba235dd0eb39936ff718e tests/test_timeline_video.py dc8b9cf0e77b4983ee4eecc60f4acde7d0e063f3b7569402feca8a56165107fd tests/test_v2_decoder.py -5ad0940c23d343784f2fe13c344bfeeb35465cb948677811c99e0254115c3dea tests/test_v2_prompts.py +3cc94a6a7957ef285f58d373fbab001d926d2b43a754d60bb00bfce98675f32d tests/test_v2_prompts.py 5dfdd4b108ba7444c0f5f371c3b1e244b5735d23136127b9818fd60738c78b68 tests/test_v2_registration.py 86314c190d4335586c18191dc095926909c67fe839eb29e65324acd16c44f24e tests/test_v2_seam.py 74e623120a963cb96b68651b44f47a836ea8449d30ce89d749c71ffad4766d4e tests/test_v2_seeds_motion.py b42bcc0983147462d96c6b71cc4a38e846995dafa6eebefc3ae0d9bb36caf359 tests/test_v2_sequence_orchestration.py 0b5b20a8318862d167f135720e0489b8d4f93406d67c6646e052e35b03dcb876 tests/test_v2_session.py 58438c3ed814adf40cefde098a37cae00ddcb703b7e5548bbbb295e54bed5a6d tests/test_v2_widget_migration.py -021477ee5c5003b5d4d7da955fe71150b49156c3f654eb60e3a7f027e8b4e95d tests/test_v217_stable_facade.py +1db3b655866b70b297dee9c01e3d79d10b4f7efbc481a0edf5ac8bac12a56926 tests/test_v217_stable_facade.py 78bc478a5e4edda902c80849c911782a99e75c06dfb04127391b6cc5b27b28e1 tests/test_v3_hardening.py eb5b27f8f0d79529c56ef344a5601703642c3cba5388c9768116223e2ed58a36 tests/test_v3_video_seam.py -361970ce218abae028dcb163e691f835cde8c115e663f182ceb3aaf724cf10b0 tests/test_v31_run_storage.py +144433f5b5bca50e1933778ff1ba4a852b3e2c4a0108f8b50ef0be3bc9b14e5d tests/test_v31_run_storage.py 3af78ab85c8e19dee8d0a98bfd11a2c0e88c30d87256da1f9699c49a19a684e9 tests/test_v32_reference.py 72719bcd6686d84f518d80751e3754b875d34c2aa72e2183dfa05ac9158a9eb0 tests/test_v34_driving_audio.py -0afe1291a6f24d967a385e1c6c59fe581bdf2b9132f0030a67406cab92a06852 tests/test_v35_compact_ui_frontend.py +47c07c57934d4194ad56da2559b97631fc98b061ba1eb1b8390eab99d13648a6 tests/test_v35_compact_ui_frontend.py cf1ca6342a89e4cb02b398b32edbe91b6c1353535383e9f51d459466305a0114 tests/test_v35_conditioning_bridge.py f41ebbb64a9cab7dd74e97a149b25d8a15681b3a38003ec00b5baf4b6003b905 tests/test_v35_context_sampler.py -1de83989a361cd23af8a38686e27740eafd62299123c71a110dd5c0a337d136e tests/test_v35_hires_fix.py +a21c0722907ebb08fe24efbcf8b51494de546cde748a24d536e72270a9b784d1 tests/test_v35_hires_fix.py 9ceac8c3c6e4e57ec8b53b48f3b547c204df36a3f6281328aa9ab5ebc2e6a0b6 tests/test_v35_latent_resize.py 59a07f2172014dfdc0a447775324d7cd049f20b823276dfaf9b7b3f79628f5a8 tests/test_v35_pixel_vae_resize.py -4508d4d15bf48046b1664e385157f8f7f8cabdd7e6694726c8fa6e0b90ecbd1e tests/test_v35_refine_context.py +05ba609fb948665f050d58fb087569a158c040d08bebad1d728b911673b95462 tests/test_v35_refine_context.py 8ae5173eaec35adf9efcde2c464c95651c848248bdbdd6396ed2e3c3c1ac7965 tests/test_v35_refine_sampling.py 98a9006ebc4cab2b61b38904e0043fab24e088a25b28ffd38012c29991b8550c tests/test_v35_second_pass_contract.py -167d19efa7194c4dc52e39c3068d501023891e9a1dfba2ccf52440e7ca0d12fc tests/test_v35_second_pass_sampling.py +a11956a22f373d96f13b395971f39187d6bb12cdc153ce794b4729d258ce9725 tests/test_v35_second_pass_sampling.py 63d18643701c7d8be7b45046e6dc76616565572180afa06b7582600bd6c32431 tests/test_v351_reference_audio_ui.py 5003c5f5ce1a4b4c77deb47011431e4a15fe0cecaeb6d689e0d0878567c42f5a tests/test_v351_reference_audio.py 5f70cf8bd5248120ffcbe75ff3a54e23030fa6eb318ab0de6e0b08ee20e25a87 tests/test_v36_chunk_duration.py bf69d1ac3fc30f963b6fed6cbd661f273593904b03275467427a954fbdc0a03f tests/test_v36_masked_video_prefix.py 46531e6d505cc383b559994c2c74a1619d49715dc6fca838b1df29d575d9dea2 tests/test_v36_public_sampler.py +324c213aba761e8989a78eadc0cfdcc54d098f50ed1fe84a5ea7aec26f0dc595 tests/test_v37_guide_production.py +14ce0c7f78bcba9948e9e9930c4de5a8c7e8c453fcb6172066d43f593f7175ea tests/test_v37_guide_timeline.py +70b2413ad779bdde05bb131ef19db881c48e02004287d99626467303e23f8af6 tests/test_v37_refine_schedule.py 0dbe8a5f71c92f3523942343b40787104c8b96781461ba3ba82934a6bdbe5834 THIRD_PARTY_NOTICES.md f218e1a93c42467c6057c5c1d04d57cc82f6331b97ec9257e4e2dfb9c831876a timeline_video.py e5a84569953ee63b9625f4f2e3195ec368204fddcfc746564cfbd0e8449bb8e9 tools/p20_file_backed_tensor_poc.py -74a027ac89796e2862b84e98c210dde7f58c29f6e283f28a0e8c5336731412d6 tools/verify_runtime.py +71e5270fe0b0768c761a06eccdf61a600413802c17b6acf689647d09f1a93d67 tools/verify_runtime.py ffd61f3f31c9b6430e1169007ee906c8f5000eba63ee44e2976ad4f5f1112671 v2/__init__.py 2003902c87bba09cfa143f5a9e4248f3a78c0fb544449a75fd40ba2cacb35655 v2/context_diagnostics.py cde27db19b677e318cc4dfb4235be7a11429c19945f4083052a91fe117e74c82 v2/decoder.py 31012ec48a64c7467ad869c79982b7f8502c1785c33f51ee1b5727ce8b4243fb v2/diagnostics.py 8fe649acb25c36361c042807b828c545d8febf760f9ba0187fbec3e69698064e v2/h3_builder.py aea01a48a8c03a25ed97ea05e5b137f89e388832d1be7d38f2da2be3d1b9830b v2/motion.py -b65e97199e230b3ef46231a011896b6d6b9e63aa5a302a4c2e35bc4f969be238 v2/nodes.py +19249ea6b00be3a792f957aff85e2cc11422f8301f7391af1f7c269f33605314 v2/nodes.py dc2b901789e4b024dbcbc4024c63eb8cbc564d77003ce8c35c0584851ba6dfbd v2/prompts.py 4080f1875b958b316e8e76852c4be5527a6de5c71d604e7642d3098478eb4a36 v2/sampling.py 2fd811794c4cc0f2ce050250b80484876454926b9f20fce6af3a97d728e5acdf v2/seam_guard.py be0d8585fa57e0ccd6d02577bbc7299629e5bfe20e186747f571fccc98b67d7e v2/seam_types.py 12cfcc0c71ca087fe39a5ce2922959a62b2bb311bfe664f05c4480affce03708 v2/seeds.py -5f0830991cd9e59f4cf005daf8bc0071311b7f2ff9061d5f161000df8160e295 v2/sequence.py +0003f5c609c05dd8688d8eed640cf3fcaf95dbd40c3804fae1c957afbad3b132 v2/sequence.py 13213e7709fd02bb810af3c18e4cd7d010f8cdfb121a4b99866a9f2333331089 v2/session_io.py 3ea23dbce6fcd217b6e81235855479b9b16fed7a21693cf156f9014555c4fe13 v2/session.py 78c830cdf49034c6e3b2cd3da5914d5cfc5638eb63ec6dbd1bab13c50d6d4caf v3/__init__.py b3dc61503d35d9ef0a0dc7fed1c9b2fdc00fcb2072d4e39f64ae0826f9ec7dca v3/assembly_v35.py 7815230e0a9540bc2edeaf818e940b7a1fdd817fd217ba8a4f9cb21aaf6a308e v3/assembly.py 3f62fdb35e804f42d7cbf0828b4e87e69a2b99246c3f7467fe4fa698f1d803c9 v3/conditioning_bridge_nodes.py -432f4c7c1e8f350b1d06a572704cbf6a4d16605c389893e7c032d49829a4ba72 v3/driving_nodes.py +7ef3960e741a23ce3e34de56c8987104798e01475a57967da597d3bad6eab269 v3/driving_nodes.py 6cc7ed74666084c55beb9075304e92a9defafd81b9c6678239ca3859a08cddd7 v3/file_backed_buffer.py -039f03431c341aa0229f749699fd92272c77097e00b08649aded8328dfd83970 v3/hires_fix_nodes.py +cb53e1b104415032ec79b7e7aa1c99848e63da3eedaa251eeba102970e4172b5 v3/hires_fix_nodes.py 0858487e2b8c0060a856273ffc65d23165b2f253d183f506e27e419aea0da561 v3/latent_resize_nodes.py 5b8a54e67a608e757a505abc712effb33312636e3bb235835a485a506e80eeee v3/masked_continuation.py 85477badd85281cfb77582fdd5b34228a9f6b68376f1b7743af2ca7d4b55aa36 v3/memory_attribution.py -84321562a347c72bfdef2bbebae8b680cb4202d2a47d15b8d275950a309a8d4a v3/nodes.py +ef00dc62585a3581cc6641cb832abfc7dd01e02a45ebe8c438a463905052097d v3/nodes.py b7c4a35a5e73f528492bc6946b97b687c412f1d3f5f976c19d45c6dc20288c9a v3/pixel_vae_resize.py 34ea38c03b6322288d88fc8595e3655a7a7afddb51709142a954eb7349f71ac2 v3/plan.py -10eaab14eb8a70dea3345bf8bb20069d78ec5464aef5542a9a80f1ccfdeeb9b0 v3/refine_context.py +9076c47aa5145c81f34793d6c90410656065248f37d9990a92a6a4061b358811 v3/refine_context.py +43f33f989eb70ca87b916fc33267732a2be3dd4581fc72af17c53f840b53ca49 v3/refine_schedule.py 519586b1b3f48c73d329f7a2aaa8a1bfc6fe31ac2ecb64f2b1fdf9c19026001a v3/refine_sampling.py -da5edf3b4392c41e12ef73a0cd21799be42a327b18bd5a6989447b75163dcab1 v3/second_pass_nodes.py -23a412ce55797cbe6ea19c4379053855ff21bca233e3c373577225b761cc03d0 v3/second_pass.py +30cd7cd29cb804f9d5d85af49b1e4b9ebfa8bc7b485043ed745491dc1d99294b v3/second_pass_nodes.py +5483328d9c76802f7883e74fa766585ea13a62606f41ea0691f33c7ec846d485 v3/second_pass.py 4178dcfa442abdb06ce276e05bd7bcbaa6da28469ba5e57d3da3c663de4e4a9d v3/video_seam_v35.py 2f07ace1462644f0bee553827b3571535de4d0c2d9ef847bd9e0ca73a4eed5cb v3/video_seam.py -f983eaa646e3b2ee69e3be697fb073a5136869a2a99f0068d54de869572516f3 version.py -8eaaacd469c333d83bed0c83997014f256b2ca70fc2ba620c6a4a5648544b34e web/project_id.js +b5a8069934ed305688ebc07acda05a6d4d391365892cd6c9d6c9db651520f4cd version.py +cdcf166531835a5256fd9fcbb02d02efacfb669253cb3ea280d868cefd7e5874 web/project_id.js 0cf8d49bcb71b30437dc893f6218dc4cfb1cd244b647e4fbc2861dea2271a33a web/reference_audio_ui.js diff --git a/PACKAGE_INFO_JA.txt b/PACKAGE_INFO_JA.txt index dba1372..35be31b 100644 --- a/PACKAGE_INFO_JA.txt +++ b/PACKAGE_INFO_JA.txt @@ -1,7 +1,15 @@ -ComfyUI-H3-Continuum V3.6.1 +ComfyUI-H3-Continuum V3.7.0 MiniMax H3の5秒ChunkをAV latent contextで継続し、長尺映像として組み立てるComfyUIカスタムノードです。 +V3.7.0: +- H3 Continuum Sampler V3.7と、1枚のStill Image Guide用optional入力を追加 +- Conditioning AdapterでFirst/Last、Continuation context、Still Guide元画像をSecond Passのtarget解像度へ再構築 +- 内部RefineSchedule v1としてExternal/Full/Tail/Partialを定義し、既存SIGMAS socketとの互換性を維持 +- 704×704 Internal Tail 6と1152×1152 Guide再ConditioningのGPU Correctness GateをPASS +- Still Image GuideはCorrectness PASS、Experimental/Production HOLD。hard anchorによる急なtrajectory変化が起きる場合あり +- V3.6 Production初期値、旧Node ID、保存済みWorkflow、Core PackedLayout/RoPE、First Pass Audio passthroughを維持 + V3.6.1: - Timeline/List混在PromptへH3C-P105警告を追加し、Timelineではstandalone --- 行だけを除去 - Standard+Audio Continuity ONのFast 5/Strong 39/Autoを、実行開始時からReference Contextへ安全にfallback @@ -47,10 +55,13 @@ V3.5.0: - Assemble + Seam V3.5のRAM / Disk-backed / Auto Experimental: +- Still Image Guide V3.7(Correctness PASS、hard-anchor qualityはProduction HOLD) - Main Hi-Res Fix V3.5 - Main Hi-Res Fix 3x5 2x(RTX 5060 Ti 16 GiBではTerminal 77TでCUDA OOM) GPU受入済み: +- Internal Tail 6 704×704(外部Tail 6比Video SSIM 0.982936、decoded Audio PCM bit-exact) +- Still Guide元画像の1152×1152再Conditioning(Correctnessのみ。品質はProduction HOLD) - Main Hi-Res Fix 1x5、576から1152 - Hybrid FL2VA + Reference 1x5の統合Hi-Res FixとAdvanced Second Pass diff --git a/PACKAGE_VALIDATION.txt b/PACKAGE_VALIDATION.txt index 4e61816..270fe3c 100644 --- a/PACKAGE_VALIDATION.txt +++ b/PACKAGE_VALIDATION.txt @@ -1,6 +1,6 @@ -ComfyUI-H3-Continuum V3.6.1 package validation +ComfyUI-H3-Continuum V3.7.0 package validation -Status: V3.6.1 Production hotfix. Standard uses Masked AV for Balanced 22 with Audio Continuity, Reference Context fallback for Fast 5 / Strong 39 / Auto with Audio Continuity, and Masked Video when Audio Continuity is disabled. Advanced Compatibility retains the V3.5 Reference Context route. Run Storage identity is resolved before execution, Terminal Merge remains physical-group atomic, and all V3.5.3/V3.4 public node IDs and saved-workflow contracts remain available. Integrated Hi-Res Fix remains Experimental. +Status: V3.7.0 release candidate. Conditioning Adapter and the internal RefineSchedule v1 are correctness-accepted without changing V3.6 Production defaults or the existing SIGMAS socket. Still Image Guide positioning, source ownership, Terminal Merge, Run Storage identity, and target-resolution reconditioning are correctness-accepted, but hard-anchor quality remains Experimental / Production HOLD. All V3.6/V3.5.3/V3.4 public node IDs and saved-workflow contracts remain available. Required automated checks: - python -m compileall -q . @@ -8,6 +8,13 @@ Required automated checks: - python tools/verify_runtime.py --comfy-root Validated runtime paths include: +- H3 Continuum Sampler V3.7 required-input parity with V3.6 and one optional Still Image Guide input +- Conditioning Adapter reconstruction of First/Last, continuation context, and owned Still Guide sources at target geometry +- RefineSchedule v1 External / Full / Tail / Partial contracts with exact source schedule slicing +- Internal Tail 6 at 704x704: six evaluations, decoded Video SSIM 0.982936 versus the external Tail 6 baseline, and bit-exact decoded Audio PCM +- 1152x1152 Still Guide source reconditioning correctness with first-pass Audio passthrough preserved +- Still Guide single-IMAGE validation and explicit source-role priority at First/Last endpoint collisions +- V3.7 compact frontend parity for project identity, hidden widgets, Run Storage controls, queue normalization, diagnostics, and permanent Reference Audio sockets - V3.6.1 mixed Timeline/List Prompt diagnostics and fail-open normalization - V3.6.1 non-Balanced Audio Continuity fallback routing before Run Storage identity creation - V3.6.1 public-node Strong 39 / Audio Continuity fallback GPU Smoke on ComfyUI_W: 2x5 seconds, 576x576, 240 frames, 10.000-second video and audio @@ -39,8 +46,8 @@ Validated runtime paths include: - Audio Seam Auto - Video Seam Auto guarded transient and micro-flash correction -Latest verified automated result: 543 passed. +Latest verified automated result: 633 passed. -Hi-Res Fix and Auto 2 remain experimental. Main 3x5 2x is not accepted on the tested RTX 5060 Ti 16 GiB because the terminal 77T Second Pass group exceeded VRAM; longer Reference/Hybrid acceptance remains pending. +Still Image Guide, legacy Main Hi-Res Fix, and Auto 2 remain experimental. Still Image Guide hard-anchor transition quality is not Production-accepted. Main 3x5 2x is not accepted on the tested RTX 5060 Ti 16 GiB because the terminal 77T Second Pass group exceeded VRAM; longer Reference/Hybrid acceptance remains pending. Detailed evidence: docs/VALIDATION_RESULTS.md diff --git a/PROJECT_STATE.md b/PROJECT_STATE.md index 35e74b4..e7cfaff 100644 --- a/PROJECT_STATE.md +++ b/PROJECT_STATE.md @@ -10,7 +10,38 @@ - E2-8A Contract, E2-8B1 CPU/static validation, E2-8B2 external LBH GPU PoC, and E2-8C Second Pass GPU acceptance are formally PASS. The E2-8C CPU baseline is `260 passed`. - External LATENT nodes may discard custom dictionary metadata. Identically shaped group reordering therefore cannot be cryptographically detected; count, position, T, geometry, and audio-shape checks are enforced. -Updated: 2026-08-27 +Updated: 2026-08-28 + +## V3.7.0 Conditioning Adapter and RefineSchedule release candidate (2026-08-30) + +- Post-review frontend/input hardening is complete. `H3ContinuumSamplerV37` now follows the V3.6 compact frontend path for project identity, hidden internal widgets, Run Storage conditional controls, queue normalization, runtime diagnostics/debug/preview settings, and permanent Reference Audio label normalization. Still Image Guide now rejects every IMAGE batch except exactly one image at both public payload creation and defensive source preparation. +- Guide/First/Last endpoint collisions are regression-covered at physical frame `0` and `123`: the explicit Still Guide role marker takes priority over frame-number inference, so the owned Guide source is reencoded rather than the First/Last image. Reference Audio remains the accepted V3.5.1 permanent-socket design; the withdrawn frontend `Hidden / Show` widget was not restored. +- V3.7 has an internal, versioned `RefineSchedule` contract with `External`, `Full`, `Tail`, and `Partial` modes. `External` preserves the exact incoming SIGMAS tensor; Tail/Partial use exact source slices. The contract records source/effective sigma hashes, evaluation range, video-random/audio-locked noise policy, and is included in `second_pass_contract` identity without invalidating reusable First Pass Run Storage. +- Hi-Res Fix and Second Pass expose the schedule only as an optional Python-internal argument. Their public `INPUT_TYPES`, saved-workflow schema, V3.6/V3.5 nodes, Production defaults, and existing SIGMAS socket remain unchanged. Tail 10 and Tail 6 are reproducible from the same 10-evaluation source schedule. +- Still Image Guide now owns a CPU clone and SHA-256 identity of the original Guide source image. Only its owner physical group carries that source, and Second Pass rebuilds the marked Guide keyframe from the original image at target latent geometry; First/Last, Terminal Merge ownership, Core PackedLayout/RoPE construction, and First Pass audio bit-exact passthrough remain unchanged. +- GPU Correctness PASS: internal Tail 6 at 704x704 used the exact six-evaluation suffix. Under the same Sage path as the earlier external `SplitSigmas` Tail 6 baseline, decoded Video SSIM is `0.982936` and decoded PCM SHA-256 is identical; both are 120 frames / 5.000 seconds. The 1152x1152 Guide run encoded the First Image plus the original 1254x1254 Guide source to 72x72 latent geometry and completed without node/finite/geometry/AV errors. It remains low-motion/freeze-detected, consistent with the already-known hard-anchor quality limitation; Still Image Guide Production promotion therefore remains **HOLD**. +- Evidence: `D:\Codex\_test_results\ComfyUI-H3-Continuum\v37-pillars-gpu-gate-20260830`. Accepted snapshots: `pre-v37-refine-schedule-conditioning-approved-ecc72da-accepted-20260830_005156` (source, 641 files, zero SHA mismatch) and `pre-v37-refine-schedule-conditioning-runtime-w-approved-accepted-20260830_005202` (ComfyUI_W runtime, 353 files, zero mismatch). +- Final local Release Gate is `633 passed`; the 185-entry Manifest, Python/JavaScript syntax, `git diff --check`, ComfyUI_W runtime verifier, live V3.7/V3.6 registration, empty queue, and source/runtime SHA-256 equality for 25 release/Production files pass. ComfyUI_W restarted on 0.34.2 and reports `H3 Continuum 3.7.0 loaded`. Runtime logic and Production defaults are unchanged; commit, push, and release remain pending. + +## Sampling layout-validation measurement (2026-08-28) + +- Phase 1 Correctness PASS snapshots `phase1-correctness-pass-source-accepted-20260828_172802-ecc72da` and `phase1-correctness-pass-runtime-w-accepted-20260828_172802-ecc72da` are the formal optimization A/B baseline. +- Detailed Report now measures the existing `validate_native_continuity_layout()` call count, full-validation count, status counts, cumulative host wall including its existing device-to-host transfers/implicit synchronization, physical-group step contribution, and observable accelerator markers. It does not add `torch.cuda.synchronize()` and is inactive outside Detailed Report. Validation, Sampling, payload, schema, workflow, metadata, and public UI contracts are unchanged. +- The live ComfyUI_W / RTX 5060 Ti matrix used I2VA + Continuation, Compatibility Reference Context, 2x5 seconds, 384x384, 4 steps, fixed seed `361040`, and identical prompts. Sage and Sage+Sol each made `4` full calls (`1.000`/validated step) at `0.472` and `0.530 ms/step`; Sage+Spectrum and Sage+Sol+Spectrum each made `8` full calls (`2.000`/validated step) at `1.164` and `1.108 ms/step`. Every route reported zero validation failures. Global `--use-sage-attention` is not exposed through the inspected MODEL markers, so Sage route identity is taken from the controlled workflow graph and recorded backend launch arguments rather than inferred from `accelerator_summary()`. +- The representative Sage run used 576x576, 2x5 seconds, 20 steps, and the same seed. It made `20` full calls, `1.000` call/validated step, with `14.289 ms` cumulative validator wall (`0.714 ms/step`) versus `321.632848 s` measured Sampling and `382.055317 s` API elapsed. The validator therefore accounts for approximately `0.00444%` of Sampling and `0.00374%` of API time. +- Decision: do not implement a layout-validation cache or fast-path. Even eliminating the measured validator completely has a maximum representative saving of about `14 ms`; it is not a material Sampling optimization target. Spectrum doubles the validator call count in this matrix but remains about `1.1 ms/step`. No Sampling optimization was started. Evidence: `D:\Codex\_test_results\ComfyUI-H3-Continuum\layout-validation-profile-phase`. + +## V3.6.1 Run Storage correctness hotfix (unreleased, 2026-08-28) + +- Absent Last Frame hashes are canonicalized as `""` for every new chunk contract. Candidate revisions may bypass a hash mismatch only when both top-level Last Frame values are absent and normalizing the per-chunk `last_frame_hash` is the sole contract difference. +- This narrow path reuses legacy V3.6.1 final chunks stored with `"none"`; any real Last Frame or any other field difference remains incompatible. Run Storage schema and Sampling Contract versions are unchanged. FL2VA Long Terminal Merge atomicity remains unchanged. +- Compact UI now resets `Regenerate From = Auto` and `Variation Nonce = 0` whenever Run Storage is Off, including graph reload and final API serialization. Backend validation remains enabled. +- CPU/static regression expects normal no-Last-Frame I2VA 2→3 at 2/1, legacy `none` at 2/1, real Last Frame at 1/2, Terminal Merge at 1/2, exact resume at full reuse, and frontend Off/reload/queue normalization. Focused validation is `64 passed`; full validation is `565 passed` with only the known `pynvml` warning. +- Actual ComfyUI_W 0.34.2 / RTX 5060 Ti 16 GiB GPU regression copied only legacy revision `9c35c64b529a5c2c` into isolated test Run `run_95c2caec1a0846a09cf3570acb29e27f`. Prompt `bf619577-2057-4635-8fef-2537a40295c4` completed as `2 reused, 1 generated`, first regenerated Chunk 3, output `MiniMax_H3_00008_.mp4`. Exact 2-chunk resume prompt `e593b06a-9a37-4cc1-932c-0d13e55979c1` completed as `2 reused, 0 generated` with no regenerated chunk. +- G3 is repaired without changing Run Storage identity or Sampling behavior: the `FLF_STRATEGY` compatibility guard now applies only when Terminal Merge is actually enabled. Non-Terminal FL2VA therefore retains a prefix already validated by Run Storage; Terminal Merge still rejects a missing/mismatched strategy before its atomic pair handling. Focused validation is `63 passed`; full validation is `568 passed` with only the known `pynvml` warning. +- **Phase 1 GPU Acceptance G1-G6 is PASS.** G1 canonical no-Last-Frame I2VA 2→3 and G2 an isolated copy of actual legacy V3.6.1 `"none"` cache both completed at `2 reused / 1 generated`, Sampling 1. G3 real-Last-Frame non-Terminal FL2VA completed at `1 / 2`, Sampling 2, and no longer reports `FLF chunk contract changed`. G4 Terminal Merge remains `1 / 2` with one physical `77T Video / 433T Audio` Sampling call. G6 Run Storage Off completed with one Sampling call and no queue error. +- G5 fresh 3-chunk and matched 2→3 extension remain bit-exact: all three raw Video latent SHA-256 values, all three raw Audio latent SHA-256 values, decoded RGB24 SHA, decoded PCM SHA, 360 frames, and 480256 PCM samples/channel are identical. Evidence: `D:\Codex\_test_results\ComfyUI-H3-Continuum\phase1-gpu-acceptance-20260828\20260828_170034\gate_summary.json`. +- Verified pre-G3 snapshots are source `pre-g3-fl2va-prefix-correctness-source-accepted-20260828_165400-ecc72da` (632 files excluding `.git` and the inaccessible `.pytest_cache`) and ComfyUI_W runtime `pre-g3-fl2va-prefix-correctness-runtime-w-accepted-20260828_165400-ecc72da` (351 files excluding the inaccessible `.pytest_cache`), both with zero SHA-256 mismatch. Final accepted snapshots are `phase1-correctness-pass-source-accepted-20260828_172802-ecc72da` and `phase1-correctness-pass-runtime-w-accepted-20260828_172802-ecc72da`. All 180 Manifest entries, source/runtime SHA-256, runtime verifier, Python/JavaScript syntax, empty queue, and `git diff --check` pass. Public UI, metadata, workflows, Reference/Masked transport identity, schema/version, and optimizations are unchanged; Sampling hot-path optimization remains a separate later phase. ## V3.6.1 Continuity fallback hotfix (2026-08-27) diff --git a/README.md b/README.md index 5b07171..0dc899c 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,34 @@ -# ComfyUI-H3-Continuum 3.6.1 +# ComfyUI-H3-Continuum 3.7.0 Clip_95 Long-form MiniMax H3 video generation for ComfyUI with Continuum-aware Second Pass refinement, optional Hi-Res Fix, low-memory disk-backed assembly, restartable chunks, persistent references, and optional Spectrum interoperability. +## V3.7 High-Resolution Refinement Foundation + +V3.7 adds **H3 Continuum Sampler V3.7** and completes two foundations for resolution-changing Second Pass workflows without changing V3.6 Production defaults or the existing SIGMAS socket. + +### Conditioning survives a resolution change + +The Conditioning Adapter rebuilds First/Last images, continuation context, and an owned Still Image Guide at the target latent geometry. Physical-group ownership, Long Terminal Merge, Core PackedLayout/RoPE reconstruction, and first-pass Audio passthrough are preserved. Correctness gates passed at 704×704 and 1152×1152; larger canvases still require substantially more memory and processing time. + +### RefineSchedule gives refinement ranges explicit meaning + +The internal, versioned `RefineSchedule` contract supports `External`, `Full`, `Tail`, and `Partial`. `External` preserves the incoming SIGMAS tensor exactly, while `Tail` and `Partial` select exact ranges from the same source schedule. The accepted internal Tail 6 gate reproduced the six-evaluation suffix and preserved decoded Audio PCM bit-exact. This contract is an implementation foundation rather than a new public widget, and Production defaults remain unchanged. + +### Still Image Guide remains Experimental + +V3.7 can map one Still Image Guide from an absolute frame to its owning physical group and rebuild it from the original image during a high-resolution Second Pass. Its positioning, Terminal Merge ownership, Run Storage identity, and non-owner isolation passed correctness testing. Core Add Guide uses hard-anchor semantics, however, so a Guide can cause an abrupt trajectory change at the anchor and can redirect later motion. **Still Image Guide is Experimental and remains on Production HOLD.** It should not be treated as a smooth transition control. + ## V3.6.1 Maintenance Hotfix -V3.6.1 fixes two fail-open/compatibility issues without changing the accepted Balanced 22 Masked AV path. Mixed Timeline/List prompts now report `H3C-P105`; Timeline parsing ignores only standalone `---` lines, keeps existing uncovered-chunk fallback, and never stops generation because of prompt syntax. +V3.6.1 fixes focused fail-open/compatibility issues without changing the accepted Balanced 22 Masked AV path. Mixed Timeline/List prompts now report `H3C-P105`; Timeline parsing ignores only standalone `---` lines, keeps existing uncovered-chunk fallback, and never stops generation because of prompt syntax. With `Continuation Backend = Standard` and Audio Continuity enabled, `Balanced — 22 frames` continues to use Masked AV. `Fast — 5 frames`, `Strong — 39 frames`, and `Auto — conservative` now resolve to the accepted Reference Context transport before Run Storage identity is created. The selected UI values are not rewritten, and the status report states the resolved transport and reason. Standard with Audio Continuity disabled remains Masked Video; Compatibility remains Reference Context. +Run Storage now treats every absent Last Frame spelling as the same empty identity. A normal no-Last-Frame run can therefore extend from two to three chunks as `2 reused, 1 generated`, including narrowly compatible V3.6.1 caches whose former final chunk stored `none`. A real connected Last Frame and the Long Terminal Merge atomic pair remain strict. Turning Run Storage Off also resets the hidden Regenerate From and Variation Nonce values to `Auto` and `0` before queueing. + ## V3.6 Masked AV Continuation V3.6 adds **H3 Continuum Sampler V3.6**. Its Standard continuation backend places the previous finalized Video and Audio latent prefixes directly inside the next H3 target and protects them with Core noise masks. Unlike the V3.5 Reference Context route, it does not append the same prior frames as a separate Reference block, reducing the packed sequence processed by H3. @@ -65,7 +83,7 @@ Prompt/CLIP figures measure only the conditioning subphase, not total generation The measured Sage-only production baselines on the tested RTX 5060 Ti 16 GB / 64 GB system were 168.069 seconds for 1×5-second 576×576 T2VA and 379.765 seconds for 3×5-second 640×640 FL2VA Long Terminal Merge. These are configuration-specific baselines, not universal speed guarantees. Sampling remained the dominant cost; Continuum Assemble + Seam stayed below 1%. -> **V3.6.1 is the current release.** V3.5.3 remains the maintenance/compatibility baseline, and V3.5.2 remains the accepted Stabilization & Optimization baseline. Older Node IDs, backend socket keys, and saved-workflow loading remain intentionally supported. The withdrawn experimental Last Queued Seed override is not included. +> **V3.7.0 is the current release.** V3.6.1 remains the maintenance/compatibility baseline. Older Node IDs, backend socket keys, and saved-workflow loading remain intentionally supported. Production defaults are unchanged, and Still Image Guide remains Experimental. ## V3.5.1 Reference Audio & Compatibility Update @@ -351,7 +369,7 @@ Experimental Timeline Video and earlier timeline-audio paths are no longer publi ## Installation -Requires ComfyUI 0.32.0 or later. Package validation passed on ComfyUI 0.33.3, and the V3.6.1 GPU smoke test passed on ComfyUI 0.34.0; the latest ComfyUI release is not required. +Requires ComfyUI 0.32.0 or later. Package validation passed on ComfyUI 0.33.3, the V3.6.1 GPU smoke test passed on ComfyUI 0.34.0, and the V3.7 Conditioning/RefineSchedule correctness gates passed on ComfyUI 0.34.2; the latest ComfyUI release is not required. ### Updating an existing installation diff --git a/README_JA.md b/README_JA.md index 3efa7f1..36a4cb5 100644 --- a/README_JA.md +++ b/README_JA.md @@ -1,13 +1,31 @@ -# ComfyUI-H3-Continuum 3.6.1 +# ComfyUI-H3-Continuum 3.7.0 MiniMax H3を複数チャンクで連続生成し、直前チャンク末尾の**映像latent / 音声latentを直接**次チャンクへ継承するComfyUIカスタムノードです。チャンク間でVideo/Audio VAEのDecode→Encodeは行いません。 +## V3.7 高解像度Refinement基盤 + +V3.7では`H3 Continuum Sampler V3.7`を追加し、解像度を変更するSecond Passに必要な2つの基盤を完成させました。V3.6のProduction初期値と既存SIGMAS socketは変更していません。 + +### 解像度変更後もConditioningを再構築 + +Conditioning Adapterは、First/Last Image、Continuation context、Still Image Guideの元画像をtarget latent geometryに合わせて再構築します。Physical group ownership、Long Terminal Merge、Core側のPackedLayout/RoPE再構築、First Pass Audioのpassthroughは維持します。704×704と1152×1152のCorrectness GateはPASSしていますが、大きなcanvasほどmemory使用量と処理時間は増えます。 + +### RefineScheduleでRefinement範囲を明示 + +内部のversioned contractである`RefineSchedule`は、`External`、`Full`、`Tail`、`Partial`に対応します。`External`は入力SIGMAS tensorをそのまま維持し、`Tail`と`Partial`は同じsource scheduleから範囲を正確に切り出します。内部Tail 6 Gateでは、6 evaluationのsuffix再現とdecoded Audio PCMのbit-exact passthroughを確認しました。現時点では実装基盤として内部で扱い、公開widgetは追加していません。Production初期値も変更していません。 + +### Still Image GuideはExperimental + +V3.7では、Still Image Guide 1枚をabsolute frameからowner physical groupへ割り当て、高解像度Second Passでも元画像から再encodeできます。位置変換、Terminal Merge ownership、Run Storage identity、non-owner groupの非干渉はCorrectness PASSです。一方、Core Add Guideはhard anchorとして働くため、anchor位置で急なtrajectory変化が起き、その後のmotionも別の軌道へ分岐する場合があります。**Still Image GuideはExperimentalで、Production昇格はHOLDです。** 滑らかなtransition制御としては扱わないでください。 + ## V3.6.1 Maintenance Hotfix -V3.6.1は、受入済みBalanced 22 Masked AV経路を変更せず、2件のfail-open/互換性問題を修正します。Timeline/List記法が混在したPromptは`H3C-P105`を表示し、Timeline解析ではstandalone `---`行だけを除去します。未指定Chunkの既存fallbackとFixed Promptのfail-open動作は維持し、Prompt構文だけを理由に生成を停止しません。 +V3.6.1は、受入済みBalanced 22 Masked AV経路を変更せず、限定的なfail-open/互換性問題を修正します。Timeline/List記法が混在したPromptは`H3C-P105`を表示し、Timeline解析ではstandalone `---`行だけを除去します。未指定Chunkの既存fallbackとFixed Promptのfail-open動作は維持し、Prompt構文だけを理由に生成を停止しません。 `Continuation Backend = Standard`かつAudio Continuity ONでは、`Balanced — 22 frames`が引き続きMasked AVを使用します。`Fast — 5 frames`、`Strong — 39 frames`、`Auto — conservative`はRun Storage identity作成前に、受入済みReference Contextへ解決します。UIの選択値は書き換えず、status reportへ解決結果と理由を表示します。Audio Continuity OFFのStandardはMasked Video、Compatibilityは常にReference Contextのままです。 +Run Storageは、Last Frame未接続を表す値をすべて同じ空identityとして扱います。通常のLast Frameなし2チャンク生成を3チャンクへ延長すると、旧最終Chunkが`none`だったV3.6.1 cacheを含めて`2 reused, 1 generated`になります。実Last Frame接続時とLong Terminal Mergeのatomic pairは従来どおり厳密です。Run StorageをOffへ変更した場合は、Queue前にhiddenのRegenerate FromとVariation Nonceも`Auto`と`0`へ戻します。 + ## V3.6 Masked AV Continuation V3.6では`H3 Continuum Sampler V3.6`を追加しました。標準backendは、前Chunkで確定したVideo/Audio latent prefixを次のH3 Target内へ直接配置し、CoreのNoise Maskで保持します。V3.5のReference Context方式のように、同じ過去フレームを別Reference blockとして追加しないため、H3が処理するpacked sequenceを短縮できます。 @@ -62,7 +80,7 @@ Prompt/CLIPの数値はconditioning区間だけで、総生成時間ではあり RTX 5060 Ti 16 GB/RAM 64 GBの検証環境で測定したSage-only Production baselineは、576×576 T2VA 1×5秒が168.069秒、640×640 FL2VA Long Terminal Merge 3×5秒が379.765秒です。環境・設定固有の測定値であり、すべての環境に対する速度保証ではありません。Samplingが最大コストで、Continuum Assemble + Seamは1%未満でした。 -**V3.6.1が現在の公開版です。** V3.5.3はmaintenance/compatibility baseline、V3.5.2は受入済みStabilization & Optimization baselineとして維持します。旧Node ID、backend socket key、保存済みWorkflow読込は維持します。撤回済みの実験的Last Queued Seed overrideは含まれていません。 +**V3.7.0が現在の公開版です。** V3.6.1はmaintenance/compatibility baselineとして維持します。旧Node ID、backend socket key、保存済みWorkflow読込は維持し、Production初期値は変更していません。Still Image GuideはExperimentalです。 ## V3.5.1 Reference Audio/互換性更新 @@ -304,7 +322,7 @@ UNET -> SageAttention -> Sol-Attn -> LoRA -> Spectrum -> H3 Continuum Sampler ## インストール -ComfyUI 0.32.0以上が必要です。ComfyUI 0.33.3でパッケージ検証、0.34.0でV3.6.1 GPU Smoke検証済みで、ComfyUIの最新版は必須ではありません。 +ComfyUI 0.32.0以上が必要です。ComfyUI 0.33.3でパッケージ検証、0.34.0でV3.6.1 GPU Smoke、0.34.2でV3.7 Conditioning/RefineSchedule Correctness Gateを検証済みです。ComfyUIの最新版は必須ではありません。 ZIPを展開して、`ComfyUI-H3-Continuum`フォルダーを`ComfyUI/custom_nodes/`へ置き、ComfyUIを再起動します。 diff --git a/WORKLOG.md b/WORKLOG.md index f693f6e..2743246 100644 --- a/WORKLOG.md +++ b/WORKLOG.md @@ -1,5 +1,57 @@ # Work Log +## 2026-08-30 - V3.7.0 release metadata staging + +- Created verified pre-change snapshots of the authoritative source and ComfyUI_W runtime before release-only edits: `pre-v370-release-metadata-source-approved-20260830_022944` (227 files) and `pre-v370-release-metadata-runtime-w-approved-20260830_022944` (170 files), both at revision `ecc72dae9bad1fb909b8e2a003b8e4e5013f4a09` with zero SHA-256 mismatch. +- Unified `version.py`, `pyproject.toml`, and `metadata.ini` at `3.7.0`; updated English/Japanese release documentation, package information, validation text, and version assertions. The release message centers on the Conditioning Adapter and RefineSchedule foundations and states that Still Image Guide is Experimental / Production HOLD because of hard-anchor trajectory changes. +- Runtime generation logic, public Production defaults, existing workflows, and the untracked PDD workflow were not changed. Commit, push, and release remain pending until the final Release Gate is reviewed. +- Final local Release Gate passed: `633 passed`, 185 Manifest entries with zero missing/mismatch, Python/JavaScript syntax, `git diff --check`, runtime verification as `3.7.0`, live V3.7/V3.6 schema registration, empty queue, and exact source/runtime SHA-256 for 25 release/Production files. ComfyUI_W restarted as PID `8296`; evidence is `D:\Codex\_test_results\ComfyUI-H3-Continuum\v370-release-runtime-restart-20260830`. + +## 2026-08-30 - V3.7 frontend parity and Still Guide input hardening + +- Audited four findings from an older WIP ZIP against the current authoritative source. Confirmed and fixed the V37 compact-frontend class omission and the overly broad Still Guide IMAGE batch contract. The reported Guide/First/Last collision was already fixed by explicit Guide-role priority, and the Reference Audio `Hidden / Show` behavior was an obsolete pre-V3.5.1 expectation rather than a current regression. +- Added `H3ContinuumSamplerV37` to the same setup and queue-normalization paths as V3.6. Enforced exactly one Still Guide image during public payload creation and defensive source preparation. Added regressions for V37 frontend routing, batch sizes 0/2/5, defensive batch validation, and Guide collisions at physical frames 0 and 123. +- Accepted snapshots are `pre-v37-frontend-batch-contract-approved-accepted-20260830_020900` (source, 646 files, zero mismatch, revision `ecc72dae9bad1fb909b8e2a003b8e4e5013f4a09`) and `pre-v37-frontend-batch-contract-runtime-w-approved-accepted-20260830_020901` (ComfyUI_W runtime, 359 files, zero mismatch). Focused validation is `45 passed`; final full regression is `633 passed` with only the known `pynvml` warning. Runtime files were synchronized with exact SHA-256 equality. No GPU rerun, Production-default change, version change, commit, push, or release was performed. + +## 2026-08-30 - V3.7 Conditioning Adapter and RefineSchedule pillars + +- Added the internal schema-v1 `RefineSchedule` contract and integrated it into context-aware Second Pass without changing public node schemas or the existing SIGMAS socket. External/Full preserve the source tensor, Tail/Partial select exact source ranges, and Second Pass records schedule/hash/noise/audio policy in its contract. First Pass Run Storage reuse remains schedule-independent; schedule differences are identified at the Second Pass contract. +- Added original-source ownership for one Still Image Guide. The owner group alone retains a CPU source clone, source hash, absolute frame, and Guide schema/mode identity; target-resolution Second Pass conditioning reencodes the marked Guide from that source rather than resizing its First Pass latent fallback. +- GPU Gate PASS for correctness: 704x704 internal Tail 6 completed in six evaluations. A final same-Sage comparison against the earlier external `SplitSigmas` Tail 6 baseline produced Video SSIM `0.982936` and identical decoded PCM SHA-256 with matching 120-frame/5-second contracts. The 1152x1152 Guide + Tail 6 run reencoded the 1254x1254 Guide source to 72x72 latent geometry and completed with valid Video and 32 kHz stereo Audio. That Guide output was low-motion/freeze-detected, so the existing Still Image Guide hard-anchor quality and Production HOLD decisions are unchanged. +- Final regression is `626 passed`; compileall, Manifest hashes, runtime source equality, runtime verifier, and `git diff --check` pass. Evidence is under `D:\Codex\_test_results\ComfyUI-H3-Continuum\v37-pillars-gpu-gate-20260830`. No commit, push, release, Production-default change, or public workflow change was performed. + +## 2026-08-28 - Sampling layout-validation measurement and no-fast-path decision + +- Started from the formally accepted Phase 1 source/runtime snapshots and added Detailed-Report-only instrumentation around the existing full `validate_native_continuity_layout()` call. It records calls, full validations, statuses, wall time including existing D2H/implicit synchronization, physical groups, and per-step contribution without adding explicit CUDA synchronization. Normal diagnostics modes and generation semantics are untouched. +- Focused regression is `43 passed`; canonical full pytest is `570 passed`. All 180 Manifest hashes, changed-file syntax, runtime verifier, source/runtime identity, empty queue, and `git diff --check` pass. The first full-pytest attempt is excluded because its newly named `--basetemp` parent did not yet exist; it produced setup-only errors while 466 tests passed. Re-running after creating the parent produced the accepted all-PASS result. +- GPU matrix PASS on the existing ComfyUI_W Sage backend: 384x384, 2x5-second I2VA + Continuation, Compatibility Reference Context, 4 steps, fixed seed `361040`. Sage: 4 full calls / 1.889 ms total / 0.472 ms per step. Sage+Sol: 4 / 2.122 ms / 0.530 ms. Sage+Spectrum: 8 / 4.658 ms / 1.164 ms. Sage+Sol+Spectrum: 8 / 4.431 ms / 1.108 ms. All routes reported zero failures; no explicit `torch.cuda.synchronize()` was used. Because global `--use-sage-attention` has no observable MODEL marker, controlled prompt configuration plus the backend command line is the authoritative Sage route evidence. +- Representative 576x576 / 20-step Sage PASS: 20 calls, 20 full validations, zero failures, `14.289 ms` total and `0.714 ms/step`. Sampling was `321.632848 s` and API elapsed was `382.055317 s`, so the validator contributes only about `0.00444%` of Sampling and `0.00374%` of API time. +- Rejected the proposed validation cache/fast-path: its theoretical maximum representative gain is only about 14 ms, far below a material Production improvement. No Layout, Sampling, Terminal Merge, Run Storage, UI, metadata, workflow, schema/version, or transport behavior was optimized or changed. Evidence and the reusable live-API runner are under `D:\Codex\_test_results\ComfyUI-H3-Continuum\layout-validation-profile-phase`. Commit and push were not performed. + +## 2026-08-28 - G3 FL2VA prefix correctness repair and Phase 1 PASS + +- Scoped the G3 repair to the existing post-Run-Storage FL2VA guard. `FLF_STRATEGY` is now required only when Terminal Merge is active; a real-Last-Frame non-Terminal request keeps the compatible prefix already validated by Run Storage. A missing/mismatched Terminal strategy still discards the prefix, and terminal pair atomicity remains unchanged. +- Added three regressions for non-Terminal prefix retention, Terminal missing-strategy rejection, and matching-Terminal retention. Focused result is `63 passed`; canonical full result is `568 passed`. Manifest 180 entries, compileall except the known inaccessible `.pytest_cache` listing notice, runtime verifier, source/runtime SHA-256, Python/JavaScript syntax, empty queue, and `git diff --check` pass. +- Synchronized only `v2/sequence.py` to ComfyUI_W and restarted the same `127.0.0.6:8188` Sage backend with its recorded venv Python and arguments. Verified pre-change snapshots are `pre-g3-fl2va-prefix-correctness-source-accepted-20260828_165400-ecc72da` (632 files) and `pre-g3-fl2va-prefix-correctness-runtime-w-accepted-20260828_165400-ecc72da` (351 files), excluding only `.git` and the known inaccessible `.pytest_cache`, with zero mismatch. Final accepted snapshots are `phase1-correctness-pass-source-accepted-20260828_172802-ecc72da` and `phase1-correctness-pass-runtime-w-accepted-20260828_172802-ecc72da`. +- Formal GPU rerun PASS: G1 current canonical cache `2/1` with Sampling 1; G2 isolated actual legacy V3.6.1 `"none"` cache `2/1` with Sampling 1; G3 real-Last-Frame non-Terminal FL2VA `1/2` with Sampling 2 and no FLF-strategy reset; G4 Terminal Merge `1/2` with one physical `77T/433T` Sampling call; G6 Run Storage Off completed with one Sampling call and no queue error. +- G5 fresh 3-chunk versus matched 2→3 extension retained exact equality for all three Video/Audio latent SHA-256 values, decoded RGB24, decoded PCM, 360 frames, and 480256 PCM samples/channel. Phase 1 G1-G6 is formally **PASS**. Evidence: `D:\Codex\_test_results\ComfyUI-H3-Continuum\phase1-gpu-acceptance-20260828\20260828_170034\gate_summary.json`. +- Public UI, metadata, workflows, schema/version, Reference/Masked transport identity, optimization paths, commit, push, and release were not changed. + +## 2026-08-28 - Phase 1 Run Storage GPU Acceptance Gate + +- Ran G1-G6 against the already-running ComfyUI_W 0.34.2 backend at `127.0.0.6:8188` on RTX 5060 Ti 16 GiB. G1 current canonical I2VA 2→3 and G2 actual legacy V3.6.1 `"none"` cache both passed at `2 reused / 1 generated`; G4 FL2VA Terminal Merge passed at `1 / 2` with one `77T Video / 433T Audio` physical Sampling call; G6 Run Storage Off completed with one Sampling call and no hidden-value queue error. +- G5 compared a fresh 3-chunk run with the matched 2→3 extension at 576x576, 3x5 seconds, 20 steps, and Variation Nonce 1. All three raw Video latent SHA-256 values and all three Audio latent SHA-256 values matched. Decoded RGB24 and PCM hashes also matched; both outputs are 360 frames and 480256 decoded PCM samples/channel. +- G3 failed the required negative case: real-Last-Frame non-Terminal FL2VA expected `1 reused / 2 generated` but returned `0 / 3` with three Sampling calls. The old/new top-level Last Frame hash and Chunk 1 contract hash are identical, and the report first says `resuming after accepted chunk 1`; the subsequent existing FLF whole-sequence guard clears that prefix because a non-Terminal request has no saved terminal `flf_execution` semantic. +- Overall Phase 1 status is **HOLD**. The G3 finding is outside the absent-hash compatibility implementation and was not repaired because this gate explicitly prohibited Sampling and Terminal Merge contract changes. No optimization, post-acceptance snapshot, commit, push, or release was performed. Evidence: `D:\Codex\_test_results\ComfyUI-H3-Continuum\phase1-gpu-acceptance-20260828\20260828_154951\gate_summary.json`. + +## 2026-08-28 - V3.6.1 Run Storage correctness hotfix + +- Canonicalized absent Last Frame hashes to `""` and added a strictly limited V3.6.1 cache compatibility comparison: both top-level Last Frames must be absent, and the per-chunk `last_frame_hash` spelling must be the only contract difference. Real Last Frame changes and FL2VA Terminal Merge atomicity remain strict; no schema/version bump or optimization was included. +- Run Storage Off now resets hidden Regenerate From/Variation Nonce widgets to `Auto`/`0` on toggle and graph load, and defensively rewrites the queued API inputs. Backend validation remains unchanged. +- Added regressions for canonical/legacy no-Last-Frame 2→3 reuse, real Last Frame invalidation, unrelated-field rejection, exact resume, Terminal Merge 1/2 atomicity, and frontend toggle/reload/queue serialization. Focused result: `64 passed`; full result: `565 passed`; all 180 Manifest entries, Python/JS syntax, and `git diff --check` pass. +- Synchronized only `run_storage.py` and `web/project_id.js` to ComfyUI_W after accepted source/runtime snapshots `pre-phase1-correctness-hotfix-accepted-20260828_150500-ecc72da` and `pre-phase1-correctness-hotfix-comfyui-w-20260828_150659-ecc72da`. Runtime verifier and source/runtime hashes pass. The first restart attempt used the resolved base CPython and stopped before listening because venv dependencies were absent; the same backend was immediately restored through `ComfyUI_W\venv\Scripts\python.exe`, with no double-start or queued job. +- Actual ComfyUI_W 0.34.2 / RTX 5060 Ti GPU prompt `bf619577-2057-4635-8fef-2537a40295c4` extended an isolated copy of legacy revision `9c35c64b529a5c2c` from 2→3 chunks as `2 reused, 1 generated`; first regenerated Chunk 3, Sampling `169.256391s`, output `D:\output\video\comfy_video\video\MiniMax_H3_00008_.mp4`, and empty final queue. Exact 2-chunk prompt `e593b06a-9a37-4cc1-932c-0d13e55979c1` then passed as `2 reused, 0 generated`, first regenerated `none`, output `MiniMax_H3_00009_.mp4`. + ## 2026-08-28 - Current V3.6 sampler README images - Replaced the English README's obsolete V3.4 combined workflow screenshot with separate current `H3 Continuum Sampler V3.6` and `H3 Continuum Assemble + Seam V3.5` node images, and added the same images to the Japanese recommended-template section. diff --git a/guide_timeline.py b/guide_timeline.py new file mode 100644 index 0000000..0151222 --- /dev/null +++ b/guide_timeline.py @@ -0,0 +1,357 @@ +"""Frame-based Still Image Guide support for H3 Continuum V3.7.""" + +from __future__ import annotations + +from collections.abc import Mapping +from dataclasses import dataclass +import hashlib +import json +from typing import Any + +import torch + +from .continuation import clone_conditioning + + +GUIDE_SCHEMA_VERSION = 1 +GUIDE_MODE_STILL_IMAGE = "still_image" +GUIDE_TYPE = "H3_CONTINUUM_STILL_IMAGE_GUIDE" +MARK_STILL_IMAGE_GUIDE = "h3_continuum_still_image_guide_v1" + + +class GuideTargetError(ValueError): + pass + + +@dataclass(slots=True) +class StillImageGuideSource: + image: torch.Tensor + absolute_frame: int + contract: dict[str, Any] + source_image: torch.Tensor | None = None + + +@dataclass(slots=True) +class StillImageGuideAssets: + source: StillImageGuideSource + latent: torch.Tensor + + +def _resize_guide_image( + image: torch.Tensor, + width: int, + height: int, +) -> torch.Tensor: + # Lazy import keeps the V2 package initializer from cycling back through + # sequence.py while this standalone resolver module is being imported. + from .v2.h3_builder import resize_h3_image + + return resize_h3_image(image, width, height, "center") + + +def _strict_int(name: str, value: Any, *, minimum: int = 0) -> int: + if type(value) is not int or value < minimum: + raise GuideTargetError(f"{name} must be an integer >= {minimum}") + return value + + +def _tensor_fingerprint(tensor: torch.Tensor) -> str: + sample = tensor.detach().to("cpu").contiguous() + digest = hashlib.sha256() + digest.update(str(tuple(int(value) for value in sample.shape)).encode("ascii")) + digest.update(str(sample.dtype).encode("ascii")) + digest.update(sample.numpy().tobytes()) + return digest.hexdigest() + + +def _validate_still_image_tensor(image: Any) -> torch.Tensor: + if not torch.is_tensor(image) or image.ndim != 4 or image.shape[-1] < 3: + raise GuideTargetError( + "Still Image Guide input must be [B,H,W,C] with at least three channels" + ) + if int(image.shape[0]) != 1: + raise GuideTargetError("Still Image Guide input batch must be exactly 1") + return image + + +def make_still_image_guide(image: torch.Tensor, absolute_frame: int) -> dict[str, Any]: + """Create the small public guide payload without output-size assumptions.""" + + image = _validate_still_image_tensor(image) + return { + "schema_version": GUIDE_SCHEMA_VERSION, + "mode": GUIDE_MODE_STILL_IMAGE, + "absolute_frame": _strict_int("absolute_frame", absolute_frame), + "image": image, + } + + +def prepare_still_image_guide_source( + guide: Mapping[str, Any] | None, + *, + output_width: int, + output_height: int, +) -> StillImageGuideSource | None: + if guide is None: + return None + if not isinstance(guide, Mapping): + raise GuideTargetError("Still Image Guide must be a mapping") + if guide.get("schema_version") != GUIDE_SCHEMA_VERSION: + raise GuideTargetError( + f"unsupported Still Image Guide schema {guide.get('schema_version')!r}" + ) + if guide.get("mode") != GUIDE_MODE_STILL_IMAGE: + raise GuideTargetError(f"unsupported Guide mode {guide.get('mode')!r}") + absolute_frame = _strict_int("absolute_frame", guide.get("absolute_frame")) + image = _validate_still_image_tensor(guide.get("image")) + resized = _resize_guide_image( + image, + int(output_width), + int(output_height), + ) + contract = { + "schema_version": GUIDE_SCHEMA_VERSION, + "mode": GUIDE_MODE_STILL_IMAGE, + "absolute_frame": absolute_frame, + "image_sha256": _tensor_fingerprint(resized), + "source_image_sha256": _tensor_fingerprint(image), + "source_width": int(image.shape[-2]), + "source_height": int(image.shape[-3]), + "width": int(output_width), + "height": int(output_height), + } + return StillImageGuideSource( + image=resized, + absolute_frame=absolute_frame, + contract=contract, + source_image=image.detach().to(device="cpu").clone().contiguous(), + ) + + +def validate_guide_visible_range( + source: StillImageGuideSource | None, + *, + target_frames: int, +) -> None: + if source is None: + return + target_frames = _strict_int("target_frames", target_frames, minimum=1) + if source.absolute_frame >= target_frames: + raise GuideTargetError( + f"absolute_frame {source.absolute_frame} is outside visible range " + f"0-{target_frames - 1}" + ) + + +def encode_still_image_guide( + video_vae: Any, + source: StillImageGuideSource | None, +) -> StillImageGuideAssets | None: + if source is None: + return None + return StillImageGuideAssets(source=source, latent=video_vae.encode(source.image)) + + +def combine_guide_identity( + base_identity: str, + source: StillImageGuideSource | None, +) -> str: + """Scope resume identity by image, absolute frame, mode, and schema version.""" + + if source is None: + return str(base_identity) + payload = { + "base_identity": str(base_identity), + "guide": source.contract, + } + encoded = json.dumps(payload, sort_keys=True, separators=(",", ":")).encode( + "utf-8" + ) + return hashlib.sha256(encoded).hexdigest() + + +def _physical_groups(physical_plan: Mapping[str, Any]) -> list[dict[str, Any]]: + if not isinstance(physical_plan, Mapping): + raise GuideTargetError("physical_plan must be a mapping") + target_frames = _strict_int( + "physical_plan.target_frames", + physical_plan.get("target_frames"), + minimum=1, + ) + raw_groups = physical_plan.get("decode_groups") + if raw_groups is None: + raw_groups = physical_plan.get("chunks") + if not isinstance(raw_groups, list) or not raw_groups: + raise GuideTargetError("physical_plan has no physical groups") + + groups: list[dict[str, Any]] = [] + natural_cursor = 0 + for group_index, raw_group in enumerate(raw_groups): + if not isinstance(raw_group, Mapping): + raise GuideTargetError(f"physical group {group_index} is not a mapping") + frame_start = _strict_int( + f"physical group {group_index}.frame_start", + raw_group.get("frame_start", natural_cursor), + ) + net_frames = _strict_int( + f"physical group {group_index}.net_frames", + raw_group.get("net_frames"), + minimum=1, + ) + natural_frame_stop = _strict_int( + f"physical group {group_index}.frame_stop", + raw_group.get("frame_stop", frame_start + net_frames), + minimum=1, + ) + context_prefix_frames = _strict_int( + f"physical group {group_index}.trim_frames", + raw_group.get("trim_frames", raw_group.get("context_frames", 0)), + ) + physical_frames = _strict_int( + f"physical group {group_index}.total_frames", + raw_group.get("total_frames"), + minimum=1, + ) + if frame_start != natural_cursor: + raise GuideTargetError("physical group visible ranges are not contiguous") + if natural_frame_stop != frame_start + net_frames: + raise GuideTargetError("physical group visible range differs from net_frames") + if physical_frames - context_prefix_frames != net_frames: + raise GuideTargetError( + "physical group total/context frames differ from visible net frames" + ) + + visible_frame_stop = min(natural_frame_stop, target_frames) + if visible_frame_stop > frame_start: + logical_chunks = raw_group.get("logical_chunk_indices") + if logical_chunks is None: + logical_chunks = [raw_group.get("chunk_index", group_index + 1)] + groups.append( + { + "physical_group_index": group_index, + "logical_chunks": [int(value) for value in logical_chunks], + "global_visible_start": frame_start, + "global_visible_stop": visible_frame_stop, + "natural_frame_stop": natural_frame_stop, + "context_prefix_frames": context_prefix_frames, + "physical_frames": physical_frames, + "net_new_frames": net_frames, + "terminal_merged": bool(raw_group.get("terminal_merged", False)), + } + ) + natural_cursor = natural_frame_stop + + if not groups or groups[-1]["global_visible_stop"] != target_frames: + raise GuideTargetError("physical groups do not cover the visible target timeline") + return groups + + +def _resolved_target( + absolute_frame: int, + group: Mapping[str, Any], +) -> dict[str, Any] | None: + start = int(group["global_visible_start"]) + stop = int(group["global_visible_stop"]) + if not start <= absolute_frame < stop: + return None + local_visible_frame = absolute_frame - start + resolved_frame_index = int(group["context_prefix_frames"]) + local_visible_frame + if resolved_frame_index < int(group["context_prefix_frames"]): + raise GuideTargetError("resolved guide overlaps the continuation prefix") + if resolved_frame_index >= int(group["physical_frames"]): + raise GuideTargetError("resolved guide lies outside its physical group") + return { + **dict(group), + "absolute_frame": absolute_frame, + "local_visible_frame": local_visible_frame, + "resolved_frame_index": resolved_frame_index, + } + + +def resolve_guide_target( + absolute_frame: int, + physical_plan: Mapping[str, Any], +) -> dict[str, Any]: + """Resolve one visible absolute frame to Core MiniMaxH3AddGuide frame_idx.""" + + absolute_frame = _strict_int("absolute_frame", absolute_frame) + target_frames = _strict_int( + "physical_plan.target_frames", + physical_plan.get("target_frames") + if isinstance(physical_plan, Mapping) + else None, + minimum=1, + ) + if absolute_frame >= target_frames: + raise GuideTargetError( + f"absolute_frame {absolute_frame} is outside visible range 0-{target_frames - 1}" + ) + for group in _physical_groups(physical_plan): + result = _resolved_target(absolute_frame, group) + if result is not None: + return result + raise GuideTargetError("absolute frame was not owned by any physical group") + + +def resolve_guide_for_physical_group( + absolute_frame: int, + *, + target_frames: int, + physical_group_index: int, + logical_chunks: tuple[int, ...] | list[int], + global_visible_start: int, + natural_visible_stop: int, + context_prefix_frames: int, + physical_frames: int, + terminal_merged: bool, +) -> dict[str, Any] | None: + """Resolve against one authoritative runtime chunk/terminal physical group.""" + + absolute_frame = _strict_int("absolute_frame", absolute_frame) + target_frames = _strict_int("target_frames", target_frames, minimum=1) + if absolute_frame >= target_frames: + raise GuideTargetError( + f"absolute_frame {absolute_frame} is outside visible range 0-{target_frames - 1}" + ) + start = _strict_int("global_visible_start", global_visible_start) + natural_stop = _strict_int( + "natural_visible_stop", natural_visible_stop, minimum=1 + ) + context = _strict_int("context_prefix_frames", context_prefix_frames) + physical = _strict_int("physical_frames", physical_frames, minimum=1) + if natural_stop <= start or physical - context != natural_stop - start: + raise GuideTargetError("runtime physical group geometry is contradictory") + group = { + "physical_group_index": _strict_int( + "physical_group_index", physical_group_index + ), + "logical_chunks": [int(value) for value in logical_chunks], + "global_visible_start": start, + "global_visible_stop": min(natural_stop, target_frames), + "natural_frame_stop": natural_stop, + "context_prefix_frames": context, + "physical_frames": physical, + "net_new_frames": natural_stop - start, + "terminal_merged": bool(terminal_merged), + } + return _resolved_target(absolute_frame, group) + + +def attach_still_image_guide( + conditioning: list, + assets: StillImageGuideAssets | None, + target: Mapping[str, Any] | None, +) -> list: + if assets is None or target is None: + return conditioning + output = clone_conditioning(conditioning) + keyframe = { + "resolved_frame_index": int(target["resolved_frame_index"]), + "latent": assets.latent, + MARK_STILL_IMAGE_GUIDE: True, + } + for _, metadata in output: + keyframes = [dict(item) for item in (metadata.get("minimax_keyframes") or [])] + keyframes.append(dict(keyframe)) + metadata["minimax_keyframes"] = keyframes + return output diff --git a/metadata.ini b/metadata.ini index 8d631b9..89aa578 100644 --- a/metadata.ini +++ b/metadata.ini @@ -1,4 +1,4 @@ [project] name = H3 Continuum -version = 3.6.1 +version = 3.7.0 description = Native MiniMax H3 masked AV continuation, Second Pass, and disk-backed assembly. diff --git a/model_patch.py b/model_patch.py index 8cac302..dca70b4 100644 --- a/model_patch.py +++ b/model_patch.py @@ -4,6 +4,7 @@ from __future__ import annotations import logging +import time from typing import Any, Callable from .compatibility import CompatibilityError, ensure_native_h3_base_model @@ -23,7 +24,142 @@ from .layout_adapter import ( ) -def _wrapper_factory(*, strict: bool, debug: bool) -> Callable[..., Any]: +class LayoutValidationProfiler: + """Detailed-only wall-time accounting for the current full validator.""" + + def __init__(self, *, route_markers: str): + self.route_markers = str(route_markers) + self.validation_calls = 0 + self.full_validation_count = 0 + self.cumulative_wall_seconds = 0.0 + self.status_counts: dict[str, int] = {} + self.failed_validation_count = 0 + self.sampled_physical_groups = 0 + self.sampling_steps_total = 0 + self.validated_sampling_steps = 0 + self._groups: list[dict[str, Any]] = [] + + def record_validation( + self, + result: dict[str, Any] | None, + wall_seconds: float, + *, + full_validation: bool, + failed: bool = False, + ) -> None: + self.validation_calls += 1 + self.full_validation_count += int(bool(full_validation)) + self.cumulative_wall_seconds += max(0.0, float(wall_seconds)) + if failed: + self.failed_validation_count += 1 + return + status = str((result or {}).get("status", "unknown")) + self.status_counts[status] = self.status_counts.get(status, 0) + 1 + + def begin_sampling_group( + self, + *, + physical_group: int, + logical_chunks: tuple[int, ...], + sampling_steps: int, + ) -> dict[str, Any]: + return { + "physical_group": int(physical_group), + "logical_chunks": tuple(int(value) for value in logical_chunks), + "sampling_steps": max(0, int(sampling_steps)), + "validation_calls": self.validation_calls, + "full_validation_count": self.full_validation_count, + "cumulative_wall_seconds": self.cumulative_wall_seconds, + } + + def finish_sampling_group(self, token: dict[str, Any]) -> None: + sampling_steps = int(token["sampling_steps"]) + validation_calls = self.validation_calls - int(token["validation_calls"]) + full_validations = self.full_validation_count - int( + token["full_validation_count"] + ) + wall_seconds = self.cumulative_wall_seconds - float( + token["cumulative_wall_seconds"] + ) + self.sampled_physical_groups += 1 + self.sampling_steps_total += sampling_steps + if validation_calls: + self.validated_sampling_steps += sampling_steps + self._groups.append( + { + "physical_group": int(token["physical_group"]), + "logical_chunks": tuple(token["logical_chunks"]), + "sampling_steps": sampling_steps, + "validation_calls": validation_calls, + "full_validation_count": full_validations, + "wall_seconds": max(0.0, wall_seconds), + } + ) + + def report_lines(self) -> list[str]: + validated_steps = self.validated_sampling_steps + calls_per_step = ( + self.validation_calls / validated_steps if validated_steps else 0.0 + ) + wall_ms_per_step = ( + self.cumulative_wall_seconds * 1000.0 / validated_steps + if validated_steps + else 0.0 + ) + mean_ms_per_call = ( + self.cumulative_wall_seconds * 1000.0 / self.validation_calls + if self.validation_calls + else 0.0 + ) + status_text = ",".join( + f"{name}={count}" for name, count in sorted(self.status_counts.items()) + ) or "none" + route_markers = self.route_markers.replace(";", " |") + lines = [ + "Layout validation profile [V3.6]: " + f"route_markers={route_markers}; " + f"validation_calls={self.validation_calls}; " + f"full_validation_count={self.full_validation_count}; " + f"failed_validation_count={self.failed_validation_count}; " + f"statuses={status_text}; " + "cumulative_wall_including_existing_device_to_host_sync=" + f"{self.cumulative_wall_seconds:.6f}s; " + f"sampled_physical_groups={self.sampled_physical_groups}; " + f"sampling_steps_total={self.sampling_steps_total}; " + f"validated_sampling_steps={validated_steps}; " + f"calls_per_validated_step={calls_per_step:.3f}; " + f"wall_per_validated_step={wall_ms_per_step:.3f}ms; " + f"mean_wall_per_call={mean_ms_per_call:.3f}ms; " + "explicit_cuda_synchronize=not_used." + ] + for group in self._groups: + group_steps = int(group["sampling_steps"]) + group_calls = int(group["validation_calls"]) + group_wall = float(group["wall_seconds"]) + group_calls_per_step = group_calls / group_steps if group_steps else 0.0 + group_wall_per_step = ( + group_wall * 1000.0 / group_steps if group_steps else 0.0 + ) + lines.append( + "Layout validation group [V3.6]: " + f"physical_group={group['physical_group']}; " + f"logical_chunks={list(group['logical_chunks'])}; " + f"sampling_steps={group_steps}; " + f"validation_calls={group_calls}; " + f"full_validation_count={group['full_validation_count']}; " + f"cumulative_wall={group_wall:.6f}s; " + f"calls_per_step={group_calls_per_step:.3f}; " + f"wall_per_step={group_wall_per_step:.3f}ms." + ) + return lines + + +def _wrapper_factory( + *, + strict: bool, + debug: bool, + validation_profiler: LayoutValidationProfiler | None = None, +) -> Callable[..., Any]: branch_baselines: dict[tuple[Any, ...], tuple[Any, ...]] = {} def apply_model_wrapper(executor, *args, **kwargs): @@ -49,13 +185,34 @@ def _wrapper_factory(*, strict: bool, debug: bool) -> Callable[..., Any]: if has_continuum: patch_layout_in_place(patched_payload, strict=True, debug=debug) transformer_options = kwargs.get("transformer_options") - validate_native_continuity_layout( - patched_payload, - transformer_options=( - transformer_options if isinstance(transformer_options, dict) else {} - ), - branch_baselines=branch_baselines, + validation_started = ( + time.perf_counter() if validation_profiler is not None else None ) + try: + validation_result = validate_native_continuity_layout( + patched_payload, + transformer_options=( + transformer_options + if isinstance(transformer_options, dict) + else {} + ), + branch_baselines=branch_baselines, + ) + except Exception: + if validation_profiler is not None and validation_started is not None: + validation_profiler.record_validation( + None, + time.perf_counter() - validation_started, + full_validation=True, + failed=True, + ) + raise + if validation_profiler is not None and validation_started is not None: + validation_profiler.record_validation( + validation_result, + time.perf_counter() - validation_started, + full_validation=True, + ) input_x = args[0] if args else None materialize_continuum_latents(patched_payload, input_x, debug=debug) # ComfyUI Core 0.33.1 replaces keyframe condition latents with @@ -70,7 +227,13 @@ def _wrapper_factory(*, strict: bool, debug: bool) -> Callable[..., Any]: return apply_model_wrapper -def configure_continuum_model(model: Any, *, strict: bool, debug: bool): +def configure_continuum_model( + model: Any, + *, + strict: bool, + debug: bool, + validation_profiler: LayoutValidationProfiler | None = None, +): try: from comfy.patcher_extension import WrappersMP except Exception as exc: # pragma: no cover @@ -97,7 +260,11 @@ def configure_continuum_model(model: Any, *, strict: bool, debug: bool): patched.add_wrapper_with_key( WrappersMP.APPLY_MODEL, MODEL_WRAPPER_KEY, - _wrapper_factory(strict=bool(strict), debug=bool(debug)), + _wrapper_factory( + strict=bool(strict), + debug=bool(debug), + validation_profiler=validation_profiler, + ), ) model_options = dict(getattr(patched, "model_options", None) or {}) join_options = dict(model_options.get("h3_continuum_join") or {}) @@ -106,13 +273,24 @@ def configure_continuum_model(model: Any, *, strict: bool, debug: bool): patched.model_options = model_options return patched -def patch_model(model: Any, *, strict: bool, debug: bool): +def patch_model( + model: Any, + *, + strict: bool, + debug: bool, + validation_profiler: LayoutValidationProfiler | None = None, +): """Clone once, then install the Continuum wrapper on that clone.""" if not hasattr(model, "clone"): raise RuntimeError( "MODEL lacks the wrapper API required by H3 Continuum Join: clone" ) - return configure_continuum_model(model.clone(), strict=strict, debug=debug) + return configure_continuum_model( + model.clone(), + strict=strict, + debug=debug, + validation_profiler=validation_profiler, + ) def continuum_interop_request(*, chunk_index: int, context_frames: int) -> dict[str, Any]: return { @@ -131,6 +309,7 @@ def clone_model_for_chunk( debug: bool, chunk_index: int, context_frames: int | None, + validation_profiler: LayoutValidationProfiler | None = None, ): """Create a call-local MODEL and attach an optional read-only Spectrum hint.""" if not hasattr(model, "clone"): @@ -139,7 +318,10 @@ def clone_model_for_chunk( ) chunk_model = model.clone() configure_continuum_model( - chunk_model, strict=bool(strict), debug=bool(debug) + chunk_model, + strict=bool(strict), + debug=bool(debug), + validation_profiler=validation_profiler, ) if debug: parent = getattr(chunk_model, "parent", None) diff --git a/nodes.py b/nodes.py index f4706eb..ddc3fba 100644 --- a/nodes.py +++ b/nodes.py @@ -423,6 +423,8 @@ _primary_node_ids = { "H3ContinuumSamplerV34", "H3ContinuumSamplerV35", "H3ContinuumSamplerV36", + "H3ContinuumStillImageGuideV37", + "H3ContinuumSamplerV37", "H3ContinuumAssembleSeamV34", "H3ContinuumAssembleSeamV35", "H3ContinuumHiResFixV35", diff --git a/pyproject.toml b/pyproject.toml index 2ad3cdc..16e80d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "comfyui-h3-continuum" -version = "3.6.1" +version = "3.7.0" description = "Integrated N-chunk continuation for ComfyUI native MiniMax H3 video and audio" readme = "README.md" requires-python = ">=3.10" diff --git a/run_storage.py b/run_storage.py index 20fbb70..a26c0d8 100644 --- a/run_storage.py +++ b/run_storage.py @@ -63,6 +63,15 @@ def _hash(value: Any) -> str: return hashlib.sha256(_canonical(value).encode("utf-8")).hexdigest() +def _canonical_optional_hash(value: Any) -> str: + """Normalize legacy absent-value spellings without changing real hashes.""" + + if value is None: + return "" + text = str(value).strip() + return "" if text.lower() in {"", "none", "null"} else text + + def sanitize_run_name(value: str) -> str: name = str(value) if not name or name != name.strip() or len(name) > 96: @@ -512,6 +521,9 @@ def _apply_nonce_contract( contract: dict[str, Any], *, requested_nonce: int, effective_nonce: int, ) -> dict[str, Any]: result = dict(contract) + result["last_frame_hash"] = _canonical_optional_hash( + result.get("last_frame_hash") + ) boundary = int(result["reroll_from_chunk"]) if boundary <= 0: mode = "inactive" @@ -553,6 +565,45 @@ def _apply_nonce_contract( return result +def _legacy_absent_last_frame_compatible( + *, + stored_contract: dict[str, Any], + current_contract: dict[str, Any], + position: int, + stored_hash: str, + current_hash: str, +) -> bool: + """Accept only the V3.6.1 ``none`` versus ``""`` Last Frame mismatch.""" + + if not isinstance(stored_contract, dict) or not isinstance(current_contract, dict): + return False + if _canonical_optional_hash(stored_contract.get("last_frame_hash")): + return False + if _canonical_optional_hash(current_contract.get("last_frame_hash")): + return False + stored_chunks = stored_contract.get("chunk_contracts") or [] + current_chunks = current_contract.get("chunk_contracts") or [] + if position >= len(stored_chunks) or position >= len(current_chunks): + return False + stored_chunk = stored_chunks[position] + current_chunk = current_chunks[position] + if not isinstance(stored_chunk, dict) or not isinstance(current_chunk, dict): + return False + if _hash(stored_chunk) != str(stored_hash): + return False + if _hash(current_chunk) != str(current_hash): + return False + stored_normalized = dict(stored_chunk) + current_normalized = dict(current_chunk) + stored_normalized["last_frame_hash"] = _canonical_optional_hash( + stored_normalized.get("last_frame_hash") + ) + current_normalized["last_frame_hash"] = _canonical_optional_hash( + current_normalized.get("last_frame_hash") + ) + return stored_normalized == current_normalized + + def build_sampling_contract( *, model: Any, model_fingerprint_value: str, clip: Any, video_vae: Any, sampler: Any, @@ -571,8 +622,10 @@ def build_sampling_contract( driving_audio_vae: Any = None, reference_video_contract: dict[str, Any] | None = None, timeline_video_contract: dict[str, Any] | None = None, + guide_contract: dict[str, Any] | None = None, execution_semantics: dict[str, Any] | None = None, ) -> tuple[dict[str, Any], bool, list[str]]: + last_frame_hash = _canonical_optional_hash(last_frame_hash) model_value, model_safe = _model_signature(model, model_fingerprint_value) clip_value, clip_safe = _clip_signature(clip) has_first = str(first_frame_hash).lower() not in {"", "none", "null"} @@ -594,6 +647,7 @@ def build_sampling_contract( conditioning_mode_uses_video_vae(conditioning_mode) or reference_video_contract is not None or timeline_video_contract is not None + or guide_contract is not None ) if uses_video_vae: video_vae_value, video_vae_safe = _video_vae_signature( @@ -693,6 +747,8 @@ def build_sampling_contract( global_contract["driving_audio_vae"] = driving_audio_vae_value if reference_video_contract is not None: global_contract["reference_video"] = dict(reference_video_contract) + if guide_contract is not None: + global_contract["guide"] = dict(guide_contract) timeline_chunk_contracts = [] if timeline_video_contract is not None: timeline_value = dict(timeline_video_contract) @@ -970,11 +1026,23 @@ class RunStorageController: return validate_chunk_entry(entry) def _valid_prefix(self, manifest: dict[str, Any], hashes: list[str]) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]: - stored = list((manifest.get("contract") or {}).get("chunk_contract_hashes") or []) + stored_contract = manifest.get("contract") or {} + stored = list(stored_contract.get("chunk_contract_hashes") or []) records = list(manifest.get("chunks") or []) entries, accepted = [], [] for position, current in enumerate(hashes): - if position >= len(stored) or stored[position] != current: + if position >= len(stored): + break + compatible_absent_last_frame = False + if stored[position] != current: + compatible_absent_last_frame = _legacy_absent_last_frame_compatible( + stored_contract=stored_contract, + current_contract=self.contract or {}, + position=position, + stored_hash=stored[position], + current_hash=current, + ) + if stored[position] != current and not compatible_absent_last_frame: break if position >= len(records) or int(records[position].get("sequence_index", -1)) != position: break @@ -985,6 +1053,11 @@ class RunStorageController: break entries.append(entry) accepted.append(records[position]) + if compatible_absent_last_frame: + self.notes.append( + f"stored chunk {position + 1} reused through V3.6.1 absent " + "Last Frame compatibility" + ) return entries, accepted def _resolve_effective_nonce( @@ -1039,6 +1112,7 @@ class RunStorageController: driving_audio_vae: Any = None, reference_video_contract: dict[str, Any] | None = None, timeline_video_contract: dict[str, Any] | None = None, + guide_contract: dict[str, Any] | None = None, execution_semantics: dict[str, Any] | None = None, ) -> dict[str, Any] | None: if existing_session is not None: @@ -1052,6 +1126,7 @@ class RunStorageController: conditioning_mode_uses_video_vae(str(conditioning_mode)) or reference_video_contract is not None or timeline_video_contract is not None + or guide_contract is not None ), require_reference_audio_vae=reference_audio_contract is not None, require_audio_vae=driving_audio_contract is not None, @@ -1077,6 +1152,7 @@ class RunStorageController: driving_audio_vae=driving_audio_vae, reference_video_contract=reference_video_contract, timeline_video_contract=timeline_video_contract, + guide_contract=guide_contract, execution_semantics=execution_semantics, ) effective_nonce, nonce_decision = self._resolve_effective_nonce( diff --git a/tests/test_model_patch.py b/tests/test_model_patch.py index a1de270..6988c3c 100644 --- a/tests/test_model_patch.py +++ b/tests/test_model_patch.py @@ -12,6 +12,7 @@ from ComfyUI_H3_Continuum_Join.constants import ( MARK_VIDEO_CONTEXT, ) from ComfyUI_H3_Continuum_Join.model_patch import ( + LayoutValidationProfiler, _wrapper_factory, clone_model_for_chunk, patch_model, @@ -135,6 +136,75 @@ def test_apply_model_wrapper_fails_when_actual_topology_changes(): wrapper(Executor(), torch.zeros(1), transformer_options=options, minimax_payload=payload) +def test_layout_validation_profiler_records_full_calls_groups_and_step_contribution(): + profiler = LayoutValidationProfiler(route_markers="Sage + Sol + Spectrum") + token = profiler.begin_sampling_group( + physical_group=2, + logical_chunks=(2,), + sampling_steps=20, + ) + profiler.record_validation( + {"status": "baseline_created"}, + 0.01, + full_validation=True, + ) + profiler.record_validation( + {"status": "baseline_matched"}, + 0.03, + full_validation=True, + ) + profiler.finish_sampling_group(token) + + report = "\n".join(profiler.report_lines()) + assert "route_markers=Sage + Sol + Spectrum" in report + assert "validation_calls=2" in report + assert "full_validation_count=2" in report + assert "cumulative_wall_including_existing_device_to_host_sync=0.040000s" in report + assert "sampling_steps_total=20" in report + assert "validated_sampling_steps=20" in report + assert "calls_per_validated_step=0.100" in report + assert "wall_per_validated_step=2.000ms" in report + assert "physical_group=2" in report + + +def test_apply_model_wrapper_reports_validator_status_without_changing_payload(): + video = torch.zeros(1, 24, 1, 1, 1) + audio = torch.zeros(1, 32, 2, 1) + ref = { + "kind": "video_audio", + "latent_t": 1, + "latent_h": 1, + "latent_w": 1, + "ref_audio_t": 1, + "latent": video, + "audio_latent": audio, + MARK_VIDEO_CONTEXT: True, + MARK_CONTEXT_FRAMES: 1, + MARK_AUDIO_CONTEXT: True, + MARK_AUDIO_END_FRAME: 1.0, + MARK_AUDIO_OVERHANG: 0.0, + } + payload = {"layout": _layout(), "keyframes": [], "refs": [ref]} + profiler = LayoutValidationProfiler(route_markers="Sage") + wrapper = _wrapper_factory( + strict=True, + debug=False, + validation_profiler=profiler, + ) + + first = wrapper(Executor(), torch.zeros(1), minimax_payload=payload) + second = wrapper(Executor(), torch.zeros(1), minimax_payload=payload) + + assert first["cond_video_latents"] == [video] + assert second["cond_audio_latents"] == [audio] + assert profiler.validation_calls == 2 + assert profiler.full_validation_count == 2 + assert profiler.status_counts == { + "baseline_created": 1, + "baseline_matched": 1, + } + + class FakeModelPatcher: def __init__(self): inner_type = type( diff --git a/tests/test_release_metadata.py b/tests/test_release_metadata.py index 015a7b4..774f5d3 100644 --- a/tests/test_release_metadata.py +++ b/tests/test_release_metadata.py @@ -6,7 +6,7 @@ import tomllib ROOT = Path(__file__).resolve().parents[1] -EXPECTED_VERSION = "3.6.1" +EXPECTED_VERSION = "3.7.0" def test_v35_release_metadata_is_consistent(): diff --git a/tests/test_v217_stable_facade.py b/tests/test_v217_stable_facade.py index ea7ad62..75c1e50 100644 --- a/tests/test_v217_stable_facade.py +++ b/tests/test_v217_stable_facade.py @@ -145,4 +145,4 @@ def test_v217_result_pack_expands_legacy_outputs(): def test_v217_has_no_frontend_display_controller(): assert not (ROOT / "web" / "h3_continuum_v2.js").exists() version_source = (ROOT / "version.py").read_text(encoding="utf-8") - assert 'PACKAGE_VERSION = "3.6.1"' in version_source + assert 'PACKAGE_VERSION = "3.7.0"' in version_source diff --git a/tests/test_v2_prompts.py b/tests/test_v2_prompts.py index de78ec0..5fd108a 100644 --- a/tests/test_v2_prompts.py +++ b/tests/test_v2_prompts.py @@ -16,6 +16,7 @@ from ComfyUI_H3_Continuum_Join.v2.prompts import ( detect_prompt_mode, make_prompt_plan, parse_sparse_prompt_overrides, + prompt_hash, prompt_plan_report, validate_sparse_prompt_overrides, validate_prompt_plan, @@ -30,6 +31,140 @@ def test_fixed_prompt_repeats_without_mutation(): assert validate_prompt_plan(plan) is plan +def test_prompt_transparency_t1_fixed_passthrough(): + script = "\n".join( + [ + "Hello world", + "embedding:character_style", + "", + "", + "日本語 text:01", + "symbols +=[]{}()", + ] + ) + plan = make_prompt_plan( + mode=PROMPT_MODE_FIXED, + script=script, + chunks=2, + chunk_seconds=5, + ) + assert plan["prompts"] == [script, script] + + +def test_prompt_transparency_t2_list_passthrough(): + plan = make_prompt_plan( + mode=PROMPT_MODE_LIST, + script=( + "first dialogue\n" + "embedding:style_a\n" + "---\n" + "second dialogue\n" + "" + ), + chunks=2, + chunk_seconds=5, + ) + assert plan["prompts"] == [ + "first dialogue\nembedding:style_a", + "second dialogue\n", + ] + + +def test_prompt_transparency_t3_timeline_passthrough(): + plan = make_prompt_plan( + mode=PROMPT_MODE_TIMELINE, + script=( + "Shared \n" + "embedding:global_style\n\n" + "[0-5s]\n" + "first line\n\n" + "[5-10s]\n" + "second line\n" + "" + ), + chunks=2, + chunk_seconds=5, + ) + assert plan["prompts"] == [ + "Shared \nembedding:global_style\n\nfirst line", + "Shared \nembedding:global_style\n\nsecond line\n", + ] + + +def test_prompt_transparency_t4_timeline_preamble_passthrough(): + preamble = "embedding:character_x\n\nshared instruction" + plan = make_prompt_plan( + mode=PROMPT_MODE_TIMELINE, + script=f"{preamble}\n\n[Chunk 1]\nfirst\n[Chunk 2]\nsecond", + chunks=2, + chunk_seconds=5, + ) + assert plan["prompts"] == [ + f"{preamble}\n\nfirst", + f"{preamble}\n\nsecond", + ] + + +def test_prompt_transparency_t5_external_override_passthrough_and_rehash(): + plan = make_prompt_plan( + mode=PROMPT_MODE_FIXED, + script="base", + chunks=2, + chunk_seconds=5, + ) + override = "override dialogue\nembedding:new_style\n" + updated = apply_prompt_overrides(plan, [None, override]) + assert updated["prompts"] == ["base", override] + assert updated["hashes"][0] == plan["hashes"][0] + assert updated["hashes"][1] == prompt_hash(override) + assert updated["hashes"][1] != plan["hashes"][1] + + +def test_prompt_transparency_t6_invalid_timeline_fallback_passthrough(): + script = "[0 to 5s]\nHello\nembedding:style\n" + plan = make_prompt_plan( + mode=PROMPT_MODE_TIMELINE, + script=script, + chunks=2, + chunk_seconds=5, + ) + assert plan["mode"] == PROMPT_MODE_FIXED + assert plan["prompts"] == [script, script] + assert plan["diagnostics"][0]["code"] == "H3C-P100" + + +@pytest.mark.parametrize( + ("left", "right"), + [ + ("Hello", "hello"), + ("embedding:a", "embedding:b"), + ("", ""), + ], +) +def test_prompt_transparency_t7_hash_sensitivity(left, right): + assert prompt_hash(left) == prompt_hash(left) + assert prompt_hash(left) != prompt_hash(right) + + +def test_prompt_transparency_t8_unknown_future_syntax_is_literal(): + script = "\n".join( + [ + '', + "", + "[[SPECIAL_X]]", + "token://future/value", + ] + ) + plan = make_prompt_plan( + mode=PROMPT_MODE_FIXED, + script=script, + chunks=2, + chunk_seconds=5, + ) + assert plan["prompts"] == [script, script] + assert "diagnostics" not in plan + + @pytest.mark.parametrize( ("script", "expected"), [ diff --git a/tests/test_v2_terminal_merge.py b/tests/test_v2_terminal_merge.py index c0d28f2..9388534 100644 --- a/tests/test_v2_terminal_merge.py +++ b/tests/test_v2_terminal_merge.py @@ -11,6 +11,7 @@ from ComfyUI_H3_Continuum_Join.v2.sequence import ( _terminal_physical_seed_plan, _terminal_pair_contract, _terminal_sampling_plan, + _terminal_strategy_mismatch, ) from ComfyUI_H3_Continuum_Join.v2.seeds import derive_chunk_seed @@ -97,6 +98,27 @@ def test_rerolling_final_chunk_regenerates_both_terminal_chunks(): assert reset is True +def test_two_chunk_terminal_cache_extended_to_three_reuses_one_generates_two(): + preserved = [{"chunk": 1}, {"chunk": 2}] + + reusable, reset = _atomic_terminal_prefix( + preserved, + chunks=3, + reroll_from_chunk=3, + ) + normal, terminal = _terminal_sampling_plan( + chunks=3, + completed=len(reusable), + merge_enabled=True, + ) + + assert reusable == preserved[:1] + assert reset is True + assert normal == () + assert terminal is True + assert (len(reusable), 2) == (1, 2) + + def test_complete_terminal_pair_remains_reusable_without_reroll(): preserved = [{"chunk": 1}, {"chunk": 2}, {"chunk": 3}] result, reset = _atomic_terminal_prefix(preserved, chunks=3, reroll_from_chunk=0) @@ -104,6 +126,29 @@ def test_complete_terminal_pair_remains_reusable_without_reroll(): assert reset is False +def test_non_terminal_flf_keeps_run_storage_validated_prefix_without_terminal_strategy(): + session = {"settings": {"run_storage_validated_prefix": True}} + + assert not _terminal_strategy_mismatch(session, merge_enabled=False) + + +def test_terminal_merge_rejects_prefix_without_matching_strategy(): + session = {"settings": {"run_storage_validated_prefix": True}} + + assert _terminal_strategy_mismatch(session, merge_enabled=True) + + +def test_terminal_merge_keeps_prefix_with_matching_strategy(): + session = { + "settings": { + "run_storage_validated_prefix": True, + "flf_execution": "terminal_merged_10s_seed_v2", + } + } + + assert not _terminal_strategy_mismatch(session, merge_enabled=True) + + @pytest.mark.parametrize("base_seed", [42, 123456789]) def test_initial_terminal_pair_uses_base_seed_directly(base_seed): plan = _terminal_physical_seed_plan( diff --git a/tests/test_v31_run_storage.py b/tests/test_v31_run_storage.py index 796f181..edcfd53 100644 --- a/tests/test_v31_run_storage.py +++ b/tests/test_v31_run_storage.py @@ -10,6 +10,7 @@ import ctypes from ComfyUI_H3_Continuum_Join.run_storage import ( RunStorageController, + _hash, _resume_session_settings, _apply_nonce_contract, _fsync_file, @@ -297,7 +298,9 @@ def _sampling_contract( execution_semantics=None, reference_audio_contract=None, reference_audio_vae=None, prompt_hashes=None, + chunks=3, reroll_from_chunk=2, ): + default_hashes = [str(index) * 64 for index in range(1, int(chunks) + 1)] return build_sampling_contract( model=model or _Model(), model_fingerprint_value="f" * 64, @@ -306,8 +309,8 @@ def _sampling_contract( sampler=sampler or _Sampler(), sigmas=torch.tensor([1.0, 0.0]), prompt_plan={ - "chunks": 3, - "hashes": list(prompt_hashes or ["1" * 64, "2" * 64, "3" * 64]), + "chunks": int(chunks), + "hashes": list(prompt_hashes or default_hashes), "mode": "list", }, width=96, @@ -316,7 +319,7 @@ def _sampling_contract( continuity="Balanced", audio_continuity=True, base_seed=1, - reroll_from_chunk=2, + reroll_from_chunk=int(reroll_from_chunk), reroll_nonce=reroll_nonce, first_frame_hash=first_frame_hash, last_frame_hash=last_frame_hash, @@ -332,6 +335,194 @@ def _sampling_contract( ) +def _persist_contract_prefix(tmp_path, contract, *, count): + controller = RunStorageController("extend-prefix") + controller.revisions_root = tmp_path / "revisions" + controller.revision_id, controller.contract_sha256 = revision_identity(contract) + controller.revision_root = controller.revisions_root / controller.revision_id + controller.contract = contract + controller.prompts = [f"prompt {index + 1}" for index in range(int(count))] + controller.manifest = { + "contract": contract, + "chunks": [], + "status": "in_progress", + } + for position in range(int(count)): + controller.commit_chunk( + _entry(position, prompt=controller.prompts[position]), + position=position, + ) + return controller + + +def _load_compatible_prefix(tmp_path, stored, current): + controller = RunStorageController("extend-prefix") + controller.revisions_root = tmp_path / "revisions" + controller.contract = current + controller.prompts = [ + f"prompt {index + 1}" for index in range(int(current["chunk_count"])) + ] + entries, records = controller._valid_prefix( + stored.manifest, current["chunk_contract_hashes"] + ) + return controller, entries, records + + +def _legacy_none_final_contract(contract): + legacy = copy.deepcopy(contract) + legacy["last_frame_hash"] = "none" + legacy["chunk_contracts"][-1]["last_frame_hash"] = "none" + legacy["chunk_contract_hashes"][-1] = _hash(legacy["chunk_contracts"][-1]) + return legacy + + +@pytest.mark.parametrize("absent", [None, "", "none", "null", " NONE ", " NULL "]) +def test_absent_last_frame_hash_is_canonical_for_every_chunk(absent): + contract, safe, reasons = _sampling_contract( + last_frame_hash=absent, + chunks=3, + reroll_from_chunk=3, + ) + + assert safe, reasons + assert contract["last_frame_hash"] == "" + assert [item["last_frame_hash"] for item in contract["chunk_contracts"]] == [ + "", + "", + "", + ] + + +def test_i2va_two_to_three_reuses_both_canonical_prefix_chunks(tmp_path): + model, clip, video_vae, sampler = _Model(), _Clip(), _VideoVAE(), _Sampler() + common = { + "model": model, + "clip": clip, + "video_vae": video_vae, + "sampler": sampler, + } + stored_contract, safe, reasons = _sampling_contract( + **common, chunks=2, reroll_from_chunk=0, last_frame_hash="" + ) + assert safe, reasons + current_contract, safe, reasons = _sampling_contract( + **common, chunks=3, reroll_from_chunk=3, last_frame_hash="" + ) + assert safe, reasons + stored = _persist_contract_prefix(tmp_path, stored_contract, count=2) + + controller, entries, records = _load_compatible_prefix( + tmp_path, stored, current_contract + ) + + assert len(entries) == len(records) == 2 + assert not controller.notes + + +def test_i2va_two_to_three_reuses_legacy_none_final_chunk(tmp_path): + model, clip, video_vae, sampler = _Model(), _Clip(), _VideoVAE(), _Sampler() + common = { + "model": model, + "clip": clip, + "video_vae": video_vae, + "sampler": sampler, + } + canonical_stored, safe, reasons = _sampling_contract( + **common, chunks=2, reroll_from_chunk=0, last_frame_hash="" + ) + assert safe, reasons + legacy_stored = _legacy_none_final_contract(canonical_stored) + current_contract, safe, reasons = _sampling_contract( + **common, chunks=3, reroll_from_chunk=3, last_frame_hash="" + ) + assert safe, reasons + stored = _persist_contract_prefix(tmp_path, legacy_stored, count=2) + + controller, entries, records = _load_compatible_prefix( + tmp_path, stored, current_contract + ) + + assert len(entries) == len(records) == 2 + assert controller.notes == [ + "stored chunk 2 reused through V3.6.1 absent Last Frame compatibility" + ] + + +def test_legacy_none_cache_exact_resume_reuses_every_chunk(tmp_path): + model, clip, video_vae, sampler = _Model(), _Clip(), _VideoVAE(), _Sampler() + common = { + "model": model, + "clip": clip, + "video_vae": video_vae, + "sampler": sampler, + } + canonical, safe, reasons = _sampling_contract( + **common, chunks=2, reroll_from_chunk=0, last_frame_hash="" + ) + assert safe, reasons + legacy = _legacy_none_final_contract(canonical) + current, safe, reasons = _sampling_contract( + **common, chunks=2, reroll_from_chunk=0, last_frame_hash="" + ) + assert safe, reasons + stored = _persist_contract_prefix(tmp_path, legacy, count=2) + + _, entries, records = _load_compatible_prefix(tmp_path, stored, current) + + assert len(entries) == len(records) == 2 + + +def test_real_last_frame_two_to_three_invalidates_old_final_chunk(tmp_path): + model, clip, video_vae, sampler = _Model(), _Clip(), _VideoVAE(), _Sampler() + common = { + "model": model, + "clip": clip, + "video_vae": video_vae, + "sampler": sampler, + "conditioning_mode": "fl2va", + "last_frame_hash": "b" * 64, + } + stored_contract, safe, reasons = _sampling_contract( + **common, chunks=2, reroll_from_chunk=0 + ) + assert safe, reasons + current_contract, safe, reasons = _sampling_contract( + **common, chunks=3, reroll_from_chunk=3 + ) + assert safe, reasons + stored = _persist_contract_prefix(tmp_path, stored_contract, count=2) + + _, entries, records = _load_compatible_prefix(tmp_path, stored, current_contract) + + assert len(entries) == len(records) == 1 + + +def test_absent_last_frame_compatibility_rejects_any_other_chunk_difference(tmp_path): + model, clip, video_vae, sampler = _Model(), _Clip(), _VideoVAE(), _Sampler() + common = { + "model": model, + "clip": clip, + "video_vae": video_vae, + "sampler": sampler, + } + canonical, safe, reasons = _sampling_contract( + **common, chunks=2, reroll_from_chunk=0, last_frame_hash="" + ) + assert safe, reasons + legacy = _legacy_none_final_contract(canonical) + legacy["chunk_contracts"][1]["prompt_hash"] = "f" * 64 + legacy["chunk_contract_hashes"][1] = _hash(legacy["chunk_contracts"][1]) + current, safe, reasons = _sampling_contract( + **common, chunks=3, reroll_from_chunk=3, last_frame_hash="" + ) + assert safe, reasons + stored = _persist_contract_prefix(tmp_path, legacy, count=2) + + _, entries, records = _load_compatible_prefix(tmp_path, stored, current) + + assert len(entries) == len(records) == 1 + + def test_mixed_timeline_normalization_separates_run_storage_revision(): script = "[Chunk 1]\nA\n[Chunk 2]\nB\n---\nC" normalized = make_prompt_plan( diff --git a/tests/test_v35_compact_ui_frontend.py b/tests/test_v35_compact_ui_frontend.py index 0dc8535..2c9911b 100644 --- a/tests/test_v35_compact_ui_frontend.py +++ b/tests/test_v35_compact_ui_frontend.py @@ -1,4 +1,9 @@ from pathlib import Path +import json +import shutil +import subprocess + +import pytest ROOT = Path(__file__).resolve().parents[1] @@ -45,6 +50,23 @@ def test_v36_sampler_uses_compact_settings_without_hiding_backend_choice(): assert 'hidePersistentWidget(findWidget(node, "continuation_backend"))' not in configure +def test_v37_sampler_inherits_v36_compact_frontend_and_queue_normalization(): + source = PROJECT_ID_JS.read_text(encoding="utf-8") + configure = _function_source(source, "configureNode", "configureNodeAfterSetup") + before_queue = source[source.index("async beforeQueuePrompt") :] + + assert 'const V37_NODE_CLASS = "H3ContinuumSamplerV37";' in source + assert "const isV37 = node.comfyClass === V37_NODE_CLASS;" in configure + assert ( + "!isProduction && !isTimeline && !isV34 && !isV35 && !isV36 && !isV37" + in configure + ) + assert "isProduction || isV34 || isV35 || isV36 || isV37" in configure + assert "isV35 || isV36 || isV37" in configure + assert "node.comfyClass === V37_NODE_CLASS" in before_queue + assert 'hidePersistentWidget(findWidget(node, "continuation_backend"))' not in configure + + def test_v35_assembler_uses_existing_compact_runtime_settings_path(): source = PROJECT_ID_JS.read_text(encoding="utf-8") configure = _function_source(source, "configureAssembler", "configureNode") @@ -57,3 +79,99 @@ def test_v35_assembler_uses_existing_compact_runtime_settings_path(): assert "node.comfyClass !== V35_ASSEMBLE_SEAM_NODE_CLASS" in configure assert "node.comfyClass === V35_ASSEMBLE_SEAM_NODE_CLASS" in before_queue assert 'hidePersistentWidget(findWidget(node, "diagnostics"))' in configure + + +def test_run_storage_off_normalizes_widgets_reload_and_queued_inputs(tmp_path): + node_executable = shutil.which("node") + if node_executable is None: + pytest.skip("Node.js is required for the frontend behavior regression") + + source = PROJECT_ID_JS.read_text(encoding="utf-8") + functions = "\n".join( + [ + _function_source(source, "findWidget", "setWidgetVisible"), + _function_source(source, "setWidgetVisible", "hidePersistentWidget"), + _function_source(source, "linkedInput", "attachRefresh"), + _function_source(source, "attachRefresh", "normalizeRunStorageState"), + _function_source(source, "normalizeRunStorageState", "configureConditionalWidgets"), + _function_source(source, "configureConditionalWidgets", "configureAssembler"), + ] + ) + script = f""" +const RUN_STORAGE_WIDGET = "run_storage"; +const REGENERATE_WIDGET = "reroll_from_chunk"; +const REROLL_NONCE_WIDGET = "reroll_nonce"; +const LEGACY_RUN_NAME_WIDGET = "run_name"; +const REFERENCE_SIZE_WIDGET = "reference_size"; +const TIMELINE_SIZE_WIDGET = "timeline_video_size"; +const VIDEO_REFERENCE_SIZE_WIDGET = "video_reference_size"; +{functions} + +function widget(name, value) {{ + return {{ name, value, type: "combo", options: {{}}, computeSize: () => [120, 20] }}; +}} +function makeNode(storage, regenerate, nonce) {{ + return {{ + widgets: [ + widget(RUN_STORAGE_WIDGET, storage), + widget(REGENERATE_WIDGET, regenerate), + widget(REROLL_NONCE_WIDGET, nonce), + widget(LEGACY_RUN_NAME_WIDGET, "phase1-test"), + widget(REFERENCE_SIZE_WIDGET, "Match Output"), + widget(TIMELINE_SIZE_WIDGET, "Efficient"), + widget(VIDEO_REFERENCE_SIZE_WIDGET, "Efficient"), + ], + inputs: [], + setDirtyCanvas() {{}}, + }}; +}} + +const live = makeNode("Save + Auto Resume", "Auto", 0); +configureConditionalWidgets(live); +const liveStorage = findWidget(live, RUN_STORAGE_WIDGET); +const liveRegenerate = findWidget(live, REGENERATE_WIDGET); +const liveNonce = findWidget(live, REROLL_NONCE_WIDGET); +liveRegenerate.value = "Chunk 2"; +liveRegenerate.callback("Chunk 2"); +liveNonce.value = 5; +liveStorage.value = "Off"; +liveStorage.callback("Off"); + +const queued = {{ reroll_from_chunk: "Chunk 2", reroll_nonce: 5 }}; +normalizeRunStorageState(live, queued); + +const reloaded = makeNode("Off", "Chunk 3", 9); +configureConditionalWidgets(reloaded); +const reloadRegenerate = findWidget(reloaded, REGENERATE_WIDGET); +const reloadNonce = findWidget(reloaded, REROLL_NONCE_WIDGET); + +console.log(JSON.stringify({{ + live: {{ regenerate: liveRegenerate.value, nonce: liveNonce.value }}, + queued, + reloaded: {{ + regenerate: reloadRegenerate.value, + nonce: reloadNonce.value, + regenerateHidden: reloadRegenerate.hidden, + nonceHidden: reloadNonce.hidden, + }}, +}})); +""" + script_path = tmp_path / "run-storage-frontend-regression.js" + script_path.write_text(script, encoding="utf-8") + + result = subprocess.run( + [node_executable, str(script_path)], + check=True, + capture_output=True, + text=True, + ) + observed = json.loads(result.stdout) + + assert observed["live"] == {"regenerate": "Auto", "nonce": 0} + assert observed["queued"] == {"reroll_from_chunk": "Auto", "reroll_nonce": 0} + assert observed["reloaded"] == { + "regenerate": "Auto", + "nonce": 0, + "regenerateHidden": True, + "nonceHidden": True, + } diff --git a/tests/test_v35_hires_fix.py b/tests/test_v35_hires_fix.py index 127c0f2..08f282c 100644 --- a/tests/test_v35_hires_fix.py +++ b/tests/test_v35_hires_fix.py @@ -125,6 +125,7 @@ def test_enabled_pixel_vae_roundtrip_then_reuses_second_pass_contract(monkeypatc "sampled", ) calls = [] + schedule = object() def fake_roundtrip(video_latents, assembly_plan, **kwargs): calls.append(("roundtrip", video_latents, assembly_plan, kwargs)) @@ -161,6 +162,7 @@ def test_enabled_pixel_vae_roundtrip_then_reuses_second_pass_contract(monkeypatc [17], [{"context": True}], ["video-vae"], + schedule, ) assert result[:3] == sentinel[:3] @@ -190,6 +192,7 @@ def test_enabled_pixel_vae_roundtrip_then_reuses_second_pass_contract(monkeypatc assert second_pass["refine_context"] == {"context": True} assert second_pass["video_vae"] == "video-vae" assert second_pass["conditioning_upscale_method"] == "bilinear" + assert second_pass["refine_schedule"] is schedule @pytest.mark.parametrize( diff --git a/tests/test_v35_refine_context.py b/tests/test_v35_refine_context.py index 7ff1a6d..05d8da2 100644 --- a/tests/test_v35_refine_context.py +++ b/tests/test_v35_refine_context.py @@ -6,6 +6,7 @@ import pytest import torch from ComfyUI_H3_Continuum_Join.constants import MARK_VIDEO_CONTEXT +from ComfyUI_H3_Continuum_Join.guide_timeline import MARK_STILL_IMAGE_GUIDE from ComfyUI_H3_Continuum_Join.v3 import refine_context as rc @@ -170,6 +171,71 @@ def test_keyframes_reencode_images_with_core_first_last_crop_rules(monkeypatch): assert stats["warnings"] == () +def test_arbitrary_guide_keyframe_reencodes_from_owned_source_image(monkeypatch): + calls = [] + + def upscale(samples, width, height, method, crop): + calls.append((width, height, method, crop, samples.clone())) + return torch.nn.functional.interpolate(samples, size=(height, width), mode="nearest") + + monkeypatch.setattr(rc, "_common_upscale", upscale) + conditioning = _conditioning() + conditioning[0][1]["minimax_keyframes"].append( + { + "resolved_frame_index": 60, + "latent": torch.zeros((1, 24, 1, 2, 3)), + MARK_STILL_IMAGE_GUIDE: True, + } + ) + guide_image = torch.full((1, 20, 30, 3), 0.625) + group = _group( + conditioning=conditioning, + guide_images={60: guide_image}, + ) + vae = _FakeVAE() + + adapted, stats = rc.adapt_group_conditioning(group, 4, 6, video_vae=vae) + + guide_keyframe = adapted[0][1]["minimax_keyframes"][2] + assert torch.all(guide_keyframe["latent"] == 3) + assert calls[2][:4] == (96, 64, "lanczos", "center") + assert torch.all(calls[2][4] == 0.625) + assert stats["keyframes_reencoded"] == 3 + assert stats["guide_keyframes_reencoded"] == 1 + assert stats["keyframes_latent_fallback"] == 0 + assert group["guide_images"][60].device.type == "cpu" + assert group["guide_images"][60].data_ptr() != guide_image.data_ptr() + + +@pytest.mark.parametrize("frame_index", [0, 123]) +def test_guide_role_wins_when_guide_shares_first_or_last_frame(monkeypatch, frame_index): + monkeypatch.setattr(rc, "_common_upscale", _upscale) + conditioning = _conditioning() + conditioning[0][1]["minimax_keyframes"].append( + { + "resolved_frame_index": frame_index, + "latent": torch.full((1, 24, 1, 2, 3), 9.0), + MARK_STILL_IMAGE_GUIDE: True, + } + ) + guide_image = torch.full((1, 32, 48, 3), 0.75) + vae = _FakeVAE() + + adapted, stats = rc.adapt_group_conditioning( + _group(conditioning=conditioning, guide_images={frame_index: guide_image}), + 4, + 6, + video_vae=vae, + ) + + keyframes = adapted[0][1]["minimax_keyframes"] + assert torch.all(keyframes[2]["latent"] == 3) + assert torch.all(vae.inputs[2] == 0.75) + assert not torch.equal(vae.inputs[2], vae.inputs[0]) + assert not torch.equal(vae.inputs[2], vae.inputs[1]) + assert stats["guide_keyframes_reencoded"] == 1 + + def test_context_validation_matches_physical_group_assembly_contract(): group = _group() context = rc.make_refine_context( diff --git a/tests/test_v35_second_pass_sampling.py b/tests/test_v35_second_pass_sampling.py index b189984..e78a792 100644 --- a/tests/test_v35_second_pass_sampling.py +++ b/tests/test_v35_second_pass_sampling.py @@ -14,6 +14,7 @@ from ComfyUI_H3_Continuum_Join.v3.refine_context import ( MAGIC as REFINE_CONTEXT_MAGIC, RefineConditioningAdaptationError, ) +from ComfyUI_H3_Continuum_Join.v3.refine_schedule import make_tail_schedule from ComfyUI_H3_Continuum_Join.v3.second_pass_nodes import ( H3ContinuumSecondPassV35, ) @@ -81,6 +82,7 @@ def _run_fixture(groups: list[dict]): def sample(**kwargs): calls[-1]["seed"] = kwargs["seed"] calls[-1]["conditioning"] = kwargs["conditioning"] + calls[-1]["sigmas"] = kwargs["sigmas"] nested = kwargs["latent"] return { "video": nested["video"] + 1, @@ -151,12 +153,63 @@ def test_second_pass_uses_plan_prompts_one_seed_per_physical_group_and_audio_pas assert updated["second_pass_contract"]["audio_sampling"] == ( "zero_noise_mask_locked" ) + schedule = updated["second_pass_contract"]["refine_schedule"] + assert schedule["mode"] == "external" + assert schedule["evaluation_count"] == 1 + assert updated["second_pass_contract"]["refine_schedule_identity"] == ( + schedule["schedule_hash"] + ) + assert all(call["sigmas"] is calls[0]["sigmas"] for call in calls) assert "temporary_audio_discarded=true" in report assert "audio zero noise/mask=0" in report assert "refine_seed=" in report assert videos[1]["samples"].shape[2] == 65 +def test_internal_tail_schedule_passes_the_exact_suffix_and_records_identity(): + group = _group(0, temporal=31, prompt="physical prompt") + video = _latent(torch.zeros((1, 24, 31, 48, 48))) + audio = _latent(torch.ones(tuple(group["source_audio_shape"]))) + base_sigmas = torch.tensor([1.0, 0.75, 0.5, 0.25, 0.0]) + tail = make_tail_schedule(base_sigmas, evaluation_count=2) + captured = {} + + def sample(**kwargs): + captured.update(kwargs) + return kwargs["latent"] + + _video, output_audio, updated, report = run_second_pass_groups( + model=object(), + clip=object(), + sampler=object(), + sigmas=base_sigmas, + video_latents=[video], + audio_latents=[audio], + assembly_plan=_plan([group]), + refine_seed=17, + refine_schedule=tail, + encode_prompt_fn=lambda *_args, **_kwargs: ["conditioning"], + latent_builder=lambda video_samples, audio_samples: { + "video": video_samples, + "audio": audio_samples, + }, + sample_fn=sample, + stream_extractor=lambda sampled: (sampled["video"], sampled["audio"]), + clone_model_fn=lambda source, **_kwargs: source, + ) + + assert captured["sigmas"] is tail.sigmas + assert torch.equal(captured["sigmas"], base_sigmas[2:]) + schedule = updated["second_pass_contract"]["refine_schedule"] + assert schedule["mode"] == "tail" + assert schedule["evaluation_count"] == 2 + assert schedule["start_index"] == 2 + assert schedule["noise_mode"] == "video_random_mask_1_audio_zero_mask_0" + assert schedule["audio_policy"] == "locked_first_pass_bit_exact_passthrough" + assert output_audio[0] is audio + assert "mode=tail" in report + + def test_second_pass_defaults_to_audio_locked_refine_sampler(monkeypatch): group = _group(0, temporal=31, prompt="physical prompt") video = _latent(torch.zeros((1, 24, 31, 48, 48))) @@ -469,6 +522,7 @@ def test_second_pass_node_forwards_optional_refine_context_and_video_vae(monkeyp ) context = {"context": True} video_vae = object() + schedule = object() result = H3ContinuumSecondPassV35().refine( ["model"], ["clip"], @@ -480,11 +534,13 @@ def test_second_pass_node_forwards_optional_refine_context_and_video_vae(monkeyp [7], [context], [video_vae], + schedule, ) assert result == sentinel assert captured["refine_context"] is context assert captured["video_vae"] is video_vae + assert captured["refine_schedule"] is schedule def test_second_pass_node_is_registered_and_not_deprecated(): diff --git a/tests/test_v37_guide_production.py b/tests/test_v37_guide_production.py new file mode 100644 index 0000000..f476789 --- /dev/null +++ b/tests/test_v37_guide_production.py @@ -0,0 +1,328 @@ +from __future__ import annotations + +import copy + +import pytest +import torch + +from ComfyUI_H3_Continuum_Join import guide_timeline as guide_module +from ComfyUI_H3_Continuum_Join import run_storage as run_storage_module +from ComfyUI_H3_Continuum_Join.guide_timeline import ( + GUIDE_MODE_STILL_IMAGE, + GUIDE_SCHEMA_VERSION, + GUIDE_TYPE, + MARK_STILL_IMAGE_GUIDE, + GuideTargetError, + StillImageGuideAssets, + attach_still_image_guide, + combine_guide_identity, + make_still_image_guide, + prepare_still_image_guide_source, + resolve_guide_for_physical_group, +) +from ComfyUI_H3_Continuum_Join.v3.driving_nodes import ( + H3ContinuumSamplerV36, + H3ContinuumSamplerV37, + H3ContinuumStillImageGuideV37, + NODE_CLASS_MAPPINGS, +) +from ComfyUI_H3_Continuum_Join.v2 import nodes as v2_nodes_module +from ComfyUI_H3_Continuum_Join.v2.nodes import H3ContinuumSamplerV2 +from ComfyUI_H3_Continuum_Join.run_storage import ( + build_sampling_contract, + revision_identity, +) + + +def _prepare(monkeypatch, image, frame): + monkeypatch.setattr( + guide_module, + "_resize_guide_image", + lambda value, width, height: value[:1, ..., :3].contiguous(), + ) + return prepare_still_image_guide_source( + make_still_image_guide(image, frame), + output_width=576, + output_height=576, + ) + + +def test_public_guide_payload_is_frame_based_and_versioned(): + image = torch.zeros((1, 4, 4, 3), dtype=torch.float32) + payload = H3ContinuumStillImageGuideV37().pack(image, 183)[0] + assert payload["schema_version"] == GUIDE_SCHEMA_VERSION + assert payload["mode"] == GUIDE_MODE_STILL_IMAGE + assert payload["absolute_frame"] == 183 + assert payload["image"] is image + assert H3ContinuumStillImageGuideV37.RETURN_TYPES == (GUIDE_TYPE,) + + +@pytest.mark.parametrize("absolute_frame", [-1, 1.5, True]) +def test_public_guide_rejects_non_strict_frames(absolute_frame): + image = torch.zeros((1, 4, 4, 3), dtype=torch.float32) + with pytest.raises(GuideTargetError, match="absolute_frame"): + make_still_image_guide(image, absolute_frame) + + +@pytest.mark.parametrize("batch", [0, 2, 5]) +def test_public_guide_rejects_non_single_image_batches(batch): + image = torch.zeros((batch, 4, 4, 3), dtype=torch.float32) + with pytest.raises(GuideTargetError, match="batch must be exactly 1"): + make_still_image_guide(image, 0) + + +def test_prepare_rejects_non_single_image_batch_defensively(monkeypatch): + image = torch.zeros((2, 4, 4, 3), dtype=torch.float32) + payload = { + "schema_version": GUIDE_SCHEMA_VERSION, + "mode": GUIDE_MODE_STILL_IMAGE, + "absolute_frame": 0, + "image": image, + } + with pytest.raises(GuideTargetError, match="batch must be exactly 1"): + prepare_still_image_guide_source( + payload, output_width=576, output_height=576 + ) + + +def test_run_storage_identity_scopes_image_frame_mode_and_schema(monkeypatch): + image = torch.zeros((1, 4, 4, 3), dtype=torch.float32) + source_a = _prepare(monkeypatch, image, 60) + source_same = _prepare(monkeypatch, image.clone(), 60) + source_frame = _prepare(monkeypatch, image.clone(), 61) + changed = image.clone() + changed[0, 0, 0, 0] = 1.0 + source_image = _prepare(monkeypatch, changed, 60) + + identity = combine_guide_identity("base", source_a) + assert identity == combine_guide_identity("base", source_same) + assert identity != combine_guide_identity("base", source_frame) + assert identity != combine_guide_identity("base", source_image) + assert source_a.contract["mode"] == GUIDE_MODE_STILL_IMAGE + assert source_a.contract["schema_version"] == GUIDE_SCHEMA_VERSION + assert source_a.contract["absolute_frame"] == 60 + assert source_a.contract["source_image_sha256"] + + +def test_prepared_guide_owns_the_original_source_image(monkeypatch): + image = torch.rand((1, 6, 8, 3), dtype=torch.float32) + source = _prepare(monkeypatch, image, 60) + assert source.source_image is not image + assert source.source_image.device.type == "cpu" + assert torch.equal(source.source_image, image) + image.fill_(0) + assert not bool((source.source_image == 0).all()) + assert source.contract["source_width"] == 8 + assert source.contract["source_height"] == 6 + + +def test_prepare_rejects_future_mode_or_schema(monkeypatch): + image = torch.zeros((1, 4, 4, 3), dtype=torch.float32) + payload = make_still_image_guide(image, 0) + bad_schema = dict(payload, schema_version=GUIDE_SCHEMA_VERSION + 1) + bad_mode = dict(payload, mode="audio") + with pytest.raises(GuideTargetError, match="schema"): + prepare_still_image_guide_source( + bad_schema, output_width=576, output_height=576 + ) + with pytest.raises(GuideTargetError, match="mode"): + prepare_still_image_guide_source( + bad_mode, output_width=576, output_height=576 + ) + + +def test_runtime_group_resolver_uses_context_prefix_and_visible_tail(): + target = resolve_guide_for_physical_group( + 183, + target_frames=360, + physical_group_index=1, + logical_chunks=(2,), + global_visible_start=124, + natural_visible_stop=243, + context_prefix_frames=22, + physical_frames=141, + terminal_merged=False, + ) + assert target["local_visible_frame"] == 59 + assert target["resolved_frame_index"] == 81 + assert resolve_guide_for_physical_group( + 359, + target_frames=360, + physical_group_index=2, + logical_chunks=(3,), + global_visible_start=243, + natural_visible_stop=362, + context_prefix_frames=22, + physical_frames=141, + terminal_merged=False, + )["resolved_frame_index"] == 138 + + +def test_runtime_group_resolver_supports_terminal_merge(): + target = resolve_guide_for_physical_group( + 243, + target_frames=360, + physical_group_index=1, + logical_chunks=(2, 3), + global_visible_start=124, + natural_visible_stop=362, + context_prefix_frames=22, + physical_frames=260, + terminal_merged=True, + ) + assert target["logical_chunks"] == [2, 3] + assert target["resolved_frame_index"] == 141 + assert target["terminal_merged"] is True + + +def test_keyframe_injection_clones_and_preserves_existing_order(): + original = [[torch.zeros(1), {"minimax_keyframes": [ + {"resolved_frame_index": 0, "latent": torch.tensor([1.0])}, + {"resolved_frame_index": 123, "latent": torch.tensor([2.0])}, + ], "minimax_frame_count": 124}]] + before = copy.deepcopy(original) + source = guide_module.StillImageGuideSource( + image=torch.zeros((1, 4, 4, 3)), + absolute_frame=60, + contract={ + "schema_version": GUIDE_SCHEMA_VERSION, + "mode": GUIDE_MODE_STILL_IMAGE, + "absolute_frame": 60, + "image_sha256": "x", + }, + ) + assets = StillImageGuideAssets(source=source, latent=torch.tensor([3.0])) + output = attach_still_image_guide( + original, + assets, + {"resolved_frame_index": 60}, + ) + assert output is not original + assert [item["resolved_frame_index"] for item in output[0][1]["minimax_keyframes"]] == [0, 123, 60] + assert torch.equal( + original[0][1]["minimax_keyframes"][0]["latent"], + before[0][1]["minimax_keyframes"][0]["latent"], + ) + assert len(original[0][1]["minimax_keyframes"]) == 2 + assert output[0][1]["minimax_keyframes"][2][MARK_STILL_IMAGE_GUIDE] is True + + +def test_v36_schema_is_unchanged_and_v37_adds_only_typed_guide(): + v36 = H3ContinuumSamplerV36.INPUT_TYPES() + v37 = H3ContinuumSamplerV37.INPUT_TYPES() + assert "guide" not in v36.get("required", {}) + assert "guide" not in v36.get("optional", {}) + assert v37["required"] == v36["required"] + expected_optional = dict(v36["optional"]) + expected_optional["guide"] = v37["optional"]["guide"] + assert v37["optional"] == expected_optional + assert v37["optional"]["guide"][0] == GUIDE_TYPE + + +def test_v37_nodes_are_registered_without_replacing_v36(): + assert NODE_CLASS_MAPPINGS["H3ContinuumSamplerV36"] is H3ContinuumSamplerV36 + assert NODE_CLASS_MAPPINGS["H3ContinuumSamplerV37"] is H3ContinuumSamplerV37 + assert ( + NODE_CLASS_MAPPINGS["H3ContinuumStillImageGuideV37"] + is H3ContinuumStillImageGuideV37 + ) + + +def test_v2_orchestration_forwards_guide_source_to_sequence(monkeypatch): + captured = {} + guide_source = object() + + def fake_run_sequence(**kwargs): + captured.update(kwargs) + return "ok" + + monkeypatch.setattr(v2_nodes_module, "run_sequence", fake_run_sequence) + result = H3ContinuumSamplerV2().run( + model=object(), + clip=object(), + video_vae=object(), + audio_vae=None, + sampler=object(), + sigmas=torch.tensor([1.0, 0.0]), + prompt_mode="Fixed", + prompt_script="Prompt", + chunks=1, + chunk_seconds=5.0, + width=384, + height=384, + continuity="Balanced — 22 frames", + base_seed=1, + audio_continuity=True, + exact_total_duration=False, + diagnostics="Off", + reroll_from_chunk=0, + reroll_nonce=0, + strict_compatibility=False, + debug=False, + guide_source=guide_source, + ) + assert result == "ok" + assert captured["guide_source"] is guide_source + + +def test_run_storage_revision_tracks_every_guide_identity_field(monkeypatch): + monkeypatch.setattr( + run_storage_module, "_model_signature", lambda model, value: ({}, True) + ) + monkeypatch.setattr(run_storage_module, "_clip_signature", lambda clip: ({}, True)) + monkeypatch.setattr( + run_storage_module, + "_video_vae_signature", + lambda vae, required: ({}, True), + ) + monkeypatch.setattr( + run_storage_module, "_sampler_signature", lambda sampler: ({}, True) + ) + + base_guide = { + "schema_version": GUIDE_SCHEMA_VERSION, + "mode": GUIDE_MODE_STILL_IMAGE, + "absolute_frame": 60, + "image_sha256": "a" * 64, + "width": 384, + "height": 384, + } + + def build(guide_contract): + contract, safe, reasons = build_sampling_contract( + model=object(), + model_fingerprint_value="m" * 64, + clip=object(), + video_vae=object(), + sampler=object(), + sigmas=torch.tensor([1.0, 0.0]), + prompt_plan={"chunks": 1, "hashes": ["p" * 64], "mode": "fixed"}, + width=384, + height=384, + chunk_seconds=5.0, + continuity="Balanced — 22 frames", + audio_continuity=True, + base_seed=1, + reroll_from_chunk=0, + reroll_nonce=0, + first_frame_hash="none", + last_frame_hash="none", + strict_compatibility=False, + conditioning_mode="t2va", + guide_contract=guide_contract, + ) + assert safe is True + assert reasons == [] + return contract + + baseline = build(base_guide) + assert baseline["global"]["guide"] == base_guide + baseline_revision = revision_identity(baseline) + for field, changed_value in ( + ("absolute_frame", 61), + ("image_sha256", "b" * 64), + ("mode", "video"), + ("schema_version", GUIDE_SCHEMA_VERSION + 1), + ): + changed = dict(base_guide, **{field: changed_value}) + assert revision_identity(build(changed)) != baseline_revision diff --git a/tests/test_v37_guide_timeline.py b/tests/test_v37_guide_timeline.py new file mode 100644 index 0000000..4a548f6 --- /dev/null +++ b/tests/test_v37_guide_timeline.py @@ -0,0 +1,151 @@ +from __future__ import annotations + +import pytest + +from ComfyUI_H3_Continuum_Join.guide_timeline import ( + GuideTargetError, + resolve_guide_target, +) + + +def _standard_three_chunk_plan() -> dict[str, Any]: + return { + "target_frames": 360, + "chunks": [ + { + "chunk_index": 1, + "frame_start": 0, + "frame_stop": 124, + "total_frames": 124, + "trim_frames": 0, + "context_frames": 0, + "net_frames": 124, + }, + { + "chunk_index": 2, + "frame_start": 124, + "frame_stop": 243, + "total_frames": 141, + "trim_frames": 22, + "context_frames": 22, + "net_frames": 119, + }, + { + "chunk_index": 3, + "frame_start": 243, + "frame_stop": 362, + "total_frames": 141, + "trim_frames": 22, + "context_frames": 22, + "net_frames": 119, + }, + ], + } + + +@pytest.mark.parametrize( + ("absolute_frame", "group_index", "local_frame", "context", "resolved"), + [ + (0, 0, 0, 0, 0), + (60, 0, 60, 0, 60), + (123, 0, 123, 0, 123), + (124, 1, 0, 22, 22), + (183, 1, 59, 22, 81), + (242, 1, 118, 22, 140), + (243, 2, 0, 22, 22), + (302, 2, 59, 22, 81), + (359, 2, 116, 22, 138), + ], +) +def test_standard_three_chunk_absolute_mapping( + absolute_frame, + group_index, + local_frame, + context, + resolved, +): + result = resolve_guide_target(absolute_frame, _standard_three_chunk_plan()) + assert result["physical_group_index"] == group_index + assert result["local_visible_frame"] == local_frame + assert result["context_prefix_frames"] == context + assert result["resolved_frame_index"] == resolved + assert result["resolved_frame_index"] >= result["context_prefix_frames"] + + +def test_single_group_uses_visible_target_not_native_tail(): + plan = { + "target_frames": 120, + "chunks": [ + { + "chunk_index": 1, + "frame_start": 0, + "frame_stop": 124, + "total_frames": 124, + "trim_frames": 0, + "net_frames": 124, + } + ], + } + result = resolve_guide_target(119, plan) + assert result["resolved_frame_index"] == 119 + with pytest.raises(GuideTargetError, match="outside visible range"): + resolve_guide_target(120, plan) + + +def test_negative_and_total_duration_overflow_are_rejected(): + plan = _standard_three_chunk_plan() + with pytest.raises(GuideTargetError, match="absolute_frame"): + resolve_guide_target(-1, plan) + with pytest.raises(GuideTargetError, match="outside visible range"): + resolve_guide_target(360, plan) + + +def test_physical_boundaries_are_owned_by_the_following_group(): + plan = _standard_three_chunk_plan() + assert resolve_guide_target(123, plan)["physical_group_index"] == 0 + assert resolve_guide_target(124, plan)["physical_group_index"] == 1 + assert resolve_guide_target(242, plan)["physical_group_index"] == 1 + assert resolve_guide_target(243, plan)["physical_group_index"] == 2 + + +def test_terminal_merge_uses_physical_group_mapping(): + plan = { + "target_frames": 360, + "decode_groups": [ + { + "logical_chunk_indices": [1], + "frame_start": 0, + "frame_stop": 124, + "total_frames": 124, + "trim_frames": 0, + "net_frames": 124, + "terminal_merged": False, + }, + { + "logical_chunk_indices": [2, 3], + "frame_start": 124, + "frame_stop": 362, + "total_frames": 260, + "trim_frames": 22, + "net_frames": 238, + "terminal_merged": True, + }, + ], + } + start = resolve_guide_target(124, plan) + logical_boundary = resolve_guide_target(243, plan) + final = resolve_guide_target(359, plan) + assert start["physical_group_index"] == 1 + assert start["logical_chunks"] == [2, 3] + assert start["resolved_frame_index"] == 22 + assert logical_boundary["physical_group_index"] == 1 + assert logical_boundary["resolved_frame_index"] == 141 + assert final["resolved_frame_index"] == 257 + assert final["resolved_frame_index"] < final["physical_frames"] + + +def test_contradictory_physical_group_is_rejected(): + plan = _standard_three_chunk_plan() + plan["chunks"][1]["frame_start"] = 120 + with pytest.raises(GuideTargetError, match="not contiguous"): + resolve_guide_target(124, plan) diff --git a/tests/test_v37_refine_schedule.py b/tests/test_v37_refine_schedule.py new file mode 100644 index 0000000..de29280 --- /dev/null +++ b/tests/test_v37_refine_schedule.py @@ -0,0 +1,119 @@ +from __future__ import annotations + +import pytest +import torch + +from ComfyUI_H3_Continuum_Join.v3.refine_schedule import ( + AUDIO_POLICY_LOCKED_PASSTHROUGH, + MODE_EXTERNAL, + MODE_FULL, + MODE_PARTIAL, + MODE_TAIL, + NOISE_MODE_VIDEO_RANDOM_AUDIO_ZERO, + RefineScheduleError, + make_external_schedule, + make_full_schedule, + make_partial_schedule, + make_tail_schedule, + resolve_refine_schedule, + sigma_hash, +) + + +BASE = torch.tensor( + [ + 0.86998779, + 0.85072654, + 0.82778585, + 0.80000001, + 0.76671618, + 0.72347587, + 0.66692579, + 0.59232169, + 0.48214287, + 0.30945560, + 0.0, + ], + dtype=torch.float32, +) + + +def test_external_preserves_the_exact_existing_sigmas_object(): + schedule = make_external_schedule(BASE) + resolved = resolve_refine_schedule(BASE, schedule) + assert schedule.sigmas is BASE + assert resolved is schedule + assert schedule.contract["mode"] == MODE_EXTERNAL + assert schedule.contract["sigma_hash"] == sigma_hash(BASE) + assert schedule.contract["evaluation_count"] == 10 + assert schedule.contract["noise_mode"] == NOISE_MODE_VIDEO_RANDOM_AUDIO_ZERO + assert schedule.contract["audio_policy"] == AUDIO_POLICY_LOCKED_PASSTHROUGH + + +def test_missing_schedule_is_external_compatibility(): + resolved = resolve_refine_schedule(BASE) + assert resolved.sigmas is BASE + assert resolved.contract["mode"] == MODE_EXTERNAL + + +def test_full_preserves_values_but_has_distinct_semantic_identity(): + external = make_external_schedule(BASE) + full = make_full_schedule(BASE) + assert full.sigmas is BASE + assert full.contract["mode"] == MODE_FULL + assert full.contract["sigma_hash"] == external.contract["sigma_hash"] + assert full.contract["schedule_hash"] != external.contract["schedule_hash"] + + +def test_tail_10_and_tail_6_are_exact_suffixes_of_the_baseline(): + tail10 = make_tail_schedule(BASE, evaluation_count=10) + tail6 = make_tail_schedule(BASE, evaluation_count=6) + assert tail10.sigmas is BASE + assert tail10.contract["mode"] == MODE_TAIL + assert tail10.contract["start_index"] == 0 + assert torch.equal(tail6.sigmas, BASE[4:]) + assert tail6.contract["start_index"] == 4 + assert tail6.contract["end_index"] == 10 + assert tail6.contract["evaluation_count"] == 6 + assert tail6.contract["start_sigma"] == pytest.approx(float(BASE[4])) + assert tail6.contract["end_sigma"] == 0.0 + + +def test_partial_uses_the_requested_inclusive_sigma_range(): + partial = make_partial_schedule(BASE, start_index=2, end_index=7) + assert partial.contract["mode"] == MODE_PARTIAL + assert partial.contract["evaluation_count"] == 5 + assert torch.equal(partial.sigmas, BASE[2:8]) + + +def test_schedule_rejects_a_different_source_even_when_shape_matches(): + schedule = make_tail_schedule(BASE, evaluation_count=6) + changed = BASE.clone() + changed[0] += 0.01 + with pytest.raises(RefineScheduleError, match="different source"): + resolve_refine_schedule(changed, schedule) + + +@pytest.mark.parametrize( + "value, message", + [ + (torch.tensor([1.0]), "at least two"), + (torch.tensor([0.0, 1.0]), "non-increasing"), + (torch.tensor([1.0, float("nan")]), "NaN or Inf"), + ], +) +def test_invalid_sigmas_are_rejected(value, message): + with pytest.raises(RefineScheduleError, match=message): + make_external_schedule(value) + + +@pytest.mark.parametrize("count", [0, 11, True]) +def test_invalid_tail_counts_are_rejected(count): + with pytest.raises(RefineScheduleError, match="evaluation_count"): + make_tail_schedule(BASE, evaluation_count=count) + + +@pytest.mark.parametrize("start, end", [(-1, 2), (2, 2), (2, 11)]) +def test_invalid_partial_ranges_are_rejected(start, end): + with pytest.raises(RefineScheduleError, match="outside"): + make_partial_schedule(BASE, start_index=start, end_index=end) diff --git a/tools/verify_runtime.py b/tools/verify_runtime.py index 0f5614d..bf1b7fb 100644 --- a/tools/verify_runtime.py +++ b/tools/verify_runtime.py @@ -69,6 +69,8 @@ def main() -> int: "H3ContinuumSamplerV34", "H3ContinuumSamplerV35", "H3ContinuumSamplerV36", + "H3ContinuumSamplerV37", + "H3ContinuumStillImageGuideV37", "H3ContinuumAssembleSeamV34", "H3ContinuumAssembleSeamV35", "H3ContinuumHiResFixV35", diff --git a/v2/nodes.py b/v2/nodes.py index 6ac03fa..978f6a9 100644 --- a/v2/nodes.py +++ b/v2/nodes.py @@ -322,6 +322,7 @@ class H3ContinuumSamplerV2: driving_audio_vae=None, reference_video_source=None, timeline_video_source=None, + guide_source=None, capture_refine_context=False, memory_attribution=False, prompt_conditioning_cache=False, @@ -398,6 +399,7 @@ class H3ContinuumSamplerV2: driving_audio_vae=driving_audio_vae, reference_video_source=reference_video_source, timeline_video_source=timeline_video_source, + guide_source=guide_source, capture_refine_context=bool(capture_refine_context), memory_attribution=bool(memory_attribution), prompt_conditioning_cache=bool(prompt_conditioning_cache), diff --git a/v2/sequence.py b/v2/sequence.py index 2e722a7..a08722c 100644 --- a/v2/sequence.py +++ b/v2/sequence.py @@ -22,7 +22,14 @@ from ..driving_audio import ( encode_driving_audio, slice_driving_audio_latent, ) -from ..model_patch import clone_model_for_chunk +from ..guide_timeline import ( + attach_still_image_guide, + combine_guide_identity, + encode_still_image_guide, + resolve_guide_for_physical_group, + validate_guide_visible_range, +) +from ..model_patch import LayoutValidationProfiler, clone_model_for_chunk from ..state import assert_context_unchanged, context_fingerprint, make_plan, select_context, validate_state from ..temporal import ( align_frame_count_up, @@ -219,6 +226,18 @@ def _atomic_terminal_prefix( return preserved, False +def _terminal_strategy_mismatch( + session: dict[str, Any] | None, + *, + merge_enabled: bool, +) -> bool: + """Reject only prefixes that will actually use Terminal Merge sampling.""" + if not merge_enabled or session is None: + return False + saved_strategy = str((session.get("settings") or {}).get("flf_execution", "")) + return saved_strategy != FLF_STRATEGY + + def _terminal_sampling_plan( *, chunks: int, @@ -384,7 +403,7 @@ def _attach_terminal_flf_keyframes( metadata["minimax_frame_count"] = int(frame_count) return conditioning -def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,sigmas:torch.Tensor,first_frame:torch.Tensor|None,last_frame:torch.Tensor|None,prompt_plan:dict[str,Any],width:int,height:int,continuity:str,base_seed:int,audio_continuity:bool,exact_total_duration:bool,diagnostics_mode:str,reroll_from_chunk:int,reroll_nonce:int,strict_compatibility:bool,debug:bool,seam_correction:str=SEAM_CORRECTION_OFF,enable_preview:bool=True,session:dict[str,Any]|None=None,initial_state:dict[str,Any]|None=None,latent_only:bool=False,reference_assets=None,reference_audio_source=None,reference_audio_vae=None,driving_audio_source=None,driving_audio_vae=None,reference_video_source=None,timeline_video_source=None,capture_refine_context:bool=False,memory_attribution:bool=False,prompt_conditioning_cache:bool=False,continuation_transport:str=REFERENCE_CONTEXT_V1,_memory_attribution_collector:Any=None): +def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,sigmas:torch.Tensor,first_frame:torch.Tensor|None,last_frame:torch.Tensor|None,prompt_plan:dict[str,Any],width:int,height:int,continuity:str,base_seed:int,audio_continuity:bool,exact_total_duration:bool,diagnostics_mode:str,reroll_from_chunk:int,reroll_nonce:int,strict_compatibility:bool,debug:bool,seam_correction:str=SEAM_CORRECTION_OFF,enable_preview:bool=True,session:dict[str,Any]|None=None,initial_state:dict[str,Any]|None=None,latent_only:bool=False,reference_assets=None,reference_audio_source=None,reference_audio_vae=None,driving_audio_source=None,driving_audio_vae=None,reference_video_source=None,timeline_video_source=None,guide_source=None,capture_refine_context:bool=False,memory_attribution:bool=False,prompt_conditioning_cache:bool=False,continuation_transport:str=REFERENCE_CONTEXT_V1,_memory_attribution_collector:Any=None): from ..conditioning import detect_conditioning_mode, conditioning_display_label from ..run_storage import get_active_run_storage storage_controller=get_active_run_storage() @@ -402,6 +421,8 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si from ..v3.memory_attribution import capture_attribution_fail_soft capture_memory=capture_attribution_fail_soft plan=validate_prompt_plan(prompt_plan); chunks=int(plan["chunks"]); chunk_seconds=float(plan["chunk_seconds"]); prompts=list(plan["prompts"]); prompt_hashes=list(plan["hashes"]); width,height=int(width),int(height) + visible_target_frames=int(round(chunks*chunk_seconds*FPS)) + validate_guide_visible_range(guide_source,target_frames=visible_target_frames) continuation_transport=str(continuation_transport) if continuation_transport not in CONTINUATION_TRANSPORTS: raise SequenceRuntimeError( @@ -455,23 +476,27 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si sequence_identity_hash=combine_driving_audio_identity(sequence_identity_hash,driving_audio_source) sequence_identity_hash=combine_reference_video_identity(sequence_identity_hash,reference_video_source) sequence_identity_hash=combine_timeline_video_identity(sequence_identity_hash,timeline_video_source) + sequence_identity_hash=combine_guide_identity(sequence_identity_hash,guide_source) if multi_chunk_flf: sequence_identity_hash=_flf_contract_identity(sequence_identity_hash) sequence_identity_hash=_continuation_transport_identity(sequence_identity_hash,continuation_transport) current_model_fingerprint=model_fingerprint(model,extra_wrapper_keys=("h3_continuum_join.apply_model.v1",)) if storage_controller is not None: - stored_session=storage_controller.prepare(model=model,model_fingerprint_value=current_model_fingerprint,clip=clip,video_vae=video_vae,sampler=sampler,sigmas=sigmas,prompt_plan=plan,width=width,height=height,chunk_seconds=chunk_seconds,continuity=continuity,audio_continuity=audio_continuity,base_seed=base_seed,reroll_from_chunk=reroll_from_chunk,reroll_nonce=reroll_nonce,first_frame_hash=assets.first_frame_hash,last_frame_hash=assets.last_frame_hash,identity_hash=sequence_identity_hash,strict_compatibility=strict_compatibility,existing_session=session,reference_contract=reference_assets.contract if reference_assets is not None else None,conditioning_mode=conditioning_mode,reference_audio_contract=reference_audio_source.contract if reference_audio_source is not None else None,reference_audio_vae=reference_audio_vae,driving_audio_contract=driving_audio_source.contract if driving_audio_source is not None else None,driving_audio_vae=driving_audio_vae,reference_video_contract=reference_video_source.contract if reference_video_source is not None else None,timeline_video_contract=timeline_video_source.contract if timeline_video_source is not None else None,execution_semantics=_terminal_execution_semantics(merge_enabled=terminal_merge_enabled,prompt_policy=terminal_prompt_policy,continuation_transport=continuation_transport)) + stored_session=storage_controller.prepare(model=model,model_fingerprint_value=current_model_fingerprint,clip=clip,video_vae=video_vae,sampler=sampler,sigmas=sigmas,prompt_plan=plan,width=width,height=height,chunk_seconds=chunk_seconds,continuity=continuity,audio_continuity=audio_continuity,base_seed=base_seed,reroll_from_chunk=reroll_from_chunk,reroll_nonce=reroll_nonce,first_frame_hash=assets.first_frame_hash,last_frame_hash=assets.last_frame_hash,identity_hash=sequence_identity_hash,strict_compatibility=strict_compatibility,existing_session=session,reference_contract=reference_assets.contract if reference_assets is not None else None,conditioning_mode=conditioning_mode,reference_audio_contract=reference_audio_source.contract if reference_audio_source is not None else None,reference_audio_vae=reference_audio_vae,driving_audio_contract=driving_audio_source.contract if driving_audio_source is not None else None,driving_audio_vae=driving_audio_vae,reference_video_contract=reference_video_source.contract if reference_video_source is not None else None,timeline_video_contract=timeline_video_source.contract if timeline_video_source is not None else None,guide_contract=guide_source.contract if guide_source is not None else None,execution_semantics=_terminal_execution_semantics(merge_enabled=terminal_merge_enabled,prompt_policy=terminal_prompt_policy,continuation_transport=continuation_transport)) reroll_nonce=storage_controller.effective_reroll_nonce if stored_session is not None: session=stored_session accelerators=accelerator_summary(model) if "Continuum APPLY_MODEL wrapper installed" not in accelerators: accelerators+="; Continuum APPLY_MODEL wrapper installed" + layout_validation_profiler=( + LayoutValidationProfiler(route_markers=accelerators) + if diagnostics_mode==DIAGNOSTICS_FULL + else None + ) effective_reroll_from_chunk=0 if storage_controller is not None and session is not None and bool((session.get("settings") or {}).get("run_storage_validated_prefix")) else int(reroll_from_chunk) preserved,reuse_notes=_preserved_prefix(session=session,prompt_hashes=prompt_hashes,chunks=chunks,reroll_from_chunk=effective_reroll_from_chunk,width=width,height=height,chunk_seconds=chunk_seconds,identity_hash=sequence_identity_hash,last_frame_hash=assets.last_frame_hash) - if multi_chunk_flf and session is not None: - saved_strategy=str((session.get("settings") or {}).get("flf_execution", "")) - if saved_strategy!=FLF_STRATEGY: - preserved=[] - reuse_notes.append("FLF chunk contract changed; regenerated the requested FLF sequence.") + if _terminal_strategy_mismatch(session,merge_enabled=terminal_merge_enabled): + preserved=[] + reuse_notes.append("FLF chunk contract changed; regenerated the requested FLF sequence.") if terminal_merge_enabled: preserved,atomic_reset=_atomic_terminal_prefix(preserved,chunks=chunks,reroll_from_chunk=int(reroll_from_chunk)) if atomic_reset: @@ -497,15 +522,24 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si if timeline_video_source is not None: reuse_notes.insert(0,f"Timeline Video conditioning: chunk-local slices, size={timeline_video_source.size_mode}, resolved={timeline_video_source.target_width}x{timeline_video_source.target_height}.") if timeline_video_warning: reuse_notes.append(timeline_video_warning) + if guide_source is not None: + reuse_notes.insert( + 0, + "Still Image Guide: absolute frame " + f"{guide_source.absolute_frame}; mode={guide_source.contract['mode']}; " + f"schema={guide_source.contract['schema_version']}.", + ) if session is not None: old_fingerprint=str(session.get("model_fingerprint","")) if old_fingerprint and old_fingerprint!=current_model_fingerprint: reuse_notes.append("model/accelerator fingerprint differs from the saved session; accepted chunks were kept") cache={} + guide_assets=None if len(preserved) None: ) +def _guide_image_map(value: Any) -> Mapping[int, torch.Tensor]: + if value is None: + return MappingProxyType({}) + if not isinstance(value, Mapping): + raise RefineContextError("guide_images must be a frame-to-IMAGE mapping") + output: dict[int, torch.Tensor] = {} + for frame_index, image in value.items(): + if type(frame_index) is not int or frame_index < 0: + raise RefineContextError("guide_images frame indices must be non-negative integers") + prepared = _optional_image(image, f"guide_images[{frame_index}]") + assert prepared is not None + output[frame_index] = prepared + return MappingProxyType(output) + + +def _validate_guide_images(value: Any, *, physical_frames: int) -> None: + if value is None: + return + if not isinstance(value, Mapping): + raise RefineContextError("refine group guide_images is invalid") + for frame_index, image in value.items(): + if type(frame_index) is not int or not 0 <= frame_index < physical_frames: + raise RefineContextError("refine group guide image frame is outside the physical group") + _validate_optional_image(image, f"guide_images[{frame_index}]") + + def make_refine_group( *, conditioning: Any, @@ -113,6 +140,7 @@ def make_refine_group( context_frames: int, first_image: torch.Tensor | None = None, last_image: torch.Tensor | None = None, + guide_images: Mapping[int, torch.Tensor] | None = None, ) -> dict[str, Any]: """Capture one physical First Pass sampling group's effective conditioning.""" @@ -138,7 +166,7 @@ def make_refine_group( raise RefineContextError("refine group physical clip index is invalid") if context_frames < 0: raise RefineContextError("refine group context frame count is invalid") - return { + output = { "group_id": group_id, "logical_chunks": chunks, "physical_frames": physical_frames, @@ -151,6 +179,10 @@ def make_refine_group( "first_image": _optional_image(first_image, "first_image"), "last_image": _optional_image(last_image, "last_image"), } + frozen_guides = _guide_image_map(guide_images) + if frozen_guides: + output["guide_images"] = frozen_guides + return output def make_refine_context( @@ -271,6 +303,10 @@ def validate_refine_context( _validate_frozen_conditioning(group.get("conditioning"), group_id=expected_id) _validate_optional_image(group.get("first_image"), "first_image") _validate_optional_image(group.get("last_image"), "last_image") + _validate_guide_images( + group.get("guide_images"), + physical_frames=int(group["physical_frames"]), + ) if assembly_plan is not None: if not isinstance(assembly_plan, Mapping): @@ -448,6 +484,7 @@ def adapt_group_conditioning( "keyframes_resized": 0, "keyframes_reencoded": 0, "keyframes_latent_fallback": 0, + "guide_keyframes_reencoded": 0, "context_refs_resized": 0, } output: list[list[Any]] = [] @@ -474,7 +511,12 @@ def adapt_group_conditioning( frame_index = int(keyframe.get("resolved_frame_index", -1)) image = None crop = "disabled" - if frame_index == 0: + if bool(keyframe.get(MARK_STILL_IMAGE_GUIDE)): + guide_images = group.get("guide_images") + if isinstance(guide_images, Mapping): + image = guide_images.get(frame_index) + crop = "center" + elif frame_index == 0: image = group.get("first_image") elif frame_index == physical_frames - 1: image = group.get("last_image") @@ -488,6 +530,8 @@ def adapt_group_conditioning( video_vae=video_vae, ) stats["keyframes_reencoded"] += 1 + if bool(keyframe.get(MARK_STILL_IMAGE_GUIDE)): + stats["guide_keyframes_reencoded"] += 1 else: keyframe["latent"] = _resize_latent( latent, diff --git a/v3/refine_schedule.py b/v3/refine_schedule.py new file mode 100644 index 0000000..00a8b53 --- /dev/null +++ b/v3/refine_schedule.py @@ -0,0 +1,214 @@ +"""Versioned, UI-independent sigma contracts for Continuum refinement. + +The public Second Pass SIGMAS socket remains authoritative. These helpers attach +meaning to that tensor without recreating it: External and Full retain the exact +input object, while Tail and Partial return views into the same source values. +""" + +from __future__ import annotations + +import hashlib +import json +from dataclasses import dataclass +from types import MappingProxyType +from typing import Any, Mapping + +import torch + + +MAGIC = "H3_CONTINUUM_REFINE_SCHEDULE" +SCHEMA_VERSION = 1 + +MODE_EXTERNAL = "external" +MODE_FULL = "full" +MODE_TAIL = "tail" +MODE_PARTIAL = "partial" +MODES = (MODE_EXTERNAL, MODE_FULL, MODE_TAIL, MODE_PARTIAL) + +NOISE_MODE_VIDEO_RANDOM_AUDIO_ZERO = "video_random_mask_1_audio_zero_mask_0" +AUDIO_POLICY_LOCKED_PASSTHROUGH = "locked_first_pass_bit_exact_passthrough" + + +class RefineScheduleError(ValueError): + """Raised when a refinement schedule cannot safely describe its SIGMAS.""" + + +@dataclass(frozen=True) +class RefineSchedule: + """One validated effective SIGMAS tensor and its serializable identity.""" + + sigmas: torch.Tensor + contract: Mapping[str, Any] + source_sigma_hash: str + + +def _validate_sigmas(sigmas: Any, *, name: str) -> torch.Tensor: + if not torch.is_tensor(sigmas) or sigmas.ndim != 1 or sigmas.numel() < 2: + raise RefineScheduleError(f"{name} must be a one-dimensional tensor with at least two values") + detached = sigmas.detach() + if not bool(torch.isfinite(detached.float()).all().item()): + raise RefineScheduleError(f"{name} contains NaN or Inf") + values = detached.float().to(device="cpu") + if bool((values[1:] > values[:-1]).any().item()): + raise RefineScheduleError(f"{name} must be monotonically non-increasing") + return sigmas + + +def sigma_hash(sigmas: torch.Tensor) -> str: + """Hash dtype, shape, and exact tensor bytes without changing the input.""" + + _validate_sigmas(sigmas, name="sigmas") + cpu = sigmas.detach().to(device="cpu").contiguous() + payload = cpu.view(torch.uint8).numpy().tobytes() + digest = hashlib.sha256() + digest.update(str(cpu.dtype).encode("ascii")) + digest.update(b"|") + digest.update(str(tuple(int(value) for value in cpu.shape)).encode("ascii")) + digest.update(b"|") + digest.update(payload) + return digest.hexdigest() + + +def _schedule_identity(contract: Mapping[str, Any]) -> str: + payload = { + key: value + for key, value in contract.items() + if key != "schedule_hash" + } + encoded = json.dumps(payload, sort_keys=True, separators=(",", ":")).encode("utf-8") + return hashlib.sha256(encoded).hexdigest() + + +def _build_schedule( + source_sigmas: torch.Tensor, + *, + mode: str, + start_index: int, + end_index: int, +) -> RefineSchedule: + source = _validate_sigmas(source_sigmas, name="source_sigmas") + canonical_mode = str(mode).lower() + if canonical_mode not in MODES: + raise RefineScheduleError(f"unsupported refine schedule mode {mode!r}") + source_evaluations = int(source.numel()) - 1 + if type(start_index) is not int or type(end_index) is not int: + raise RefineScheduleError("schedule indices must be integers") + if start_index < 0 or end_index <= start_index or end_index > source_evaluations: + raise RefineScheduleError( + f"schedule range {start_index}:{end_index} is outside 0:{source_evaluations}" + ) + + if start_index == 0 and end_index == source_evaluations: + effective = source + else: + effective = source[start_index : end_index + 1] + _validate_sigmas(effective, name="effective sigmas") + effective_hash = sigma_hash(effective) + source_hash = sigma_hash(source) + values = tuple(float(value) for value in effective.detach().to(device="cpu").tolist()) + contract: dict[str, Any] = { + "magic": MAGIC, + "schema_version": SCHEMA_VERSION, + "mode": canonical_mode, + "sigma_values": values, + "sigma_hash": effective_hash, + "source_sigma_hash": source_hash, + "start_sigma": values[0], + "end_sigma": values[-1], + "evaluation_count": len(values) - 1, + "source_evaluation_count": source_evaluations, + "start_index": start_index, + "end_index": end_index, + "noise_mode": NOISE_MODE_VIDEO_RANDOM_AUDIO_ZERO, + "audio_policy": AUDIO_POLICY_LOCKED_PASSTHROUGH, + } + contract["schedule_hash"] = _schedule_identity(contract) + return RefineSchedule( + sigmas=effective, + contract=MappingProxyType(contract), + source_sigma_hash=source_hash, + ) + + +def make_external_schedule(sigmas: torch.Tensor) -> RefineSchedule: + evaluations = int(_validate_sigmas(sigmas, name="sigmas").numel()) - 1 + return _build_schedule( + sigmas, + mode=MODE_EXTERNAL, + start_index=0, + end_index=evaluations, + ) + + +def make_full_schedule(sigmas: torch.Tensor) -> RefineSchedule: + evaluations = int(_validate_sigmas(sigmas, name="sigmas").numel()) - 1 + return _build_schedule( + sigmas, + mode=MODE_FULL, + start_index=0, + end_index=evaluations, + ) + + +def make_tail_schedule( + sigmas: torch.Tensor, + *, + evaluation_count: int, +) -> RefineSchedule: + source_evaluations = int(_validate_sigmas(sigmas, name="sigmas").numel()) - 1 + if type(evaluation_count) is not int or not 1 <= evaluation_count <= source_evaluations: + raise RefineScheduleError( + f"tail evaluation_count must be between 1 and {source_evaluations}" + ) + return _build_schedule( + sigmas, + mode=MODE_TAIL, + start_index=source_evaluations - evaluation_count, + end_index=source_evaluations, + ) + + +def make_partial_schedule( + sigmas: torch.Tensor, + *, + start_index: int, + end_index: int, +) -> RefineSchedule: + return _build_schedule( + sigmas, + mode=MODE_PARTIAL, + start_index=start_index, + end_index=end_index, + ) + + +def resolve_refine_schedule( + sigmas: torch.Tensor, + schedule: RefineSchedule | None = None, +) -> RefineSchedule: + """Return External compatibility or validate an explicit internal schedule.""" + + source = _validate_sigmas(sigmas, name="sigmas") + if schedule is None: + return make_external_schedule(source) + if not isinstance(schedule, RefineSchedule): + raise RefineScheduleError("refine_schedule must be a RefineSchedule") + if sigma_hash(source) != schedule.source_sigma_hash: + raise RefineScheduleError("refine_schedule was derived from different source SIGMAS") + rebuilt = _build_schedule( + source, + mode=str(schedule.contract.get("mode", "")), + start_index=int(schedule.contract.get("start_index", -1)), + end_index=int(schedule.contract.get("end_index", -1)), + ) + if rebuilt.contract["schedule_hash"] != schedule.contract.get("schedule_hash"): + raise RefineScheduleError("refine_schedule contract identity is inconsistent") + return schedule + + +def serializable_schedule_contract(schedule: RefineSchedule) -> dict[str, Any]: + """Return a mutable JSON-safe copy for Assembly/diagnostic identity.""" + + if not isinstance(schedule, RefineSchedule): + raise RefineScheduleError("schedule must be a RefineSchedule") + return dict(schedule.contract) diff --git a/v3/second_pass.py b/v3/second_pass.py index c7c796b..2f712b0 100644 --- a/v3/second_pass.py +++ b/v3/second_pass.py @@ -21,6 +21,12 @@ from .refine_context import ( adapt_group_conditioning, validate_refine_context, ) +from .refine_schedule import ( + RefineSchedule, + RefineScheduleError, + resolve_refine_schedule, + serializable_schedule_contract, +) from .refine_sampling import sample_refine_chunk @@ -387,10 +393,17 @@ def run_second_pass_groups( clone_model_fn=None, validate_refine_context_fn=None, adapt_group_conditioning_fn=None, + refine_schedule: RefineSchedule | None = None, ) -> tuple[list[dict[str, Any]], list[Any], dict[str, Any], str]: """Refine complete physical groups while preserving first-pass audio exactly.""" validation = validate_second_pass_inputs(video_latents, audio_latents, assembly_plan) + try: + resolved_schedule = resolve_refine_schedule(sigmas, refine_schedule) + except RefineScheduleError as exc: + raise SecondPassContractError(f"refine schedule is invalid: {exc}") from exc + effective_sigmas = resolved_schedule.sigmas + schedule_contract = serializable_schedule_contract(resolved_schedule) groups = _contract_groups(assembly_plan) latent_builder = latent_builder or latent_from_cpu sample_fn = sample_fn or sample_refine_chunk @@ -424,7 +437,7 @@ def run_second_pass_groups( conditioning=conditioning, latent=nested_latent, sampler=sampler, - sigmas=sigmas, + sigmas=effective_sigmas, seed=physical_seed, enable_preview=bool(enable_preview), ) @@ -456,6 +469,7 @@ def run_second_pass_groups( f"{group_index + 1} target conditioning: " f"keyframes_resized={int(adaptation_stats.get('keyframes_resized', 0))}, " f"keyframes_reencoded={int(adaptation_stats.get('keyframes_reencoded', 0))}, " + f"guide_keyframes_reencoded={int(adaptation_stats.get('guide_keyframes_reencoded', 0))}, " f"context_refs_resized={int(adaptation_stats.get('context_refs_resized', 0))}" ) group_report_lines.extend( @@ -484,7 +498,14 @@ def run_second_pass_groups( "refine_context is available.", f"Physical groups: {validation['physical_group_count']}.", "Sampling contract: video random noise/mask=1; audio zero noise/mask=0; " - "workflow SIGMAS are applied directly by Core.", + "the resolved RefineSchedule SIGMAS are applied directly by Core.", + "RefineSchedule: " + f"schema={schedule_contract['schema_version']}, " + f"mode={schedule_contract['mode']}, " + f"evaluations={schedule_contract['evaluation_count']}, " + f"start_sigma={schedule_contract['start_sigma']}, " + f"end_sigma={schedule_contract['end_sigma']}, " + f"sigma_hash={schedule_contract['sigma_hash']}.", *prepared["warnings"], *group_report_lines, ] @@ -505,6 +526,8 @@ def run_second_pass_groups( contract["refine_group_seeds"] = group_seeds contract["audio_output"] = "bit_exact_first_pass_passthrough" contract["audio_sampling"] = "zero_noise_mask_locked" + contract["refine_schedule"] = schedule_contract + contract["refine_schedule_identity"] = schedule_contract["schedule_hash"] report_lines.append( "Audio output: first-pass physical audio LATENT objects returned bit-exact; " "temporary refined audio discarded." diff --git a/v3/second_pass_nodes.py b/v3/second_pass_nodes.py index a7f8ca5..3b492c3 100644 --- a/v3/second_pass_nodes.py +++ b/v3/second_pass_nodes.py @@ -78,6 +78,7 @@ class H3ContinuumSecondPassV35: refine_seed, refine_context=None, video_vae=None, + refine_schedule=None, ): return run_second_pass_groups( model=_single_list_input("model", model), @@ -98,6 +99,7 @@ class H3ContinuumSecondPassV35: if video_vae is None else _single_list_input("video_vae", video_vae) ), + refine_schedule=refine_schedule, ) diff --git a/version.py b/version.py index 2f7cb09..f50b571 100644 --- a/version.py +++ b/version.py @@ -1,6 +1,6 @@ """Package version and public schema identifiers.""" -PACKAGE_VERSION = "3.6.1" +PACKAGE_VERSION = "3.7.0" STATE_SCHEMA_VERSION = 1 PLAN_SCHEMA_VERSION = 1 PUBLIC_API_VERSION = 3 diff --git a/web/project_id.js b/web/project_id.js index 006a3e5..bac46a2 100644 --- a/web/project_id.js +++ b/web/project_id.js @@ -8,6 +8,7 @@ const V34_NODE_CLASS = "H3ContinuumSamplerV34"; const V34_ASSEMBLE_SEAM_NODE_CLASS = "H3ContinuumAssembleSeamV34"; const V35_NODE_CLASS = "H3ContinuumSamplerV35"; const V36_NODE_CLASS = "H3ContinuumSamplerV36"; +const V37_NODE_CLASS = "H3ContinuumSamplerV37"; const V35_ASSEMBLE_SEAM_NODE_CLASS = "H3ContinuumAssembleSeamV35"; const PROJECT_WIDGET = "project_id"; const LEGACY_RUN_NAME_WIDGET = "run_name"; @@ -165,13 +166,30 @@ function attachRefresh(widget, key, refresh) { widget[key] = true; } +function normalizeRunStorageState(node, apiInputs = null) { + const storageWidget = findWidget(node, RUN_STORAGE_WIDGET); + const storageEnabled = storageWidget?.value === "Save + Auto Resume"; + if (storageEnabled) { + return true; + } + const regenerateWidget = findWidget(node, REGENERATE_WIDGET); + const nonceWidget = findWidget(node, REROLL_NONCE_WIDGET); + if (regenerateWidget) regenerateWidget.value = "Auto"; + if (nonceWidget) nonceWidget.value = 0; + if (apiInputs) { + apiInputs[REGENERATE_WIDGET] = "Auto"; + apiInputs[REROLL_NONCE_WIDGET] = 0; + } + return false; +} + function configureConditionalWidgets(node) { const storageWidget = findWidget(node, RUN_STORAGE_WIDGET); const regenerateWidget = findWidget(node, REGENERATE_WIDGET); const nonceWidget = findWidget(node, REROLL_NONCE_WIDGET); const runNameWidget = findWidget(node, LEGACY_RUN_NAME_WIDGET); const refresh = () => { - const storageEnabled = storageWidget?.value === "Save + Auto Resume"; + const storageEnabled = normalizeRunStorageState(node); const explicitRegeneration = storageEnabled && regenerateWidget?.value !== "Auto" && Number.parseInt(String(regenerateWidget?.value).replace(/^Chunk\s+/, ""), 10) > 0; @@ -229,19 +247,20 @@ function configureNode(node) { const isV34 = node.comfyClass === V34_NODE_CLASS; const isV35 = node.comfyClass === V35_NODE_CLASS; const isV36 = node.comfyClass === V36_NODE_CLASS; - if (!isProduction && !isTimeline && !isV34 && !isV35 && !isV36) { + const isV37 = node.comfyClass === V37_NODE_CLASS; + if (!isProduction && !isTimeline && !isV34 && !isV35 && !isV36 && !isV37) { configureAssembler(node); return null; } const projectWidget = findWidget(node, PROJECT_WIDGET); - if (isProduction || isV34 || isV35 || isV36) { + if (isProduction || isV34 || isV35 || isV36 || isV37) { if (projectWidget && !String(projectWidget.value || "").trim()) { projectWidget.value = createProjectId(); } removeUnusedInput(node, PROMPT_OVERRIDES_INPUT); } applyRuntimeSettings(node); - if (isV35 || isV36) { + if (isV35 || isV36 || isV37) { normalizeReferenceAudioLabels(node); } hidePersistentWidget(findWidget(node, "diagnostics")); @@ -319,7 +338,9 @@ app.registerExtension({ || node.comfyClass === V34_NODE_CLASS || node.comfyClass === V35_NODE_CLASS || node.comfyClass === V36_NODE_CLASS + || node.comfyClass === V37_NODE_CLASS ) { + normalizeRunStorageState(node, apiNode.inputs); apiNode.inputs.diagnostics = settingValue(SETTINGS.detailedReport, false) ? "Detailed Report" : "Basic";