{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/arxiv-2604-18215","title":"Memorize When Needed: Decoupled Memory Control for Spatially Consistent Long-Horizon Video Generation","arxiv_id":"2604.18215","date":"2026-04-20","proceeding":null,"authors":["Yanjun Guo","Zhengqiang Zhang","Pengfei Wang","Xinyue Liang","Zhiyuan Ma","Lei Zhang"],"abstract":"Spatially consistent long-horizon video generation aims to maintain temporal and spatial consistency along predefined camera trajectories. Existing methods mostly entangle memory modeling with video generation, leading to inconsistent content during scene revisits and diminished generative capacity when exploring novel regions, even trained on extensive annotated data. To address these limitations, we propose a decoupled framework that separates memory conditioning from generation. Our approach significantly reduces training costs while simultaneously enhancing spatial consistency and preserving the generative capacity for novel scene exploration. Specifically, we employ a lightweight, independent memory branch to learn precise spatial consistency from historical observation. We first introduce a hybrid memory representation to capture complementary temporal and spatial cues from generated frames, then leverage a per-frame cross-attention mechanism to ensure each frame is conditioned exclusively on the most spatially relevant historical information, which is injected into the generative model to ensure spatial consistency. When generating new scenes, a camera-aware gating mechanism is proposed to mediate the interaction between memory and generation modules, enabling memory conditioning only when meaningful historical references exist. Compared with the existing method, our method is highly data-efficient, yet the experiments demonstrate that our approach achieves state-of-the-art performance in terms of both visual quality and spatial consistency.","url_abs":"https://arxiv.org/abs/2604.18215","url_pdf":"https://arxiv.org/pdf/2604.18215","source":{"archive":null,"snapshot":"2025-07-28","note":"not in the Papers with Code archive (frozen at the snapshot)","row_kind":"graph","title_abstract_authors_date":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)"},"code_links":[],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2604.18215","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2604.18215"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"mentioned_in_github":null,"is_official":null,"provenance":"deterministic:regex_extraction","mentioned_in_paper":null,"url":"https://github.com/iguoyanjun/Memorize-When-Needed","reach":null}],"summary":{"ran_draft_wrong":1,"ran_violates":1,"ran_fixture":1,"unverified":16},"by_repo_kind":{"found_in_text":{"samples":19,"ran":3,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":19,"samples":[{"code_sha256_prefix":"22b1f260da28f6a5","entry":"retrieve_timesteps","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"pipeline.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/pipeline.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"22b1f260da28f6a5"}},{"code_sha256_prefix":"dc160d63c5846f4a","entry":"rope_params","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/controlnets/wan_transformer_dual.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/controlnets/wan_transformer_dual.py","link_basis":"plan_row","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"dc160d63c5846f4a"}},{"code_sha256_prefix":"e34a97853e924d88","entry":"sinusoidal_embedding_1d","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/controlnets/wan_transformer_dual.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/controlnets/wan_transformer_dual.py","link_basis":"plan_row","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e34a97853e924d88"}},{"code_sha256_prefix":"c0487d5566533bde","entry":"attention","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/wan_modules/attention_utils.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/wan_modules/attention_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c0487d5566533bde"}},{"code_sha256_prefix":"8b0ccead2e4ce95f","entry":"build_controlnet_token_mask","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"pipeline.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/pipeline.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"8b0ccead2e4ce95f"}},{"code_sha256_prefix":"798aecf07ae276dd","entry":"build_reference_frames","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"infer.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/infer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"798aecf07ae276dd"}},{"code_sha256_prefix":"06338ab44c6754a4","entry":"color_transfer","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/utils/utils.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/utils/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"06338ab44c6754a4"}},{"code_sha256_prefix":"92f121bb438f3774","entry":"filter_kwargs","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"infer.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/infer.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"92f121bb438f3774"}},{"code_sha256_prefix":"fbc3e873361f20d5","entry":"filter_kwargs","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/utils/utils.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/utils/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"fbc3e873361f20d5"}},{"code_sha256_prefix":"7ea44a4680b76539","entry":"flash_attention","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/wan_modules/attention_utils.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/wan_modules/attention_utils.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7ea44a4680b76539"}},{"code_sha256_prefix":"1532dbb1d28a2c99","entry":"get_sampling_sigmas","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/utils/fm_solvers.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/utils/fm_solvers.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1532dbb1d28a2c99"}},{"code_sha256_prefix":"406364af353a424a","entry":"get_width_and_height_from_image_and_base_resolution","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/utils/utils.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/utils/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"406364af353a424a"}},{"code_sha256_prefix":"5485127438111d03","entry":"mat3_to_quat_wxyz","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"dataload/utils.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/dataload/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5485127438111d03"}},{"code_sha256_prefix":"3493f2b0b7ba5d3b","entry":"orthonormalize_R","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"dataload/utils.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/dataload/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3493f2b0b7ba5d3b"}},{"code_sha256_prefix":"2001736e8a6a9441","entry":"quat_wxyz_to_mat3","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"dataload/utils.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/dataload/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2001736e8a6a9441"}},{"code_sha256_prefix":"6e301fe216cd0f77","entry":"ray_condition","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/controlnets/wan_controlnet_camera.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/controlnets/wan_controlnet_camera.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6e301fe216cd0f77"}},{"code_sha256_prefix":"ddf3a7a391972394","entry":"resize_mask","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"pipeline.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/pipeline.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"ddf3a7a391972394"}},{"code_sha256_prefix":"3eeae6ab9b822c6c","entry":"retrieve_timesteps","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/utils/fm_solvers.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/utils/fm_solvers.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3eeae6ab9b822c6c"}},{"code_sha256_prefix":"d81381b327c76edd","entry":"zero_module","repo":"iguoyanjun/Memorize-When-Needed","repo_kind":"found_in_text","path":"models/controlnets/wan_controlnet_camera.py","file_url":"https://github.com/iguoyanjun/Memorize-When-Needed/blob/HEAD/models/controlnets/wan_controlnet_camera.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"d81381b327c76edd"}}]},"arxiv_metadata":{"licence":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)","fields":["title","abstract","authors","date"],"primary_category":"cs.CV","source":"arxiv_2026.jsonl"},"syntology_extracted_results":null}