diff --git a/.gitattributes b/.gitattributes index 1556d4360852411424f1ffe46af31ba52b0add07..b79d23a2bca83d32072c02c548200d228d90ac72 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14323,3 +14323,19 @@ results/worldmem-baseline-evals/matrix-game2-diagnostics/diagnostic_i2v_original results/worldmem-baseline-evals/matrix-game2-diagnostics/diagnostic_i2v_weighted_job85088_task4/case0_i2v_weighted.jpg filter=lfs diff=lfs merge=lfs -text results/worldmem-baseline-evals/matrix-game2-diagnostics/diagnostic_i2v_weighted_job85088_task4/case1_i2v_weighted.jpg filter=lfs diff=lfs merge=lfs -text results/worldmem-baseline-evals/matrix-game2-diagnostics/diagnostic_wan_oracle_job85088_task0/case1_wan_oracle.jpg filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/demo.mp4 filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/demo_icon.mp4 filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/comparison.jpg filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/demo.mp4 filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/demo_icon.mp4 filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/comparison.jpg filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/demo.mp4 filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/demo_icon.mp4 filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/samples.jpg filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/comparison.jpg filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/comparison.jpg filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/demo.mp4 filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/demo_icon.mp4 filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/comparison.jpg filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/demo.mp4 filter=lfs diff=lfs merge=lfs -text +results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/demo_icon.mp4 filter=lfs diff=lfs merge=lfs -text diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/comparison.jpg b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/comparison.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d3475f90d42cf52901085bf4ce0b812e2f5f4c10 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/comparison.jpg differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/comparison.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/comparison.json new file mode 100644 index 0000000000000000000000000000000000000000..aee79444d615c6f7d66476a611cf4e545ad10ee5 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/comparison.json @@ -0,0 +1,81 @@ +{ + "case": "comparison", + "raw_rgb_psnr": [ + 28.761943817138672, + 24.894990921020508, + 5.066094875335693, + 6.884883880615234, + 7.142206192016602, + 7.228761196136475, + 7.280294895172119, + 7.196128845214844, + 7.207036972045898, + 7.207610130310059, + 7.2647624015808105, + 7.177729606628418, + 7.162692546844482, + 7.2452826499938965, + 7.280104637145996, + 7.2675628662109375, + 7.268505096435547, + 7.322355270385742, + 7.28434944152832, + 7.270142555236816, + 7.088680267333984, + 6.997251510620117, + 6.956180572509766, + 7.0359296798706055 + ], + "raw_rgb_mse": [ + 0.0013298585545271635, + 0.0032396710012108088, + 0.3114515542984009, + 0.20488570630550385, + 0.19309870898723602, + 0.18928833305835724, + 0.18705551326274872, + 0.1907159984111786, + 0.19023756682872772, + 0.19021247327327728, + 0.1877257078886032, + 0.1915256828069687, + 0.1921899914741516, + 0.18856962025165558, + 0.18706370890140533, + 0.18760469555854797, + 0.18756400048732758, + 0.18525265157222748, + 0.186880961060524, + 0.18749330937862396, + 0.19549334049224854, + 0.1996525377035141, + 0.20154961943626404, + 0.19788235425949097 + ], + "mean_rgb": [ + 0.7190113663673401, + 0.7229689359664917, + 0.19768567383289337, + 0.296479195356369, + 0.30714768171310425, + 0.31132906675338745, + 0.31336742639541626, + 0.3084028661251068, + 0.3105626106262207, + 0.3106946647167206, + 0.3127269446849823, + 0.3085455596446991, + 0.30667993426322937, + 0.3099704384803772, + 0.31143423914909363, + 0.31037086248397827, + 0.31108224391937256, + 0.3149312436580658, + 0.3144523501396179, + 0.31461331248283386, + 0.30496296286582947, + 0.3001496493816376, + 0.2973284423351288, + 0.30110853910446167 + ] +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/demo.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..cc771abdafa81bcc3f4ded29e6d342f023a24d10 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/demo.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6660c7b9630cb1ee296a5def8c1279f56450658d5ebe93c0efe8e9180d495932 +size 105287 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/demo_icon.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/demo_icon.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..32602a789f026ccf0b7660d138b209c7b05f7ccd --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/demo_icon.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:acd8d7516b9a9a9ef6382b590ef3979b2d462592a112869f6a5d1a1043cf9f70 +size 109197 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/input.png b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/input.png new file mode 100644 index 0000000000000000000000000000000000000000..3575844c2a8079d439ece74b50a874c10bbc32f6 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/input.png differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/inputs.npz b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/inputs.npz new file mode 100644 index 0000000000000000000000000000000000000000..9c075a1c3e7d55459d3371b66ffd0048f6f93d23 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case0/inputs.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:493fc4dd35246cc265ebffe2892af27a49cb3021a298008755a8cf455b536125 +size 952269 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/comparison.jpg b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/comparison.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5df6fbc46ed09eb6405d48d7e9778f2a0baf846b --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/comparison.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:37a2ea71f84babf1a4cca4c50eb05aa85e71830125f024081fd17f39675529ae +size 165055 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/comparison.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/comparison.json new file mode 100644 index 0000000000000000000000000000000000000000..251027d1d4d87980c1bf72bb8ab7f3ec6fdca5aa --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/comparison.json @@ -0,0 +1,81 @@ +{ + "case": "comparison", + "raw_rgb_psnr": [ + 19.81435775756836, + 18.266035079956055, + 17.720809936523438, + 17.051300048828125, + 17.8521785736084, + 17.96320152282715, + 17.770442962646484, + 17.66672706604004, + 17.461271286010742, + 17.219820022583008, + 17.17270851135254, + 17.01397132873535, + 16.4091739654541, + 16.703092575073242, + 17.036758422851562, + 16.95575523376465, + 16.949073791503906, + 16.948787689208984, + 16.964191436767578, + 17.009931564331055, + 16.958953857421875, + 16.964096069335938, + 16.84088134765625, + 16.837522506713867 + ], + "raw_rgb_mse": [ + 0.010436725802719593, + 0.014907212927937508, + 0.01690126210451126, + 0.019718321040272713, + 0.016397668048739433, + 0.01598379760980606, + 0.016709202900528908, + 0.01711304485797882, + 0.01794208399951458, + 0.018967844545841217, + 0.01917472667992115, + 0.019888538867235184, + 0.02286033146083355, + 0.021364402025938034, + 0.019784456118941307, + 0.02015693485736847, + 0.020187973976135254, + 0.020189296454191208, + 0.02011781372129917, + 0.019907046109437943, + 0.020142091438174248, + 0.020118258893489838, + 0.0206972137093544, + 0.02071322314441204 + ], + "mean_rgb": [ + 0.7137359976768494, + 0.7148902416229248, + 0.7157489061355591, + 0.7161552906036377, + 0.713788628578186, + 0.7127888202667236, + 0.7122524976730347, + 0.7112450003623962, + 0.7104371786117554, + 0.7100856900215149, + 0.7079524397850037, + 0.7049611210823059, + 0.700785756111145, + 0.7041963934898376, + 0.7078825831413269, + 0.7077915668487549, + 0.7052977085113525, + 0.7040800452232361, + 0.7037867903709412, + 0.7034406065940857, + 0.7064051628112793, + 0.7068390846252441, + 0.7078206539154053, + 0.7080984115600586 + ] +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/demo.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0d072e178ea34e5073929d01c50295d261c84dd2 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/demo.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c36d9d54461a4f2cfde284402e002e69b0f680afde385beeb28e13bf8663f9a3 +size 123910 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/demo_icon.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/demo_icon.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..7b21cef24ac305d5bdd062afc7af64f6d99d91e2 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/demo_icon.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bbf31f6a1796c834d4122b2c99469c92c9cc5dc129dd1659f03727fe4e4e3b74 +size 127119 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/input.png b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/input.png new file mode 100644 index 0000000000000000000000000000000000000000..a240efc2cac61bce8c2f601e02d0eb3207816689 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/input.png differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/inputs.npz b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/inputs.npz new file mode 100644 index 0000000000000000000000000000000000000000..32b512a4e66b60c335e58aaed28925b84544f4cb --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/case1/inputs.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:000846f182a7383bde76fede303b37ca054efd047e17d6f941aeb95bd24cb7e5 +size 951982 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/complete.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/complete.json new file mode 100644 index 0000000000000000000000000000000000000000..776d63197fb8e94e961a6ed416536c218e84b85f --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/complete.json @@ -0,0 +1 @@ +{"mode": "demo_actions", "complete": true} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/inference.py b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/inference.py new file mode 100644 index 0000000000000000000000000000000000000000..f4df03bda84a07a365507a5146938effb5352ffe --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/inference.py @@ -0,0 +1,169 @@ +import os +import argparse +import torch +import numpy as np + +from omegaconf import OmegaConf +from torchvision.transforms import v2 +from diffusers.utils import load_image +from einops import rearrange +from pipeline import CausalInferencePipeline +from wan.vae.wanx_vae import get_wanx_vae_wrapper +from demo_utils.vae_block3 import VAEDecoderWrapper +from utils.visualize import process_video +from utils.misc import set_seed +from utils.conditions import * +from utils.wan_wrapper import WanDiffusionWrapper +from safetensors.torch import load_file + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("--config_path", type=str, default="configs/inference_yaml/inference_universal.yaml", help="Path to the config file") + parser.add_argument("--checkpoint_path", type=str, default="", help="Path to the checkpoint") + parser.add_argument("--img_path", type=str, default="demo_images/universal/0000.png", help="Path to the image") + parser.add_argument("--output_folder", type=str, default="outputs/", help="Output folder") + parser.add_argument("--num_output_frames", type=int, default=150, + help="Number of output latent frames") + parser.add_argument("--seed", type=int, default=0, help="Random seed") + parser.add_argument("--pretrained_model_path", type=str, default="Matrix-Game-2.0", help="Path to the VAE model folder") + args = parser.parse_args() + return args + +class InteractiveGameInference: + def __init__(self, args): + self.args = args + self.device = torch.device("cuda") + self.weight_dtype = torch.bfloat16 + + self._init_config() + self._init_models() + + self.frame_process = v2.Compose([ + v2.Resize(size=(352, 640), antialias=True), + v2.ToTensor(), + v2.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]), + ]) + + def _init_config(self): + self.config = OmegaConf.load(self.args.config_path) + + def _init_models(self): + # Initialize pipeline + generator = WanDiffusionWrapper( + **getattr(self.config, "model_kwargs", {}), is_causal=True) + current_vae_decoder = VAEDecoderWrapper() + vae_state_dict = torch.load(os.path.join(self.args.pretrained_model_path, "Wan2.1_VAE.pth"), map_location="cpu") + decoder_state_dict = {} + for key, value in vae_state_dict.items(): + if 'decoder.' in key or 'conv2' in key: + decoder_state_dict[key] = value + current_vae_decoder.load_state_dict(decoder_state_dict) + current_vae_decoder.to(self.device, torch.float16) + current_vae_decoder.requires_grad_(False) + current_vae_decoder.eval() + current_vae_decoder.compile(mode="max-autotune-no-cudagraphs") + pipeline = CausalInferencePipeline(self.config, generator=generator, vae_decoder=current_vae_decoder) + if self.args.checkpoint_path: + print("Loading Pretrained Model...") + state_dict = load_file(self.args.checkpoint_path) + pipeline.generator.load_state_dict(state_dict) + + self.pipeline = pipeline.to(device=self.device, dtype=self.weight_dtype) + self.pipeline.vae_decoder.to(torch.float16) + + vae = get_wanx_vae_wrapper(self.args.pretrained_model_path, torch.float16) + vae.requires_grad_(False) + vae.eval() + self.vae = vae.to(self.device, self.weight_dtype) + + def _resizecrop(self, image, th, tw): + w, h = image.size + if h / w > th / tw: + new_w = int(w) + new_h = int(new_w * th / tw) + else: + new_h = int(h) + new_w = int(new_h * tw / th) + left = (w - new_w) / 2 + top = (h - new_h) / 2 + right = (w + new_w) / 2 + bottom = (h + new_h) / 2 + image = image.crop((left, top, right, bottom)) + return image + + def generate_videos(self): + mode = self.config.pop('mode') + assert mode in ['universal', 'gta_drive', 'templerun'] + + image = load_image(self.args.img_path) + image = self._resizecrop(image, 352, 640) + image = self.frame_process(image)[None, :, None, :, :].to(dtype=self.weight_dtype, device=self.device) + # Encode the input image as the first latent + padding_video = torch.zeros_like(image).repeat(1, 1, 4 * (self.args.num_output_frames - 1), 1, 1) + img_cond = torch.concat([image, padding_video], dim=2) + tiler_kwargs={"tiled": True, "tile_size": [44, 80], "tile_stride": [23, 38]} + img_cond = self.vae.encode(img_cond, device=self.device, **tiler_kwargs).to(self.device) + mask_cond = torch.ones_like(img_cond) + mask_cond[:, :, 1:] = 0 + cond_concat = torch.cat([mask_cond[:, :4], img_cond], dim=1) + visual_context = self.vae.clip.encode_video(image) + sampled_noise = torch.randn( + [1, 16,self.args.num_output_frames, 44, 80], device=self.device, dtype=self.weight_dtype + ) + num_frames = (self.args.num_output_frames - 1) * 4 + 1 + + conditional_dict = { + "cond_concat": cond_concat.to(device=self.device, dtype=self.weight_dtype), + "visual_context": visual_context.to(device=self.device, dtype=self.weight_dtype) + } + + if mode == 'universal': + cond_data = Bench_actions_universal(num_frames) + mouse_condition = cond_data['mouse_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['mouse_cond'] = mouse_condition + elif mode == 'gta_drive': + cond_data = Bench_actions_gta_drive(num_frames) + mouse_condition = cond_data['mouse_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['mouse_cond'] = mouse_condition + else: + cond_data = Bench_actions_templerun(num_frames) + keyboard_condition = cond_data['keyboard_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['keyboard_cond'] = keyboard_condition + + with torch.no_grad(): + videos = self.pipeline.inference( + noise=sampled_noise, + conditional_dict=conditional_dict, + return_latents=False, + mode=mode, + profile=False + ) + + videos_tensor = torch.cat(videos, dim=1) + videos = rearrange(videos_tensor, "B T C H W -> B T H W C") + videos = ((videos.float() + 1) * 127.5).clip(0, 255).cpu().numpy().astype(np.uint8)[0] + video = np.ascontiguousarray(videos) + mouse_icon = 'assets/images/mouse.png' + if mode != 'templerun': + config = ( + keyboard_condition[0].float().cpu().numpy(), + mouse_condition[0].float().cpu().numpy() + ) + else: + config = ( + keyboard_condition[0].float().cpu().numpy() + ) + process_video(video.astype(np.uint8), self.args.output_folder+f'/demo.mp4', config, mouse_icon, mouse_scale=0.1, process_icon=False, mode=mode) + process_video(video.astype(np.uint8), self.args.output_folder+f'/demo_icon.mp4', config, mouse_icon, mouse_scale=0.1, process_icon=True, mode=mode) + print("Done") + +def main(): + """Main entry point for video generation.""" + args = parse_args() + set_seed(args.seed) + os.makedirs(args.output_folder, exist_ok=True) + pipeline = InteractiveGameInference(args) + pipeline.generate_videos() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/inference_universal.yaml b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/inference_universal.yaml new file mode 100644 index 0000000000000000000000000000000000000000..adec83e8175fbe1c0159e0e39e34e7635c319de4 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/inference_universal.yaml @@ -0,0 +1,21 @@ +denoising_step_list: +- 1000 +- 666 +- 333 +warp_denoising_step: true +ts_schedule: false +mixed_precision: true +seed: 42 +image_or_video_shape: +- 1 +- 16 +- 15 +- 44 +- 80 +num_frame_per_block: 3 +context_noise: 0 +mode: universal +causal: true +model_kwargs: + timestep_shift: 5.0 + model_config: configs/distilled_model/universal \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/launcher.sh b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/launcher.sh new file mode 100644 index 0000000000000000000000000000000000000000..b8daac36b612494e3b61040c1e52ac4e5de3b54b --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/launcher.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +#SBATCH --job-name=matrix-game2-native-control +#SBATCH --array=0-4 +#SBATCH --nodes=1 +#SBATCH --ntasks=1 +#SBATCH --cpus-per-task=14 +#SBATCH --gres=gpu:1 +#SBATCH --time=02:00:00 +#SBATCH --account=berzelius-2026-196 +#SBATCH --chdir=/proj/cvl/users/x_fahkh2/worldmem-baseline-evals +#SBATCH --output=slurm_logs/%x-%A_%a.out +#SBATCH --error=slurm_logs/%x-%A_%a.out +set -euo pipefail +module load buildenv-gcccuda/12.9.1-gcc11 +ROOT=/proj/cvl/users/x_fahkh2/worldmem-baseline-evals +PYTHON=/proj/cvl/users/x_fahkh2/envs/matrix-game2-eval/bin/python +DATA_ROOT=/proj/cvl/users/x_fahkh2/WorldMem_Repro/datasets/minecraft +MODES=(official_demo demo_actions neutral recorded small_mouse) +MODE=${MODES[$SLURM_ARRAY_TASK_ID]} +OUTPUT=$ROOT/Matrix-Game/Matrix-Game-2/outputs/diagnostic_native_${MODE}_job${SLURM_ARRAY_JOB_ID}_task${SLURM_ARRAY_TASK_ID} +export TMPDIR=$ROOT/cache +export TRITON_CACHE_DIR=$ROOT/cache +export TORCHINDUCTOR_CACHE_DIR=$ROOT/cache/torchinductor +export HF_HOME=$ROOT/cache/huggingface +export TORCH_HOME=$ROOT/cache/torch +export XDG_CACHE_HOME=$ROOT/cache +export MPLCONFIGDIR=$ROOT/cache/matplotlib +export PYTHONPATH=$ROOT/Matrix-Game/Matrix-Game-2 +export PYTHONNOUSERSITE=1 PYTHONUNBUFFERED=1 OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 +export WANDB_MODE=disabled HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 +mkdir -p "$TMPDIR" "$TORCHINDUCTOR_CACHE_DIR" "$OUTPUT" +"$PYTHON" "$ROOT/deployment/verify_node.py" --expected-gpus 1 --output "$OUTPUT" +cp "$0" "$OUTPUT/launcher.sh" +cp "$ROOT/deployment/matrix_native_controls.py" "$OUTPUT/probe.py" +cp "$ROOT/Matrix-Game/Matrix-Game-2/inference.py" "$ROOT/Matrix-Game/Matrix-Game-2/configs/inference_yaml/inference_universal.yaml" "$OUTPUT/" +srun --ntasks=1 --gpus-per-task=1 --cpus-per-task=14 --cpu-bind=cores \ + "$PYTHON" "$ROOT/deployment/matrix_native_controls.py" \ + --mode "$MODE" --data-root "$DATA_ROOT" --output "$OUTPUT" diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/manifest.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..0a4a31d1d4056e4f00fde62ac39976990ac73193 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/manifest.json @@ -0,0 +1,50 @@ +{ + "mode": "demo_actions", + "diagnostic_only": true, + "checkpoint": "/proj/cvl/users/x_fahkh2/worldmem-baseline-evals/checkpoints/matrix-game2", + "upstream_revision": "71c3cd7f741311f8100f6cf9cde942b6c1378d11", + "weight_policy": "released raw distilled; original normalization; no optimizer or updates", + "expected_generator_parameters": 1619242304, + "expected_vae_parameters": 126892531, + "expected_clip_parameters": 1193014785, + "batch_size": 1, + "lora": null, + "lr": null, + "activation_checkpointing": false, + "steps": 3, + "shift": 5, + "cache_latents": 6, + "decoder": "official compiled max-autotune-no-cudagraphs", + "official_demo": "unchanged inference.py; supplied painting0000.png; seed0;150latents=597RGB", + "minecraft": { + "anchor": 699, + "native_latents": 9, + "native_rgb": 33, + "scored_slice": [ + 1, + 25 + ], + "targets": [ + 700, + 724 + ], + "recorded_control_alignment": "incoming700:724 plus9noops; small_mouse scales camera only", + "reference": "rawRGB with official center crop and frame_process" + }, + "score_caveat": "Only recorded controls replay GT actions; other modes test stability, not benchmark accuracy", + "cases": [ + { + "index": "0", + "path": "test/val_plains/2/000034.mp4", + "seed": 42000000 + }, + { + "index": "1", + "path": "test/val_desert/1/000029.mp4", + "seed": 42000001 + } + ], + "output_frames_per_case": 33, + "generator_requires_grad_parameters": 1619242304, + "inference_grad_policy": "unchanged native no_grad; parameter flags unmodified" +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/node.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/node.json new file mode 100644 index 0000000000000000000000000000000000000000..974ca5ab6fc954d4606da20cd158791744fe9bad --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/node.json @@ -0,0 +1,7 @@ +{ + "devices": [ + "NVIDIA H200" + ], + "torch": "2.7.0+cu126", + "slurm_job_id": "85114" +} diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/probe.py b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/probe.py new file mode 100644 index 0000000000000000000000000000000000000000..8c5e386fea438328f89a79c076453c94e2f09ecb --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_demo_actions_job85112_task1/probe.py @@ -0,0 +1,106 @@ +"""Official Matrix demo and native-image controls; all scores are diagnostic.""" +import argparse +import json +import os +import subprocess +import sys +from pathlib import Path +import numpy as np +import torch +from PIL import Image +from diagnose_matrix_game2 import save_result +from protocol import minecraft_actions, read_frames, select_cases +from worldmem_adapter import map_actions + +ROOT = Path(__file__).resolve().parents[1] +REPO = ROOT / 'Matrix-Game/Matrix-Game-2' +MODES = ['official_demo', 'demo_actions', 'neutral', 'recorded', 'small_mouse'] + +def replay_controls(raw, mode, length): + keyboard, mouse = map_actions(minecraft_actions(raw), 1.0) + keys, turns = torch.zeros(length, 4), torch.zeros(length, 2) + if mode != 'neutral': + keys[:24], turns[:24] = keyboard, mouse * (0.1 if mode == 'small_mouse' else 1.0) + return {'keyboard_condition': keys, 'mouse_condition': turns} + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--mode', choices=MODES, required=True) + parser.add_argument('--data-root', type=Path, required=True) + parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--dry-run', action='store_true') + args = parser.parse_args() + checkpoint = ROOT / 'checkpoints/matrix-game2' + rows = select_cases(ROOT / 'deployment/manifests/minecraft_test_300.csv', limit=2) + manifest = {'mode': args.mode, 'diagnostic_only': True, 'checkpoint': str(checkpoint), + 'upstream_revision': '71c3cd7f741311f8100f6cf9cde942b6c1378d11', + 'weight_policy': 'released raw distilled; original normalization; no optimizer or updates', + 'expected_generator_parameters': 1619242304, 'expected_vae_parameters': 126892531, + 'expected_clip_parameters': 1193014785, 'batch_size': 1, 'lora': None, 'lr': None, + 'activation_checkpointing': False, 'steps': 3, 'shift': 5, 'cache_latents': 6, + 'decoder': 'official compiled max-autotune-no-cudagraphs', + 'official_demo': 'unchanged inference.py; supplied painting0000.png; seed0;150latents=597RGB', + 'minecraft': {'anchor': 699, 'native_latents': 9, 'native_rgb': 33, 'scored_slice': [1, 25], + 'targets': [700, 724], 'recorded_control_alignment': 'incoming700:724 plus9noops; small_mouse scales camera only', + 'reference': 'rawRGB with official center crop and frame_process'}, + 'score_caveat': 'Only recorded controls replay GT actions; other modes test stability, not benchmark accuracy', + 'cases': ([{'image': 'demo_images/universal/0000.png', 'seed': 0}] if args.mode == 'official_demo' + else [{'index': r['global_test_index'], 'path': r['relative_path'], + 'seed': 42000000 + int(r['global_test_index'])} for r in rows]), + 'output_frames_per_case': 597 if args.mode == 'official_demo' else 33} + if args.dry_run: + print(json.dumps(manifest, indent=2)) + return + args.output.mkdir(parents=True, exist_ok=True) + (args.output / 'manifest.json').write_text(json.dumps(manifest, indent=2)) + os.chdir(REPO) + if args.mode == 'official_demo': + subprocess.run([sys.executable, 'inference.py', '--checkpoint_path', str(checkpoint / 'base_distilled_model/base_distill.safetensors'), + '--pretrained_model_path', str(checkpoint), '--img_path', 'demo_images/universal/0000.png', + '--config_path', 'configs/inference_yaml/inference_universal.yaml', '--seed', '0', + '--num_output_frames', '150', '--output_folder', str(args.output)], check=True) + from torchvision.io import read_video + video, _, _ = read_video(str(args.output / 'demo.mp4'), pts_unit='sec') + assert len(video) == 597 + Image.fromarray(torch.cat([video[t] for t in [0, 1, 2, 24, 100, 596]], dim=1).numpy()).save(args.output / 'samples.jpg') + else: + import inference as native + native.set_seed(0) + model_args = argparse.Namespace(config_path='configs/inference_yaml/inference_universal.yaml', + checkpoint_path=str(checkpoint / 'base_distilled_model/base_distill.safetensors'), + pretrained_model_path=str(checkpoint), num_output_frames=9, seed=0, img_path='', output_folder='') + engine = native.InteractiveGameInference(model_args) + manifest['generator_requires_grad_parameters'] = sum(p.numel() for p in engine.pipeline.generator.parameters() if p.requires_grad) + manifest['inference_grad_policy'] = 'unchanged native no_grad; parameter flags unmodified' + (args.output / 'manifest.json').write_text(json.dumps(manifest, indent=2)) + original_inference, native_controls = engine.pipeline.inference, native.Bench_actions_universal + captured = {} + def capture(**kwargs): + condition = kwargs['conditional_dict'] + np.savez_compressed(case_dir / 'inputs.npz', initial_noise=kwargs['noise'].float().cpu().numpy(), + keyboard=condition['keyboard_cond'][0].float().cpu().numpy(), mouse=condition['mouse_cond'][0].float().cpu().numpy()) + videos = original_inference(**kwargs) + captured['prediction'] = torch.cat(videos, dim=1)[0, 1:25].detach().float().cpu().add(1).div(2) + return videos + engine.pipeline.inference = capture + for row in rows: + case_dir = args.output / f"case{row['global_test_index']}" + case_dir.mkdir(exist_ok=True) + path = args.data_root / row['relative_path'] + rgb = read_frames(path, torch.arange(699, 724)) + images = [Image.fromarray(frame.mul(255).round().byte().permute(1, 2, 0).numpy()) for frame in rgb] + images[0].save(case_dir / 'input.png') + reference = torch.stack([engine.frame_process(engine._resizecrop(im, 352, 640)).add(1).div(2) for im in images[1:]]) + with np.load(path.with_suffix('.npz')) as annotation: + controls = replay_controls(annotation['actions'][700:724], args.mode, 33) + native.Bench_actions_universal = native_controls if args.mode == 'demo_actions' else lambda length: controls + model_args.img_path, model_args.output_folder = str(case_dir / 'input.png'), str(case_dir) + engine.config['mode'] = 'universal' + native.set_seed(42000000 + int(row['global_test_index'])) + engine.generate_videos() + save_result(case_dir, 'comparison', captured.pop('prediction'), reference) + (args.output / 'complete.json').write_text(json.dumps({'mode': args.mode, 'complete': True})) + print('NATIVE_CONTROL_COMPLETE', flush=True) + +if __name__ == '__main__': + main() diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/comparison.jpg b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/comparison.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0951d29799379d64faddac832d0c98afa39d32ee Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/comparison.jpg differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/comparison.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/comparison.json new file mode 100644 index 0000000000000000000000000000000000000000..ec55e812e9e1974d5a68d694697fffd7dcd9d52a --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/comparison.json @@ -0,0 +1,81 @@ +{ + "case": "comparison", + "raw_rgb_psnr": [ + 29.00463104248047, + 25.083839416503906, + 5.1293206214904785, + 7.163086891174316, + 7.246057510375977, + 7.313009262084961, + 7.356295585632324, + 7.3129777908325195, + 7.402219772338867, + 7.4208784103393555, + 7.457307815551758, + 7.469139099121094, + 7.432450771331787, + 7.4313764572143555, + 7.441709518432617, + 7.446588516235352, + 7.415165901184082, + 7.416438579559326, + 7.437826156616211, + 7.455380439758301, + 7.600482940673828, + 7.668927192687988, + 7.7082390785217285, + 7.726196765899658 + ], + "raw_rgb_mse": [ + 0.0012575836153700948, + 0.0031018152367323637, + 0.3069502115249634, + 0.19217252731323242, + 0.18853598833084106, + 0.1856517493724823, + 0.1838105469942093, + 0.18565309047698975, + 0.18187710642814636, + 0.1810973733663559, + 0.17958466708660126, + 0.1790960729122162, + 0.18061546981334686, + 0.18066012859344482, + 0.18023081123828888, + 0.18002846837043762, + 0.18133574724197388, + 0.1812826246023178, + 0.1803920418024063, + 0.17966437339782715, + 0.1737607717514038, + 0.1710437834262848, + 0.16950249671936035, + 0.16880306601524353 + ], + "mean_rgb": [ + 0.71062171459198, + 0.712151288986206, + 0.20236869156360626, + 0.3093110918998718, + 0.31275486946105957, + 0.316022664308548, + 0.31764835119247437, + 0.31517931818962097, + 0.31939250230789185, + 0.32033178210258484, + 0.32227084040641785, + 0.3230479955673218, + 0.32040339708328247, + 0.31977322697639465, + 0.3199549615383148, + 0.32007846236228943, + 0.31954720616340637, + 0.32010453939437866, + 0.3214494287967682, + 0.3225550353527069, + 0.3296678364276886, + 0.33288630843162537, + 0.33478885889053345, + 0.3357396125793457 + ] +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/demo.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..2d45115cbb177f7aa0ff55d7c98dc5c8e1b087a6 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/demo.mp4 differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/demo_icon.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/demo_icon.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..d39f5b43ffe99fe15cbeb766249045841b7e44c3 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/demo_icon.mp4 differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/input.png b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/input.png new file mode 100644 index 0000000000000000000000000000000000000000..3575844c2a8079d439ece74b50a874c10bbc32f6 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/input.png differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/inputs.npz b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/inputs.npz new file mode 100644 index 0000000000000000000000000000000000000000..936bf37c0ddb38057a548f3b3d39e7d9715c6909 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case0/inputs.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1fe3a1516baaadafaf55d193a12a989c649b2c01bf0cfe6a68446be845073ec3 +size 952253 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/comparison.jpg b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/comparison.jpg new file mode 100644 index 0000000000000000000000000000000000000000..fdfb5b9d28e8f90840505b1eb93afd0955c39b31 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/comparison.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d842d9937979fa3f35b18bf9c48288fe8c77676f7bf92ae1725bed7afb11fbc7 +size 164319 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/comparison.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/comparison.json new file mode 100644 index 0000000000000000000000000000000000000000..0e38318d69f0dd8c7215d689b4f84ee159af2895 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/comparison.json @@ -0,0 +1,81 @@ +{ + "case": "comparison", + "raw_rgb_psnr": [ + 20.059900283813477, + 18.597415924072266, + 18.113113403320312, + 17.338909149169922, + 18.3916072845459, + 18.688901901245117, + 18.53306007385254, + 18.357519149780273, + 18.232343673706055, + 18.186416625976562, + 18.135757446289062, + 18.113117218017578, + 18.16193389892578, + 18.166234970092773, + 18.167783737182617, + 18.165790557861328, + 18.197973251342773, + 18.205169677734375, + 18.255691528320312, + 18.27703285217285, + 18.182619094848633, + 18.162242889404297, + 18.10346794128418, + 18.056255340576172 + ], + "raw_rgb_mse": [ + 0.009863022714853287, + 0.013812059536576271, + 0.015441467985510826, + 0.018454786390066147, + 0.01448235847055912, + 0.013524146750569344, + 0.014018258079886436, + 0.014596477150917053, + 0.015023309737443924, + 0.015183024108409882, + 0.015361170284450054, + 0.01544145680963993, + 0.015268862247467041, + 0.015253743156790733, + 0.015248307026922703, + 0.015255306847393513, + 0.015142681077122688, + 0.015117603354156017, + 0.01494276151061058, + 0.014869509264826775, + 0.015196304768323898, + 0.015267775394022465, + 0.0154758021235466, + 0.01564495824277401 + ], + "mean_rgb": [ + 0.7140963077545166, + 0.7141072154045105, + 0.7137575149536133, + 0.7141113877296448, + 0.7121320366859436, + 0.7116583585739136, + 0.7107756733894348, + 0.7105647325515747, + 0.7109081149101257, + 0.711028516292572, + 0.7102257609367371, + 0.7101965546607971, + 0.7101762294769287, + 0.7103557586669922, + 0.7101123332977295, + 0.7103460431098938, + 0.7076926827430725, + 0.7064762115478516, + 0.7051817178726196, + 0.7046799063682556, + 0.7081876993179321, + 0.7094244956970215, + 0.7100866436958313, + 0.7104617953300476 + ] +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/demo.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..8745fa7d8f6b809c3c98619b1aab407bcaf03e52 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/demo.mp4 differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/demo_icon.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/demo_icon.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..215c0889cbae2c9499b819250b6b7e5899f6e1cb Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/demo_icon.mp4 differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/input.png b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/input.png new file mode 100644 index 0000000000000000000000000000000000000000..a240efc2cac61bce8c2f601e02d0eb3207816689 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/input.png differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/inputs.npz b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/inputs.npz new file mode 100644 index 0000000000000000000000000000000000000000..7479ec314114016c657db7e7bd7a045acc542c3f --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/case1/inputs.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95cf1a93c298840e6226640ffa742607ab41f4aee3b1b5ae60a50691a67e83bd +size 951965 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/complete.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/complete.json new file mode 100644 index 0000000000000000000000000000000000000000..88c3c8bfa67f8146186ce05642413c70c483f5ba --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/complete.json @@ -0,0 +1 @@ +{"mode": "neutral", "complete": true} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/inference.py b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/inference.py new file mode 100644 index 0000000000000000000000000000000000000000..f4df03bda84a07a365507a5146938effb5352ffe --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/inference.py @@ -0,0 +1,169 @@ +import os +import argparse +import torch +import numpy as np + +from omegaconf import OmegaConf +from torchvision.transforms import v2 +from diffusers.utils import load_image +from einops import rearrange +from pipeline import CausalInferencePipeline +from wan.vae.wanx_vae import get_wanx_vae_wrapper +from demo_utils.vae_block3 import VAEDecoderWrapper +from utils.visualize import process_video +from utils.misc import set_seed +from utils.conditions import * +from utils.wan_wrapper import WanDiffusionWrapper +from safetensors.torch import load_file + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("--config_path", type=str, default="configs/inference_yaml/inference_universal.yaml", help="Path to the config file") + parser.add_argument("--checkpoint_path", type=str, default="", help="Path to the checkpoint") + parser.add_argument("--img_path", type=str, default="demo_images/universal/0000.png", help="Path to the image") + parser.add_argument("--output_folder", type=str, default="outputs/", help="Output folder") + parser.add_argument("--num_output_frames", type=int, default=150, + help="Number of output latent frames") + parser.add_argument("--seed", type=int, default=0, help="Random seed") + parser.add_argument("--pretrained_model_path", type=str, default="Matrix-Game-2.0", help="Path to the VAE model folder") + args = parser.parse_args() + return args + +class InteractiveGameInference: + def __init__(self, args): + self.args = args + self.device = torch.device("cuda") + self.weight_dtype = torch.bfloat16 + + self._init_config() + self._init_models() + + self.frame_process = v2.Compose([ + v2.Resize(size=(352, 640), antialias=True), + v2.ToTensor(), + v2.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]), + ]) + + def _init_config(self): + self.config = OmegaConf.load(self.args.config_path) + + def _init_models(self): + # Initialize pipeline + generator = WanDiffusionWrapper( + **getattr(self.config, "model_kwargs", {}), is_causal=True) + current_vae_decoder = VAEDecoderWrapper() + vae_state_dict = torch.load(os.path.join(self.args.pretrained_model_path, "Wan2.1_VAE.pth"), map_location="cpu") + decoder_state_dict = {} + for key, value in vae_state_dict.items(): + if 'decoder.' in key or 'conv2' in key: + decoder_state_dict[key] = value + current_vae_decoder.load_state_dict(decoder_state_dict) + current_vae_decoder.to(self.device, torch.float16) + current_vae_decoder.requires_grad_(False) + current_vae_decoder.eval() + current_vae_decoder.compile(mode="max-autotune-no-cudagraphs") + pipeline = CausalInferencePipeline(self.config, generator=generator, vae_decoder=current_vae_decoder) + if self.args.checkpoint_path: + print("Loading Pretrained Model...") + state_dict = load_file(self.args.checkpoint_path) + pipeline.generator.load_state_dict(state_dict) + + self.pipeline = pipeline.to(device=self.device, dtype=self.weight_dtype) + self.pipeline.vae_decoder.to(torch.float16) + + vae = get_wanx_vae_wrapper(self.args.pretrained_model_path, torch.float16) + vae.requires_grad_(False) + vae.eval() + self.vae = vae.to(self.device, self.weight_dtype) + + def _resizecrop(self, image, th, tw): + w, h = image.size + if h / w > th / tw: + new_w = int(w) + new_h = int(new_w * th / tw) + else: + new_h = int(h) + new_w = int(new_h * tw / th) + left = (w - new_w) / 2 + top = (h - new_h) / 2 + right = (w + new_w) / 2 + bottom = (h + new_h) / 2 + image = image.crop((left, top, right, bottom)) + return image + + def generate_videos(self): + mode = self.config.pop('mode') + assert mode in ['universal', 'gta_drive', 'templerun'] + + image = load_image(self.args.img_path) + image = self._resizecrop(image, 352, 640) + image = self.frame_process(image)[None, :, None, :, :].to(dtype=self.weight_dtype, device=self.device) + # Encode the input image as the first latent + padding_video = torch.zeros_like(image).repeat(1, 1, 4 * (self.args.num_output_frames - 1), 1, 1) + img_cond = torch.concat([image, padding_video], dim=2) + tiler_kwargs={"tiled": True, "tile_size": [44, 80], "tile_stride": [23, 38]} + img_cond = self.vae.encode(img_cond, device=self.device, **tiler_kwargs).to(self.device) + mask_cond = torch.ones_like(img_cond) + mask_cond[:, :, 1:] = 0 + cond_concat = torch.cat([mask_cond[:, :4], img_cond], dim=1) + visual_context = self.vae.clip.encode_video(image) + sampled_noise = torch.randn( + [1, 16,self.args.num_output_frames, 44, 80], device=self.device, dtype=self.weight_dtype + ) + num_frames = (self.args.num_output_frames - 1) * 4 + 1 + + conditional_dict = { + "cond_concat": cond_concat.to(device=self.device, dtype=self.weight_dtype), + "visual_context": visual_context.to(device=self.device, dtype=self.weight_dtype) + } + + if mode == 'universal': + cond_data = Bench_actions_universal(num_frames) + mouse_condition = cond_data['mouse_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['mouse_cond'] = mouse_condition + elif mode == 'gta_drive': + cond_data = Bench_actions_gta_drive(num_frames) + mouse_condition = cond_data['mouse_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['mouse_cond'] = mouse_condition + else: + cond_data = Bench_actions_templerun(num_frames) + keyboard_condition = cond_data['keyboard_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['keyboard_cond'] = keyboard_condition + + with torch.no_grad(): + videos = self.pipeline.inference( + noise=sampled_noise, + conditional_dict=conditional_dict, + return_latents=False, + mode=mode, + profile=False + ) + + videos_tensor = torch.cat(videos, dim=1) + videos = rearrange(videos_tensor, "B T C H W -> B T H W C") + videos = ((videos.float() + 1) * 127.5).clip(0, 255).cpu().numpy().astype(np.uint8)[0] + video = np.ascontiguousarray(videos) + mouse_icon = 'assets/images/mouse.png' + if mode != 'templerun': + config = ( + keyboard_condition[0].float().cpu().numpy(), + mouse_condition[0].float().cpu().numpy() + ) + else: + config = ( + keyboard_condition[0].float().cpu().numpy() + ) + process_video(video.astype(np.uint8), self.args.output_folder+f'/demo.mp4', config, mouse_icon, mouse_scale=0.1, process_icon=False, mode=mode) + process_video(video.astype(np.uint8), self.args.output_folder+f'/demo_icon.mp4', config, mouse_icon, mouse_scale=0.1, process_icon=True, mode=mode) + print("Done") + +def main(): + """Main entry point for video generation.""" + args = parse_args() + set_seed(args.seed) + os.makedirs(args.output_folder, exist_ok=True) + pipeline = InteractiveGameInference(args) + pipeline.generate_videos() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/inference_universal.yaml b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/inference_universal.yaml new file mode 100644 index 0000000000000000000000000000000000000000..adec83e8175fbe1c0159e0e39e34e7635c319de4 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/inference_universal.yaml @@ -0,0 +1,21 @@ +denoising_step_list: +- 1000 +- 666 +- 333 +warp_denoising_step: true +ts_schedule: false +mixed_precision: true +seed: 42 +image_or_video_shape: +- 1 +- 16 +- 15 +- 44 +- 80 +num_frame_per_block: 3 +context_noise: 0 +mode: universal +causal: true +model_kwargs: + timestep_shift: 5.0 + model_config: configs/distilled_model/universal \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/launcher.sh b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/launcher.sh new file mode 100644 index 0000000000000000000000000000000000000000..b8daac36b612494e3b61040c1e52ac4e5de3b54b --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/launcher.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +#SBATCH --job-name=matrix-game2-native-control +#SBATCH --array=0-4 +#SBATCH --nodes=1 +#SBATCH --ntasks=1 +#SBATCH --cpus-per-task=14 +#SBATCH --gres=gpu:1 +#SBATCH --time=02:00:00 +#SBATCH --account=berzelius-2026-196 +#SBATCH --chdir=/proj/cvl/users/x_fahkh2/worldmem-baseline-evals +#SBATCH --output=slurm_logs/%x-%A_%a.out +#SBATCH --error=slurm_logs/%x-%A_%a.out +set -euo pipefail +module load buildenv-gcccuda/12.9.1-gcc11 +ROOT=/proj/cvl/users/x_fahkh2/worldmem-baseline-evals +PYTHON=/proj/cvl/users/x_fahkh2/envs/matrix-game2-eval/bin/python +DATA_ROOT=/proj/cvl/users/x_fahkh2/WorldMem_Repro/datasets/minecraft +MODES=(official_demo demo_actions neutral recorded small_mouse) +MODE=${MODES[$SLURM_ARRAY_TASK_ID]} +OUTPUT=$ROOT/Matrix-Game/Matrix-Game-2/outputs/diagnostic_native_${MODE}_job${SLURM_ARRAY_JOB_ID}_task${SLURM_ARRAY_TASK_ID} +export TMPDIR=$ROOT/cache +export TRITON_CACHE_DIR=$ROOT/cache +export TORCHINDUCTOR_CACHE_DIR=$ROOT/cache/torchinductor +export HF_HOME=$ROOT/cache/huggingface +export TORCH_HOME=$ROOT/cache/torch +export XDG_CACHE_HOME=$ROOT/cache +export MPLCONFIGDIR=$ROOT/cache/matplotlib +export PYTHONPATH=$ROOT/Matrix-Game/Matrix-Game-2 +export PYTHONNOUSERSITE=1 PYTHONUNBUFFERED=1 OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 +export WANDB_MODE=disabled HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 +mkdir -p "$TMPDIR" "$TORCHINDUCTOR_CACHE_DIR" "$OUTPUT" +"$PYTHON" "$ROOT/deployment/verify_node.py" --expected-gpus 1 --output "$OUTPUT" +cp "$0" "$OUTPUT/launcher.sh" +cp "$ROOT/deployment/matrix_native_controls.py" "$OUTPUT/probe.py" +cp "$ROOT/Matrix-Game/Matrix-Game-2/inference.py" "$ROOT/Matrix-Game/Matrix-Game-2/configs/inference_yaml/inference_universal.yaml" "$OUTPUT/" +srun --ntasks=1 --gpus-per-task=1 --cpus-per-task=14 --cpu-bind=cores \ + "$PYTHON" "$ROOT/deployment/matrix_native_controls.py" \ + --mode "$MODE" --data-root "$DATA_ROOT" --output "$OUTPUT" diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/manifest.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..32b94bb62892768b4bfbff8926a8b61abb2960f5 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/manifest.json @@ -0,0 +1,50 @@ +{ + "mode": "neutral", + "diagnostic_only": true, + "checkpoint": "/proj/cvl/users/x_fahkh2/worldmem-baseline-evals/checkpoints/matrix-game2", + "upstream_revision": "71c3cd7f741311f8100f6cf9cde942b6c1378d11", + "weight_policy": "released raw distilled; original normalization; no optimizer or updates", + "expected_generator_parameters": 1619242304, + "expected_vae_parameters": 126892531, + "expected_clip_parameters": 1193014785, + "batch_size": 1, + "lora": null, + "lr": null, + "activation_checkpointing": false, + "steps": 3, + "shift": 5, + "cache_latents": 6, + "decoder": "official compiled max-autotune-no-cudagraphs", + "official_demo": "unchanged inference.py; supplied painting0000.png; seed0;150latents=597RGB", + "minecraft": { + "anchor": 699, + "native_latents": 9, + "native_rgb": 33, + "scored_slice": [ + 1, + 25 + ], + "targets": [ + 700, + 724 + ], + "recorded_control_alignment": "incoming700:724 plus9noops; small_mouse scales camera only", + "reference": "rawRGB with official center crop and frame_process" + }, + "score_caveat": "Only recorded controls replay GT actions; other modes test stability, not benchmark accuracy", + "cases": [ + { + "index": "0", + "path": "test/val_plains/2/000034.mp4", + "seed": 42000000 + }, + { + "index": "1", + "path": "test/val_desert/1/000029.mp4", + "seed": 42000001 + } + ], + "output_frames_per_case": 33, + "generator_requires_grad_parameters": 1619242304, + "inference_grad_policy": "unchanged native no_grad; parameter flags unmodified" +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/node.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/node.json new file mode 100644 index 0000000000000000000000000000000000000000..cd248956781ecb5915405f39a53efe22b8069c8f --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/node.json @@ -0,0 +1,7 @@ +{ + "devices": [ + "NVIDIA H200" + ], + "torch": "2.7.0+cu126", + "slurm_job_id": "85115" +} diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/probe.py b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/probe.py new file mode 100644 index 0000000000000000000000000000000000000000..8c5e386fea438328f89a79c076453c94e2f09ecb --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_neutral_job85112_task2/probe.py @@ -0,0 +1,106 @@ +"""Official Matrix demo and native-image controls; all scores are diagnostic.""" +import argparse +import json +import os +import subprocess +import sys +from pathlib import Path +import numpy as np +import torch +from PIL import Image +from diagnose_matrix_game2 import save_result +from protocol import minecraft_actions, read_frames, select_cases +from worldmem_adapter import map_actions + +ROOT = Path(__file__).resolve().parents[1] +REPO = ROOT / 'Matrix-Game/Matrix-Game-2' +MODES = ['official_demo', 'demo_actions', 'neutral', 'recorded', 'small_mouse'] + +def replay_controls(raw, mode, length): + keyboard, mouse = map_actions(minecraft_actions(raw), 1.0) + keys, turns = torch.zeros(length, 4), torch.zeros(length, 2) + if mode != 'neutral': + keys[:24], turns[:24] = keyboard, mouse * (0.1 if mode == 'small_mouse' else 1.0) + return {'keyboard_condition': keys, 'mouse_condition': turns} + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--mode', choices=MODES, required=True) + parser.add_argument('--data-root', type=Path, required=True) + parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--dry-run', action='store_true') + args = parser.parse_args() + checkpoint = ROOT / 'checkpoints/matrix-game2' + rows = select_cases(ROOT / 'deployment/manifests/minecraft_test_300.csv', limit=2) + manifest = {'mode': args.mode, 'diagnostic_only': True, 'checkpoint': str(checkpoint), + 'upstream_revision': '71c3cd7f741311f8100f6cf9cde942b6c1378d11', + 'weight_policy': 'released raw distilled; original normalization; no optimizer or updates', + 'expected_generator_parameters': 1619242304, 'expected_vae_parameters': 126892531, + 'expected_clip_parameters': 1193014785, 'batch_size': 1, 'lora': None, 'lr': None, + 'activation_checkpointing': False, 'steps': 3, 'shift': 5, 'cache_latents': 6, + 'decoder': 'official compiled max-autotune-no-cudagraphs', + 'official_demo': 'unchanged inference.py; supplied painting0000.png; seed0;150latents=597RGB', + 'minecraft': {'anchor': 699, 'native_latents': 9, 'native_rgb': 33, 'scored_slice': [1, 25], + 'targets': [700, 724], 'recorded_control_alignment': 'incoming700:724 plus9noops; small_mouse scales camera only', + 'reference': 'rawRGB with official center crop and frame_process'}, + 'score_caveat': 'Only recorded controls replay GT actions; other modes test stability, not benchmark accuracy', + 'cases': ([{'image': 'demo_images/universal/0000.png', 'seed': 0}] if args.mode == 'official_demo' + else [{'index': r['global_test_index'], 'path': r['relative_path'], + 'seed': 42000000 + int(r['global_test_index'])} for r in rows]), + 'output_frames_per_case': 597 if args.mode == 'official_demo' else 33} + if args.dry_run: + print(json.dumps(manifest, indent=2)) + return + args.output.mkdir(parents=True, exist_ok=True) + (args.output / 'manifest.json').write_text(json.dumps(manifest, indent=2)) + os.chdir(REPO) + if args.mode == 'official_demo': + subprocess.run([sys.executable, 'inference.py', '--checkpoint_path', str(checkpoint / 'base_distilled_model/base_distill.safetensors'), + '--pretrained_model_path', str(checkpoint), '--img_path', 'demo_images/universal/0000.png', + '--config_path', 'configs/inference_yaml/inference_universal.yaml', '--seed', '0', + '--num_output_frames', '150', '--output_folder', str(args.output)], check=True) + from torchvision.io import read_video + video, _, _ = read_video(str(args.output / 'demo.mp4'), pts_unit='sec') + assert len(video) == 597 + Image.fromarray(torch.cat([video[t] for t in [0, 1, 2, 24, 100, 596]], dim=1).numpy()).save(args.output / 'samples.jpg') + else: + import inference as native + native.set_seed(0) + model_args = argparse.Namespace(config_path='configs/inference_yaml/inference_universal.yaml', + checkpoint_path=str(checkpoint / 'base_distilled_model/base_distill.safetensors'), + pretrained_model_path=str(checkpoint), num_output_frames=9, seed=0, img_path='', output_folder='') + engine = native.InteractiveGameInference(model_args) + manifest['generator_requires_grad_parameters'] = sum(p.numel() for p in engine.pipeline.generator.parameters() if p.requires_grad) + manifest['inference_grad_policy'] = 'unchanged native no_grad; parameter flags unmodified' + (args.output / 'manifest.json').write_text(json.dumps(manifest, indent=2)) + original_inference, native_controls = engine.pipeline.inference, native.Bench_actions_universal + captured = {} + def capture(**kwargs): + condition = kwargs['conditional_dict'] + np.savez_compressed(case_dir / 'inputs.npz', initial_noise=kwargs['noise'].float().cpu().numpy(), + keyboard=condition['keyboard_cond'][0].float().cpu().numpy(), mouse=condition['mouse_cond'][0].float().cpu().numpy()) + videos = original_inference(**kwargs) + captured['prediction'] = torch.cat(videos, dim=1)[0, 1:25].detach().float().cpu().add(1).div(2) + return videos + engine.pipeline.inference = capture + for row in rows: + case_dir = args.output / f"case{row['global_test_index']}" + case_dir.mkdir(exist_ok=True) + path = args.data_root / row['relative_path'] + rgb = read_frames(path, torch.arange(699, 724)) + images = [Image.fromarray(frame.mul(255).round().byte().permute(1, 2, 0).numpy()) for frame in rgb] + images[0].save(case_dir / 'input.png') + reference = torch.stack([engine.frame_process(engine._resizecrop(im, 352, 640)).add(1).div(2) for im in images[1:]]) + with np.load(path.with_suffix('.npz')) as annotation: + controls = replay_controls(annotation['actions'][700:724], args.mode, 33) + native.Bench_actions_universal = native_controls if args.mode == 'demo_actions' else lambda length: controls + model_args.img_path, model_args.output_folder = str(case_dir / 'input.png'), str(case_dir) + engine.config['mode'] = 'universal' + native.set_seed(42000000 + int(row['global_test_index'])) + engine.generate_videos() + save_result(case_dir, 'comparison', captured.pop('prediction'), reference) + (args.output / 'complete.json').write_text(json.dumps({'mode': args.mode, 'complete': True})) + print('NATIVE_CONTROL_COMPLETE', flush=True) + +if __name__ == '__main__': + main() diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/complete.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/complete.json new file mode 100644 index 0000000000000000000000000000000000000000..12b6cd28d85775b5be35f2407dc7351442c6ba25 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/complete.json @@ -0,0 +1 @@ +{"mode": "official_demo", "complete": true} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/demo.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9fb84c51fce772ca44db5c4d55bddfeaf4d0d699 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/demo.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84ced7733db07bb9514d2bcfbe8d8924dcf0a9d07af18e90ea4896929a8a5e2a +size 10078212 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/demo_icon.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/demo_icon.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c8a7c81dd1f7f0fdaaafd0e1e2efa238a64567d1 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/demo_icon.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a7a28ea7754985e0323280913c18bf9fc43d31b1109e0fe5b6d4dca19325606a +size 9950995 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/inference.py b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/inference.py new file mode 100644 index 0000000000000000000000000000000000000000..f4df03bda84a07a365507a5146938effb5352ffe --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/inference.py @@ -0,0 +1,169 @@ +import os +import argparse +import torch +import numpy as np + +from omegaconf import OmegaConf +from torchvision.transforms import v2 +from diffusers.utils import load_image +from einops import rearrange +from pipeline import CausalInferencePipeline +from wan.vae.wanx_vae import get_wanx_vae_wrapper +from demo_utils.vae_block3 import VAEDecoderWrapper +from utils.visualize import process_video +from utils.misc import set_seed +from utils.conditions import * +from utils.wan_wrapper import WanDiffusionWrapper +from safetensors.torch import load_file + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("--config_path", type=str, default="configs/inference_yaml/inference_universal.yaml", help="Path to the config file") + parser.add_argument("--checkpoint_path", type=str, default="", help="Path to the checkpoint") + parser.add_argument("--img_path", type=str, default="demo_images/universal/0000.png", help="Path to the image") + parser.add_argument("--output_folder", type=str, default="outputs/", help="Output folder") + parser.add_argument("--num_output_frames", type=int, default=150, + help="Number of output latent frames") + parser.add_argument("--seed", type=int, default=0, help="Random seed") + parser.add_argument("--pretrained_model_path", type=str, default="Matrix-Game-2.0", help="Path to the VAE model folder") + args = parser.parse_args() + return args + +class InteractiveGameInference: + def __init__(self, args): + self.args = args + self.device = torch.device("cuda") + self.weight_dtype = torch.bfloat16 + + self._init_config() + self._init_models() + + self.frame_process = v2.Compose([ + v2.Resize(size=(352, 640), antialias=True), + v2.ToTensor(), + v2.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]), + ]) + + def _init_config(self): + self.config = OmegaConf.load(self.args.config_path) + + def _init_models(self): + # Initialize pipeline + generator = WanDiffusionWrapper( + **getattr(self.config, "model_kwargs", {}), is_causal=True) + current_vae_decoder = VAEDecoderWrapper() + vae_state_dict = torch.load(os.path.join(self.args.pretrained_model_path, "Wan2.1_VAE.pth"), map_location="cpu") + decoder_state_dict = {} + for key, value in vae_state_dict.items(): + if 'decoder.' in key or 'conv2' in key: + decoder_state_dict[key] = value + current_vae_decoder.load_state_dict(decoder_state_dict) + current_vae_decoder.to(self.device, torch.float16) + current_vae_decoder.requires_grad_(False) + current_vae_decoder.eval() + current_vae_decoder.compile(mode="max-autotune-no-cudagraphs") + pipeline = CausalInferencePipeline(self.config, generator=generator, vae_decoder=current_vae_decoder) + if self.args.checkpoint_path: + print("Loading Pretrained Model...") + state_dict = load_file(self.args.checkpoint_path) + pipeline.generator.load_state_dict(state_dict) + + self.pipeline = pipeline.to(device=self.device, dtype=self.weight_dtype) + self.pipeline.vae_decoder.to(torch.float16) + + vae = get_wanx_vae_wrapper(self.args.pretrained_model_path, torch.float16) + vae.requires_grad_(False) + vae.eval() + self.vae = vae.to(self.device, self.weight_dtype) + + def _resizecrop(self, image, th, tw): + w, h = image.size + if h / w > th / tw: + new_w = int(w) + new_h = int(new_w * th / tw) + else: + new_h = int(h) + new_w = int(new_h * tw / th) + left = (w - new_w) / 2 + top = (h - new_h) / 2 + right = (w + new_w) / 2 + bottom = (h + new_h) / 2 + image = image.crop((left, top, right, bottom)) + return image + + def generate_videos(self): + mode = self.config.pop('mode') + assert mode in ['universal', 'gta_drive', 'templerun'] + + image = load_image(self.args.img_path) + image = self._resizecrop(image, 352, 640) + image = self.frame_process(image)[None, :, None, :, :].to(dtype=self.weight_dtype, device=self.device) + # Encode the input image as the first latent + padding_video = torch.zeros_like(image).repeat(1, 1, 4 * (self.args.num_output_frames - 1), 1, 1) + img_cond = torch.concat([image, padding_video], dim=2) + tiler_kwargs={"tiled": True, "tile_size": [44, 80], "tile_stride": [23, 38]} + img_cond = self.vae.encode(img_cond, device=self.device, **tiler_kwargs).to(self.device) + mask_cond = torch.ones_like(img_cond) + mask_cond[:, :, 1:] = 0 + cond_concat = torch.cat([mask_cond[:, :4], img_cond], dim=1) + visual_context = self.vae.clip.encode_video(image) + sampled_noise = torch.randn( + [1, 16,self.args.num_output_frames, 44, 80], device=self.device, dtype=self.weight_dtype + ) + num_frames = (self.args.num_output_frames - 1) * 4 + 1 + + conditional_dict = { + "cond_concat": cond_concat.to(device=self.device, dtype=self.weight_dtype), + "visual_context": visual_context.to(device=self.device, dtype=self.weight_dtype) + } + + if mode == 'universal': + cond_data = Bench_actions_universal(num_frames) + mouse_condition = cond_data['mouse_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['mouse_cond'] = mouse_condition + elif mode == 'gta_drive': + cond_data = Bench_actions_gta_drive(num_frames) + mouse_condition = cond_data['mouse_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['mouse_cond'] = mouse_condition + else: + cond_data = Bench_actions_templerun(num_frames) + keyboard_condition = cond_data['keyboard_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['keyboard_cond'] = keyboard_condition + + with torch.no_grad(): + videos = self.pipeline.inference( + noise=sampled_noise, + conditional_dict=conditional_dict, + return_latents=False, + mode=mode, + profile=False + ) + + videos_tensor = torch.cat(videos, dim=1) + videos = rearrange(videos_tensor, "B T C H W -> B T H W C") + videos = ((videos.float() + 1) * 127.5).clip(0, 255).cpu().numpy().astype(np.uint8)[0] + video = np.ascontiguousarray(videos) + mouse_icon = 'assets/images/mouse.png' + if mode != 'templerun': + config = ( + keyboard_condition[0].float().cpu().numpy(), + mouse_condition[0].float().cpu().numpy() + ) + else: + config = ( + keyboard_condition[0].float().cpu().numpy() + ) + process_video(video.astype(np.uint8), self.args.output_folder+f'/demo.mp4', config, mouse_icon, mouse_scale=0.1, process_icon=False, mode=mode) + process_video(video.astype(np.uint8), self.args.output_folder+f'/demo_icon.mp4', config, mouse_icon, mouse_scale=0.1, process_icon=True, mode=mode) + print("Done") + +def main(): + """Main entry point for video generation.""" + args = parse_args() + set_seed(args.seed) + os.makedirs(args.output_folder, exist_ok=True) + pipeline = InteractiveGameInference(args) + pipeline.generate_videos() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/inference_universal.yaml b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/inference_universal.yaml new file mode 100644 index 0000000000000000000000000000000000000000..adec83e8175fbe1c0159e0e39e34e7635c319de4 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/inference_universal.yaml @@ -0,0 +1,21 @@ +denoising_step_list: +- 1000 +- 666 +- 333 +warp_denoising_step: true +ts_schedule: false +mixed_precision: true +seed: 42 +image_or_video_shape: +- 1 +- 16 +- 15 +- 44 +- 80 +num_frame_per_block: 3 +context_noise: 0 +mode: universal +causal: true +model_kwargs: + timestep_shift: 5.0 + model_config: configs/distilled_model/universal \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/launcher.sh b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/launcher.sh new file mode 100644 index 0000000000000000000000000000000000000000..b8daac36b612494e3b61040c1e52ac4e5de3b54b --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/launcher.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +#SBATCH --job-name=matrix-game2-native-control +#SBATCH --array=0-4 +#SBATCH --nodes=1 +#SBATCH --ntasks=1 +#SBATCH --cpus-per-task=14 +#SBATCH --gres=gpu:1 +#SBATCH --time=02:00:00 +#SBATCH --account=berzelius-2026-196 +#SBATCH --chdir=/proj/cvl/users/x_fahkh2/worldmem-baseline-evals +#SBATCH --output=slurm_logs/%x-%A_%a.out +#SBATCH --error=slurm_logs/%x-%A_%a.out +set -euo pipefail +module load buildenv-gcccuda/12.9.1-gcc11 +ROOT=/proj/cvl/users/x_fahkh2/worldmem-baseline-evals +PYTHON=/proj/cvl/users/x_fahkh2/envs/matrix-game2-eval/bin/python +DATA_ROOT=/proj/cvl/users/x_fahkh2/WorldMem_Repro/datasets/minecraft +MODES=(official_demo demo_actions neutral recorded small_mouse) +MODE=${MODES[$SLURM_ARRAY_TASK_ID]} +OUTPUT=$ROOT/Matrix-Game/Matrix-Game-2/outputs/diagnostic_native_${MODE}_job${SLURM_ARRAY_JOB_ID}_task${SLURM_ARRAY_TASK_ID} +export TMPDIR=$ROOT/cache +export TRITON_CACHE_DIR=$ROOT/cache +export TORCHINDUCTOR_CACHE_DIR=$ROOT/cache/torchinductor +export HF_HOME=$ROOT/cache/huggingface +export TORCH_HOME=$ROOT/cache/torch +export XDG_CACHE_HOME=$ROOT/cache +export MPLCONFIGDIR=$ROOT/cache/matplotlib +export PYTHONPATH=$ROOT/Matrix-Game/Matrix-Game-2 +export PYTHONNOUSERSITE=1 PYTHONUNBUFFERED=1 OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 +export WANDB_MODE=disabled HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 +mkdir -p "$TMPDIR" "$TORCHINDUCTOR_CACHE_DIR" "$OUTPUT" +"$PYTHON" "$ROOT/deployment/verify_node.py" --expected-gpus 1 --output "$OUTPUT" +cp "$0" "$OUTPUT/launcher.sh" +cp "$ROOT/deployment/matrix_native_controls.py" "$OUTPUT/probe.py" +cp "$ROOT/Matrix-Game/Matrix-Game-2/inference.py" "$ROOT/Matrix-Game/Matrix-Game-2/configs/inference_yaml/inference_universal.yaml" "$OUTPUT/" +srun --ntasks=1 --gpus-per-task=1 --cpus-per-task=14 --cpu-bind=cores \ + "$PYTHON" "$ROOT/deployment/matrix_native_controls.py" \ + --mode "$MODE" --data-root "$DATA_ROOT" --output "$OUTPUT" diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/manifest.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..2baa50ccab29231aff2a5f4a1664adb0bf31303a --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/manifest.json @@ -0,0 +1,42 @@ +{ + "mode": "official_demo", + "diagnostic_only": true, + "checkpoint": "/proj/cvl/users/x_fahkh2/worldmem-baseline-evals/checkpoints/matrix-game2", + "upstream_revision": "71c3cd7f741311f8100f6cf9cde942b6c1378d11", + "weight_policy": "released raw distilled; original normalization; no optimizer or updates", + "expected_generator_parameters": 1619242304, + "expected_vae_parameters": 126892531, + "expected_clip_parameters": 1193014785, + "batch_size": 1, + "lora": null, + "lr": null, + "activation_checkpointing": false, + "steps": 3, + "shift": 5, + "cache_latents": 6, + "decoder": "official compiled max-autotune-no-cudagraphs", + "official_demo": "unchanged inference.py; supplied painting0000.png; seed0;150latents=597RGB", + "minecraft": { + "anchor": 699, + "native_latents": 9, + "native_rgb": 33, + "scored_slice": [ + 1, + 25 + ], + "targets": [ + 700, + 724 + ], + "recorded_control_alignment": "incoming700:724 plus9noops; small_mouse scales camera only", + "reference": "rawRGB with official center crop and frame_process" + }, + "score_caveat": "Only recorded controls replay GT actions; other modes test stability, not benchmark accuracy", + "cases": [ + { + "image": "demo_images/universal/0000.png", + "seed": 0 + } + ], + "output_frames_per_case": 597 +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/node.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/node.json new file mode 100644 index 0000000000000000000000000000000000000000..01a74644010f15c061d958eb712b8d295c18e56d --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/node.json @@ -0,0 +1,7 @@ +{ + "devices": [ + "NVIDIA H200" + ], + "torch": "2.7.0+cu126", + "slurm_job_id": "85113" +} diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/probe.py b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/probe.py new file mode 100644 index 0000000000000000000000000000000000000000..8c5e386fea438328f89a79c076453c94e2f09ecb --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/probe.py @@ -0,0 +1,106 @@ +"""Official Matrix demo and native-image controls; all scores are diagnostic.""" +import argparse +import json +import os +import subprocess +import sys +from pathlib import Path +import numpy as np +import torch +from PIL import Image +from diagnose_matrix_game2 import save_result +from protocol import minecraft_actions, read_frames, select_cases +from worldmem_adapter import map_actions + +ROOT = Path(__file__).resolve().parents[1] +REPO = ROOT / 'Matrix-Game/Matrix-Game-2' +MODES = ['official_demo', 'demo_actions', 'neutral', 'recorded', 'small_mouse'] + +def replay_controls(raw, mode, length): + keyboard, mouse = map_actions(minecraft_actions(raw), 1.0) + keys, turns = torch.zeros(length, 4), torch.zeros(length, 2) + if mode != 'neutral': + keys[:24], turns[:24] = keyboard, mouse * (0.1 if mode == 'small_mouse' else 1.0) + return {'keyboard_condition': keys, 'mouse_condition': turns} + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--mode', choices=MODES, required=True) + parser.add_argument('--data-root', type=Path, required=True) + parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--dry-run', action='store_true') + args = parser.parse_args() + checkpoint = ROOT / 'checkpoints/matrix-game2' + rows = select_cases(ROOT / 'deployment/manifests/minecraft_test_300.csv', limit=2) + manifest = {'mode': args.mode, 'diagnostic_only': True, 'checkpoint': str(checkpoint), + 'upstream_revision': '71c3cd7f741311f8100f6cf9cde942b6c1378d11', + 'weight_policy': 'released raw distilled; original normalization; no optimizer or updates', + 'expected_generator_parameters': 1619242304, 'expected_vae_parameters': 126892531, + 'expected_clip_parameters': 1193014785, 'batch_size': 1, 'lora': None, 'lr': None, + 'activation_checkpointing': False, 'steps': 3, 'shift': 5, 'cache_latents': 6, + 'decoder': 'official compiled max-autotune-no-cudagraphs', + 'official_demo': 'unchanged inference.py; supplied painting0000.png; seed0;150latents=597RGB', + 'minecraft': {'anchor': 699, 'native_latents': 9, 'native_rgb': 33, 'scored_slice': [1, 25], + 'targets': [700, 724], 'recorded_control_alignment': 'incoming700:724 plus9noops; small_mouse scales camera only', + 'reference': 'rawRGB with official center crop and frame_process'}, + 'score_caveat': 'Only recorded controls replay GT actions; other modes test stability, not benchmark accuracy', + 'cases': ([{'image': 'demo_images/universal/0000.png', 'seed': 0}] if args.mode == 'official_demo' + else [{'index': r['global_test_index'], 'path': r['relative_path'], + 'seed': 42000000 + int(r['global_test_index'])} for r in rows]), + 'output_frames_per_case': 597 if args.mode == 'official_demo' else 33} + if args.dry_run: + print(json.dumps(manifest, indent=2)) + return + args.output.mkdir(parents=True, exist_ok=True) + (args.output / 'manifest.json').write_text(json.dumps(manifest, indent=2)) + os.chdir(REPO) + if args.mode == 'official_demo': + subprocess.run([sys.executable, 'inference.py', '--checkpoint_path', str(checkpoint / 'base_distilled_model/base_distill.safetensors'), + '--pretrained_model_path', str(checkpoint), '--img_path', 'demo_images/universal/0000.png', + '--config_path', 'configs/inference_yaml/inference_universal.yaml', '--seed', '0', + '--num_output_frames', '150', '--output_folder', str(args.output)], check=True) + from torchvision.io import read_video + video, _, _ = read_video(str(args.output / 'demo.mp4'), pts_unit='sec') + assert len(video) == 597 + Image.fromarray(torch.cat([video[t] for t in [0, 1, 2, 24, 100, 596]], dim=1).numpy()).save(args.output / 'samples.jpg') + else: + import inference as native + native.set_seed(0) + model_args = argparse.Namespace(config_path='configs/inference_yaml/inference_universal.yaml', + checkpoint_path=str(checkpoint / 'base_distilled_model/base_distill.safetensors'), + pretrained_model_path=str(checkpoint), num_output_frames=9, seed=0, img_path='', output_folder='') + engine = native.InteractiveGameInference(model_args) + manifest['generator_requires_grad_parameters'] = sum(p.numel() for p in engine.pipeline.generator.parameters() if p.requires_grad) + manifest['inference_grad_policy'] = 'unchanged native no_grad; parameter flags unmodified' + (args.output / 'manifest.json').write_text(json.dumps(manifest, indent=2)) + original_inference, native_controls = engine.pipeline.inference, native.Bench_actions_universal + captured = {} + def capture(**kwargs): + condition = kwargs['conditional_dict'] + np.savez_compressed(case_dir / 'inputs.npz', initial_noise=kwargs['noise'].float().cpu().numpy(), + keyboard=condition['keyboard_cond'][0].float().cpu().numpy(), mouse=condition['mouse_cond'][0].float().cpu().numpy()) + videos = original_inference(**kwargs) + captured['prediction'] = torch.cat(videos, dim=1)[0, 1:25].detach().float().cpu().add(1).div(2) + return videos + engine.pipeline.inference = capture + for row in rows: + case_dir = args.output / f"case{row['global_test_index']}" + case_dir.mkdir(exist_ok=True) + path = args.data_root / row['relative_path'] + rgb = read_frames(path, torch.arange(699, 724)) + images = [Image.fromarray(frame.mul(255).round().byte().permute(1, 2, 0).numpy()) for frame in rgb] + images[0].save(case_dir / 'input.png') + reference = torch.stack([engine.frame_process(engine._resizecrop(im, 352, 640)).add(1).div(2) for im in images[1:]]) + with np.load(path.with_suffix('.npz')) as annotation: + controls = replay_controls(annotation['actions'][700:724], args.mode, 33) + native.Bench_actions_universal = native_controls if args.mode == 'demo_actions' else lambda length: controls + model_args.img_path, model_args.output_folder = str(case_dir / 'input.png'), str(case_dir) + engine.config['mode'] = 'universal' + native.set_seed(42000000 + int(row['global_test_index'])) + engine.generate_videos() + save_result(case_dir, 'comparison', captured.pop('prediction'), reference) + (args.output / 'complete.json').write_text(json.dumps({'mode': args.mode, 'complete': True})) + print('NATIVE_CONTROL_COMPLETE', flush=True) + +if __name__ == '__main__': + main() diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/samples.jpg b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/samples.jpg new file mode 100644 index 0000000000000000000000000000000000000000..534692ebddab46932d00347237c326173c9ca27c --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_official_demo_job85112_task0/samples.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:afc3f0021aec173a8117c4f6225346173ef3c3649a7c136c0ccb36d4816563e9 +size 277269 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/comparison.jpg b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/comparison.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c577b2501a172b5f8535b6d5d00d6fd3934d0215 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/comparison.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79bda2168f937a60d6d0646050f56127c23b7226336fe430e93af62eb4ee9754 +size 102212 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/comparison.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/comparison.json new file mode 100644 index 0000000000000000000000000000000000000000..d519fbd6282e1bd673ec985512b58babe400c9fc --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/comparison.json @@ -0,0 +1,81 @@ +{ + "case": "comparison", + "raw_rgb_psnr": [ + 25.711793899536133, + 5.244641304016113, + 5.923252582550049, + 7.243335247039795, + 7.474766731262207, + 7.688778877258301, + 7.724562644958496, + 7.724119186401367, + 7.586732864379883, + 7.602225303649902, + 7.612397193908691, + 7.641911506652832, + 7.730371952056885, + 7.78223991394043, + 7.874336242675781, + 7.907952785491943, + 7.875397682189941, + 7.89320707321167, + 7.920524597167969, + 7.950427532196045, + 7.6845479011535645, + 7.524905204772949, + 7.746468544006348, + 8.102394104003906 + ], + "raw_rgb_mse": [ + 0.002684235805645585, + 0.2989068329334259, + 0.2556670308113098, + 0.18865419924259186, + 0.17886415123939514, + 0.17026373744010925, + 0.1688665747642517, + 0.168883815407753, + 0.1743117719888687, + 0.1736910492181778, + 0.17328473925590515, + 0.17211107909679413, + 0.1686408668756485, + 0.16663876175880432, + 0.16314223408699036, + 0.16188429296016693, + 0.16310235857963562, + 0.1624348908662796, + 0.16141636669635773, + 0.16030874848365784, + 0.17042966187000275, + 0.176811084151268, + 0.1680169552564621, + 0.154796302318573 + ], + "mean_rgb": [ + 0.7045056819915771, + 0.19928812980651855, + 0.24743865430355072, + 0.3156143128871918, + 0.32675033807754517, + 0.33701616525650024, + 0.3374362289905548, + 0.3371541500091553, + 0.33138635754585266, + 0.33189642429351807, + 0.33079421520233154, + 0.33104297518730164, + 0.33283063769340515, + 0.3347418010234833, + 0.3397929072380066, + 0.34098637104034424, + 0.34001752734184265, + 0.34064778685569763, + 0.3415800631046295, + 0.342707097530365, + 0.33026549220085144, + 0.32284045219421387, + 0.3331608772277832, + 0.3487221896648407 + ] +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/demo.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e32798c8f72eaf459feec06c8304062f3b795782 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/demo.mp4 differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/demo_icon.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/demo_icon.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..2a33dafee0543f22aa299b938b97e3963a612429 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/demo_icon.mp4 differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/input.png b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/input.png new file mode 100644 index 0000000000000000000000000000000000000000..3575844c2a8079d439ece74b50a874c10bbc32f6 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/input.png differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/inputs.npz b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/inputs.npz new file mode 100644 index 0000000000000000000000000000000000000000..f7cee8a4211e14250ee4c98c56120e0ccd62b322 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case0/inputs.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2d97d56ea4798f49e8c43134111292f0d84a9a4bdd5656a98c8378c1569d5ff9 +size 952295 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/comparison.jpg b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/comparison.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ad01db7c63721c00ad8d095e33913c037dd04140 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/comparison.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fec8a264ffca18777638658494e99ad74ef224a3b87a0384a831c33e53798722 +size 189101 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/comparison.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/comparison.json new file mode 100644 index 0000000000000000000000000000000000000000..a2aca32182a5056a9f2236c6def88e646bb355b6 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/comparison.json @@ -0,0 +1,81 @@ +{ + "case": "comparison", + "raw_rgb_psnr": [ + 15.494953155517578, + 11.288851737976074, + 8.964729309082031, + 7.841015815734863, + 6.886514663696289, + 6.564419269561768, + 6.5279998779296875, + 6.482372760772705, + 6.38002872467041, + 6.4821319580078125, + 3.9035301208496094, + 5.6491379737854, + 5.5482330322265625, + 5.530768394470215, + 5.589770317077637, + 5.503669738769531, + 5.526252269744873, + 5.558774471282959, + 5.6577606201171875, + 5.640625953674316, + 5.720058441162109, + 5.735989093780518, + 5.748996734619141, + 5.770988464355469 + ], + "raw_rgb_mse": [ + 0.02821659855544567, + 0.07432156801223755, + 0.12691912055015564, + 0.1643986999988556, + 0.2048087865114212, + 0.22057589888572693, + 0.222433403134346, + 0.22478261590003967, + 0.23014266788959503, + 0.22479508817195892, + 0.4070492684841156, + 0.27232417464256287, + 0.2787255048751831, + 0.2798486053943634, + 0.2760723829269409, + 0.2816002368927002, + 0.2801397740840912, + 0.2780497670173645, + 0.2717840373516083, + 0.2728584408760071, + 0.26791322231292725, + 0.26693227887153625, + 0.26613399386405945, + 0.26478973031044006 + ], + "mean_rgb": [ + 0.6955764293670654, + 0.6338109970092773, + 0.5616069436073303, + 0.5026013851165771, + 0.44758883118629456, + 0.42483723163604736, + 0.4189513623714447, + 0.41665932536125183, + 0.40819987654685974, + 0.4080643653869629, + 0.13215097784996033, + 0.24668142199516296, + 0.23901782929897308, + 0.238117977976799, + 0.2415611445903778, + 0.2371591031551361, + 0.23890843987464905, + 0.2416367530822754, + 0.24713867902755737, + 0.24613834917545319, + 0.2498297542333603, + 0.2500305771827698, + 0.2502730190753937, + 0.25165507197380066 + ] +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/demo.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..44791acf9169d47cbb7fa39f713213127b4c1f45 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/demo.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52a540191cca5661ed1764ad1b00c24ab1d1c12d6f2ec74a8d4c037664f15717 +size 178258 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/demo_icon.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/demo_icon.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..65f5474aede4951e350a2f367267e63720037860 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/demo_icon.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2deec7977fdbfbe32abddf1129e2a15e1366d8225939ad57fd42b1118c1d7858 +size 177081 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/input.png b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/input.png new file mode 100644 index 0000000000000000000000000000000000000000..a240efc2cac61bce8c2f601e02d0eb3207816689 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/input.png differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/inputs.npz b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/inputs.npz new file mode 100644 index 0000000000000000000000000000000000000000..b95e3a8e128ff59a692e6da484376444b68981b3 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/case1/inputs.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5982a67d83e908c6afc786423229c37c6d3cd0ee1b0df17adb63dddbbeaa0de +size 951985 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/complete.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/complete.json new file mode 100644 index 0000000000000000000000000000000000000000..1958c57556c216b3d1f4a30daedc1d62e728b91d --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/complete.json @@ -0,0 +1 @@ +{"mode": "recorded", "complete": true} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/inference.py b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/inference.py new file mode 100644 index 0000000000000000000000000000000000000000..f4df03bda84a07a365507a5146938effb5352ffe --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/inference.py @@ -0,0 +1,169 @@ +import os +import argparse +import torch +import numpy as np + +from omegaconf import OmegaConf +from torchvision.transforms import v2 +from diffusers.utils import load_image +from einops import rearrange +from pipeline import CausalInferencePipeline +from wan.vae.wanx_vae import get_wanx_vae_wrapper +from demo_utils.vae_block3 import VAEDecoderWrapper +from utils.visualize import process_video +from utils.misc import set_seed +from utils.conditions import * +from utils.wan_wrapper import WanDiffusionWrapper +from safetensors.torch import load_file + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("--config_path", type=str, default="configs/inference_yaml/inference_universal.yaml", help="Path to the config file") + parser.add_argument("--checkpoint_path", type=str, default="", help="Path to the checkpoint") + parser.add_argument("--img_path", type=str, default="demo_images/universal/0000.png", help="Path to the image") + parser.add_argument("--output_folder", type=str, default="outputs/", help="Output folder") + parser.add_argument("--num_output_frames", type=int, default=150, + help="Number of output latent frames") + parser.add_argument("--seed", type=int, default=0, help="Random seed") + parser.add_argument("--pretrained_model_path", type=str, default="Matrix-Game-2.0", help="Path to the VAE model folder") + args = parser.parse_args() + return args + +class InteractiveGameInference: + def __init__(self, args): + self.args = args + self.device = torch.device("cuda") + self.weight_dtype = torch.bfloat16 + + self._init_config() + self._init_models() + + self.frame_process = v2.Compose([ + v2.Resize(size=(352, 640), antialias=True), + v2.ToTensor(), + v2.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]), + ]) + + def _init_config(self): + self.config = OmegaConf.load(self.args.config_path) + + def _init_models(self): + # Initialize pipeline + generator = WanDiffusionWrapper( + **getattr(self.config, "model_kwargs", {}), is_causal=True) + current_vae_decoder = VAEDecoderWrapper() + vae_state_dict = torch.load(os.path.join(self.args.pretrained_model_path, "Wan2.1_VAE.pth"), map_location="cpu") + decoder_state_dict = {} + for key, value in vae_state_dict.items(): + if 'decoder.' in key or 'conv2' in key: + decoder_state_dict[key] = value + current_vae_decoder.load_state_dict(decoder_state_dict) + current_vae_decoder.to(self.device, torch.float16) + current_vae_decoder.requires_grad_(False) + current_vae_decoder.eval() + current_vae_decoder.compile(mode="max-autotune-no-cudagraphs") + pipeline = CausalInferencePipeline(self.config, generator=generator, vae_decoder=current_vae_decoder) + if self.args.checkpoint_path: + print("Loading Pretrained Model...") + state_dict = load_file(self.args.checkpoint_path) + pipeline.generator.load_state_dict(state_dict) + + self.pipeline = pipeline.to(device=self.device, dtype=self.weight_dtype) + self.pipeline.vae_decoder.to(torch.float16) + + vae = get_wanx_vae_wrapper(self.args.pretrained_model_path, torch.float16) + vae.requires_grad_(False) + vae.eval() + self.vae = vae.to(self.device, self.weight_dtype) + + def _resizecrop(self, image, th, tw): + w, h = image.size + if h / w > th / tw: + new_w = int(w) + new_h = int(new_w * th / tw) + else: + new_h = int(h) + new_w = int(new_h * tw / th) + left = (w - new_w) / 2 + top = (h - new_h) / 2 + right = (w + new_w) / 2 + bottom = (h + new_h) / 2 + image = image.crop((left, top, right, bottom)) + return image + + def generate_videos(self): + mode = self.config.pop('mode') + assert mode in ['universal', 'gta_drive', 'templerun'] + + image = load_image(self.args.img_path) + image = self._resizecrop(image, 352, 640) + image = self.frame_process(image)[None, :, None, :, :].to(dtype=self.weight_dtype, device=self.device) + # Encode the input image as the first latent + padding_video = torch.zeros_like(image).repeat(1, 1, 4 * (self.args.num_output_frames - 1), 1, 1) + img_cond = torch.concat([image, padding_video], dim=2) + tiler_kwargs={"tiled": True, "tile_size": [44, 80], "tile_stride": [23, 38]} + img_cond = self.vae.encode(img_cond, device=self.device, **tiler_kwargs).to(self.device) + mask_cond = torch.ones_like(img_cond) + mask_cond[:, :, 1:] = 0 + cond_concat = torch.cat([mask_cond[:, :4], img_cond], dim=1) + visual_context = self.vae.clip.encode_video(image) + sampled_noise = torch.randn( + [1, 16,self.args.num_output_frames, 44, 80], device=self.device, dtype=self.weight_dtype + ) + num_frames = (self.args.num_output_frames - 1) * 4 + 1 + + conditional_dict = { + "cond_concat": cond_concat.to(device=self.device, dtype=self.weight_dtype), + "visual_context": visual_context.to(device=self.device, dtype=self.weight_dtype) + } + + if mode == 'universal': + cond_data = Bench_actions_universal(num_frames) + mouse_condition = cond_data['mouse_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['mouse_cond'] = mouse_condition + elif mode == 'gta_drive': + cond_data = Bench_actions_gta_drive(num_frames) + mouse_condition = cond_data['mouse_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['mouse_cond'] = mouse_condition + else: + cond_data = Bench_actions_templerun(num_frames) + keyboard_condition = cond_data['keyboard_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['keyboard_cond'] = keyboard_condition + + with torch.no_grad(): + videos = self.pipeline.inference( + noise=sampled_noise, + conditional_dict=conditional_dict, + return_latents=False, + mode=mode, + profile=False + ) + + videos_tensor = torch.cat(videos, dim=1) + videos = rearrange(videos_tensor, "B T C H W -> B T H W C") + videos = ((videos.float() + 1) * 127.5).clip(0, 255).cpu().numpy().astype(np.uint8)[0] + video = np.ascontiguousarray(videos) + mouse_icon = 'assets/images/mouse.png' + if mode != 'templerun': + config = ( + keyboard_condition[0].float().cpu().numpy(), + mouse_condition[0].float().cpu().numpy() + ) + else: + config = ( + keyboard_condition[0].float().cpu().numpy() + ) + process_video(video.astype(np.uint8), self.args.output_folder+f'/demo.mp4', config, mouse_icon, mouse_scale=0.1, process_icon=False, mode=mode) + process_video(video.astype(np.uint8), self.args.output_folder+f'/demo_icon.mp4', config, mouse_icon, mouse_scale=0.1, process_icon=True, mode=mode) + print("Done") + +def main(): + """Main entry point for video generation.""" + args = parse_args() + set_seed(args.seed) + os.makedirs(args.output_folder, exist_ok=True) + pipeline = InteractiveGameInference(args) + pipeline.generate_videos() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/inference_universal.yaml b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/inference_universal.yaml new file mode 100644 index 0000000000000000000000000000000000000000..adec83e8175fbe1c0159e0e39e34e7635c319de4 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/inference_universal.yaml @@ -0,0 +1,21 @@ +denoising_step_list: +- 1000 +- 666 +- 333 +warp_denoising_step: true +ts_schedule: false +mixed_precision: true +seed: 42 +image_or_video_shape: +- 1 +- 16 +- 15 +- 44 +- 80 +num_frame_per_block: 3 +context_noise: 0 +mode: universal +causal: true +model_kwargs: + timestep_shift: 5.0 + model_config: configs/distilled_model/universal \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/launcher.sh b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/launcher.sh new file mode 100644 index 0000000000000000000000000000000000000000..b8daac36b612494e3b61040c1e52ac4e5de3b54b --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/launcher.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +#SBATCH --job-name=matrix-game2-native-control +#SBATCH --array=0-4 +#SBATCH --nodes=1 +#SBATCH --ntasks=1 +#SBATCH --cpus-per-task=14 +#SBATCH --gres=gpu:1 +#SBATCH --time=02:00:00 +#SBATCH --account=berzelius-2026-196 +#SBATCH --chdir=/proj/cvl/users/x_fahkh2/worldmem-baseline-evals +#SBATCH --output=slurm_logs/%x-%A_%a.out +#SBATCH --error=slurm_logs/%x-%A_%a.out +set -euo pipefail +module load buildenv-gcccuda/12.9.1-gcc11 +ROOT=/proj/cvl/users/x_fahkh2/worldmem-baseline-evals +PYTHON=/proj/cvl/users/x_fahkh2/envs/matrix-game2-eval/bin/python +DATA_ROOT=/proj/cvl/users/x_fahkh2/WorldMem_Repro/datasets/minecraft +MODES=(official_demo demo_actions neutral recorded small_mouse) +MODE=${MODES[$SLURM_ARRAY_TASK_ID]} +OUTPUT=$ROOT/Matrix-Game/Matrix-Game-2/outputs/diagnostic_native_${MODE}_job${SLURM_ARRAY_JOB_ID}_task${SLURM_ARRAY_TASK_ID} +export TMPDIR=$ROOT/cache +export TRITON_CACHE_DIR=$ROOT/cache +export TORCHINDUCTOR_CACHE_DIR=$ROOT/cache/torchinductor +export HF_HOME=$ROOT/cache/huggingface +export TORCH_HOME=$ROOT/cache/torch +export XDG_CACHE_HOME=$ROOT/cache +export MPLCONFIGDIR=$ROOT/cache/matplotlib +export PYTHONPATH=$ROOT/Matrix-Game/Matrix-Game-2 +export PYTHONNOUSERSITE=1 PYTHONUNBUFFERED=1 OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 +export WANDB_MODE=disabled HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 +mkdir -p "$TMPDIR" "$TORCHINDUCTOR_CACHE_DIR" "$OUTPUT" +"$PYTHON" "$ROOT/deployment/verify_node.py" --expected-gpus 1 --output "$OUTPUT" +cp "$0" "$OUTPUT/launcher.sh" +cp "$ROOT/deployment/matrix_native_controls.py" "$OUTPUT/probe.py" +cp "$ROOT/Matrix-Game/Matrix-Game-2/inference.py" "$ROOT/Matrix-Game/Matrix-Game-2/configs/inference_yaml/inference_universal.yaml" "$OUTPUT/" +srun --ntasks=1 --gpus-per-task=1 --cpus-per-task=14 --cpu-bind=cores \ + "$PYTHON" "$ROOT/deployment/matrix_native_controls.py" \ + --mode "$MODE" --data-root "$DATA_ROOT" --output "$OUTPUT" diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/manifest.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..65c1615bf5440f9967e2ab180a9de2c98fa82d50 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/manifest.json @@ -0,0 +1,50 @@ +{ + "mode": "recorded", + "diagnostic_only": true, + "checkpoint": "/proj/cvl/users/x_fahkh2/worldmem-baseline-evals/checkpoints/matrix-game2", + "upstream_revision": "71c3cd7f741311f8100f6cf9cde942b6c1378d11", + "weight_policy": "released raw distilled; original normalization; no optimizer or updates", + "expected_generator_parameters": 1619242304, + "expected_vae_parameters": 126892531, + "expected_clip_parameters": 1193014785, + "batch_size": 1, + "lora": null, + "lr": null, + "activation_checkpointing": false, + "steps": 3, + "shift": 5, + "cache_latents": 6, + "decoder": "official compiled max-autotune-no-cudagraphs", + "official_demo": "unchanged inference.py; supplied painting0000.png; seed0;150latents=597RGB", + "minecraft": { + "anchor": 699, + "native_latents": 9, + "native_rgb": 33, + "scored_slice": [ + 1, + 25 + ], + "targets": [ + 700, + 724 + ], + "recorded_control_alignment": "incoming700:724 plus9noops; small_mouse scales camera only", + "reference": "rawRGB with official center crop and frame_process" + }, + "score_caveat": "Only recorded controls replay GT actions; other modes test stability, not benchmark accuracy", + "cases": [ + { + "index": "0", + "path": "test/val_plains/2/000034.mp4", + "seed": 42000000 + }, + { + "index": "1", + "path": "test/val_desert/1/000029.mp4", + "seed": 42000001 + } + ], + "output_frames_per_case": 33, + "generator_requires_grad_parameters": 1619242304, + "inference_grad_policy": "unchanged native no_grad; parameter flags unmodified" +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/node.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/node.json new file mode 100644 index 0000000000000000000000000000000000000000..847792e59a31650c8f9ea26e5452d285c5914cf2 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/node.json @@ -0,0 +1,7 @@ +{ + "devices": [ + "NVIDIA H200" + ], + "torch": "2.7.0+cu126", + "slurm_job_id": "85116" +} diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/probe.py b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/probe.py new file mode 100644 index 0000000000000000000000000000000000000000..8c5e386fea438328f89a79c076453c94e2f09ecb --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_recorded_job85112_task3/probe.py @@ -0,0 +1,106 @@ +"""Official Matrix demo and native-image controls; all scores are diagnostic.""" +import argparse +import json +import os +import subprocess +import sys +from pathlib import Path +import numpy as np +import torch +from PIL import Image +from diagnose_matrix_game2 import save_result +from protocol import minecraft_actions, read_frames, select_cases +from worldmem_adapter import map_actions + +ROOT = Path(__file__).resolve().parents[1] +REPO = ROOT / 'Matrix-Game/Matrix-Game-2' +MODES = ['official_demo', 'demo_actions', 'neutral', 'recorded', 'small_mouse'] + +def replay_controls(raw, mode, length): + keyboard, mouse = map_actions(minecraft_actions(raw), 1.0) + keys, turns = torch.zeros(length, 4), torch.zeros(length, 2) + if mode != 'neutral': + keys[:24], turns[:24] = keyboard, mouse * (0.1 if mode == 'small_mouse' else 1.0) + return {'keyboard_condition': keys, 'mouse_condition': turns} + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--mode', choices=MODES, required=True) + parser.add_argument('--data-root', type=Path, required=True) + parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--dry-run', action='store_true') + args = parser.parse_args() + checkpoint = ROOT / 'checkpoints/matrix-game2' + rows = select_cases(ROOT / 'deployment/manifests/minecraft_test_300.csv', limit=2) + manifest = {'mode': args.mode, 'diagnostic_only': True, 'checkpoint': str(checkpoint), + 'upstream_revision': '71c3cd7f741311f8100f6cf9cde942b6c1378d11', + 'weight_policy': 'released raw distilled; original normalization; no optimizer or updates', + 'expected_generator_parameters': 1619242304, 'expected_vae_parameters': 126892531, + 'expected_clip_parameters': 1193014785, 'batch_size': 1, 'lora': None, 'lr': None, + 'activation_checkpointing': False, 'steps': 3, 'shift': 5, 'cache_latents': 6, + 'decoder': 'official compiled max-autotune-no-cudagraphs', + 'official_demo': 'unchanged inference.py; supplied painting0000.png; seed0;150latents=597RGB', + 'minecraft': {'anchor': 699, 'native_latents': 9, 'native_rgb': 33, 'scored_slice': [1, 25], + 'targets': [700, 724], 'recorded_control_alignment': 'incoming700:724 plus9noops; small_mouse scales camera only', + 'reference': 'rawRGB with official center crop and frame_process'}, + 'score_caveat': 'Only recorded controls replay GT actions; other modes test stability, not benchmark accuracy', + 'cases': ([{'image': 'demo_images/universal/0000.png', 'seed': 0}] if args.mode == 'official_demo' + else [{'index': r['global_test_index'], 'path': r['relative_path'], + 'seed': 42000000 + int(r['global_test_index'])} for r in rows]), + 'output_frames_per_case': 597 if args.mode == 'official_demo' else 33} + if args.dry_run: + print(json.dumps(manifest, indent=2)) + return + args.output.mkdir(parents=True, exist_ok=True) + (args.output / 'manifest.json').write_text(json.dumps(manifest, indent=2)) + os.chdir(REPO) + if args.mode == 'official_demo': + subprocess.run([sys.executable, 'inference.py', '--checkpoint_path', str(checkpoint / 'base_distilled_model/base_distill.safetensors'), + '--pretrained_model_path', str(checkpoint), '--img_path', 'demo_images/universal/0000.png', + '--config_path', 'configs/inference_yaml/inference_universal.yaml', '--seed', '0', + '--num_output_frames', '150', '--output_folder', str(args.output)], check=True) + from torchvision.io import read_video + video, _, _ = read_video(str(args.output / 'demo.mp4'), pts_unit='sec') + assert len(video) == 597 + Image.fromarray(torch.cat([video[t] for t in [0, 1, 2, 24, 100, 596]], dim=1).numpy()).save(args.output / 'samples.jpg') + else: + import inference as native + native.set_seed(0) + model_args = argparse.Namespace(config_path='configs/inference_yaml/inference_universal.yaml', + checkpoint_path=str(checkpoint / 'base_distilled_model/base_distill.safetensors'), + pretrained_model_path=str(checkpoint), num_output_frames=9, seed=0, img_path='', output_folder='') + engine = native.InteractiveGameInference(model_args) + manifest['generator_requires_grad_parameters'] = sum(p.numel() for p in engine.pipeline.generator.parameters() if p.requires_grad) + manifest['inference_grad_policy'] = 'unchanged native no_grad; parameter flags unmodified' + (args.output / 'manifest.json').write_text(json.dumps(manifest, indent=2)) + original_inference, native_controls = engine.pipeline.inference, native.Bench_actions_universal + captured = {} + def capture(**kwargs): + condition = kwargs['conditional_dict'] + np.savez_compressed(case_dir / 'inputs.npz', initial_noise=kwargs['noise'].float().cpu().numpy(), + keyboard=condition['keyboard_cond'][0].float().cpu().numpy(), mouse=condition['mouse_cond'][0].float().cpu().numpy()) + videos = original_inference(**kwargs) + captured['prediction'] = torch.cat(videos, dim=1)[0, 1:25].detach().float().cpu().add(1).div(2) + return videos + engine.pipeline.inference = capture + for row in rows: + case_dir = args.output / f"case{row['global_test_index']}" + case_dir.mkdir(exist_ok=True) + path = args.data_root / row['relative_path'] + rgb = read_frames(path, torch.arange(699, 724)) + images = [Image.fromarray(frame.mul(255).round().byte().permute(1, 2, 0).numpy()) for frame in rgb] + images[0].save(case_dir / 'input.png') + reference = torch.stack([engine.frame_process(engine._resizecrop(im, 352, 640)).add(1).div(2) for im in images[1:]]) + with np.load(path.with_suffix('.npz')) as annotation: + controls = replay_controls(annotation['actions'][700:724], args.mode, 33) + native.Bench_actions_universal = native_controls if args.mode == 'demo_actions' else lambda length: controls + model_args.img_path, model_args.output_folder = str(case_dir / 'input.png'), str(case_dir) + engine.config['mode'] = 'universal' + native.set_seed(42000000 + int(row['global_test_index'])) + engine.generate_videos() + save_result(case_dir, 'comparison', captured.pop('prediction'), reference) + (args.output / 'complete.json').write_text(json.dumps({'mode': args.mode, 'complete': True})) + print('NATIVE_CONTROL_COMPLETE', flush=True) + +if __name__ == '__main__': + main() diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/comparison.jpg b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/comparison.jpg new file mode 100644 index 0000000000000000000000000000000000000000..67c64e25d5e53116f882c773addd159f0d5eacb5 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/comparison.jpg differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/comparison.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/comparison.json new file mode 100644 index 0000000000000000000000000000000000000000..0d7d5b8786599f6d9fc4da276abb183a7d5fc123 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/comparison.json @@ -0,0 +1,81 @@ +{ + "case": "comparison", + "raw_rgb_psnr": [ + 28.60708236694336, + 25.03569793701172, + 5.018959999084473, + 7.384889125823975, + 7.533627510070801, + 7.599603652954102, + 7.640437126159668, + 7.5618367195129395, + 7.32016134262085, + 7.214138031005859, + 7.293827533721924, + 9.179265022277832, + 8.883769989013672, + 7.208369255065918, + 7.161807537078857, + 7.06353759765625, + 7.072426795959473, + 7.219183444976807, + 7.402562618255615, + 7.483301162719727, + 7.307889461517334, + 7.234793663024902, + 7.245107650756836, + 7.398245334625244 + ], + "raw_rgb_mse": [ + 0.0013781352899968624, + 0.0031363903544843197, + 0.31485018134117126, + 0.1826043426990509, + 0.17645631730556488, + 0.1737959384918213, + 0.1721695363521576, + 0.17531388998031616, + 0.18534627556800842, + 0.18992678821086884, + 0.186473548412323, + 0.12080182135105133, + 0.12930729985237122, + 0.19017921388149261, + 0.19222916662693024, + 0.1966283917427063, + 0.1962263584136963, + 0.18970626592636108, + 0.1818627566099167, + 0.17851300537586212, + 0.18587075173854828, + 0.18902559578418732, + 0.18857721984386444, + 0.18204361200332642 + ], + "mean_rgb": [ + 0.7117173671722412, + 0.7148102521896362, + 0.19500593841075897, + 0.32063478231430054, + 0.3258987069129944, + 0.32893607020378113, + 0.3301492929458618, + 0.32595276832580566, + 0.3140086531639099, + 0.30913710594177246, + 0.31366264820098877, + 0.39693987369537354, + 0.3851563036441803, + 0.3078592121601105, + 0.30555886030197144, + 0.30015668272972107, + 0.3016118109226227, + 0.3094468414783478, + 0.31849607825279236, + 0.3225367069244385, + 0.31422314047813416, + 0.3108382225036621, + 0.3113982081413269, + 0.31849315762519836 + ] +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/demo.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f1cd1afcdc0d4c0b61fa509fdd07f8e796ea9540 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/demo.mp4 differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/demo_icon.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/demo_icon.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..7856a39c341d1b3b22fce23d9270778fd4f252a5 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/demo_icon.mp4 differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/input.png b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/input.png new file mode 100644 index 0000000000000000000000000000000000000000..3575844c2a8079d439ece74b50a874c10bbc32f6 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/input.png differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/inputs.npz b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/inputs.npz new file mode 100644 index 0000000000000000000000000000000000000000..93daefe44801c87c363e8f0cdb7835db2a7335e2 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case0/inputs.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72838d12ebb3dc19ef298830f68d94bf9f85a5ff50ba8851bbee595c913fc309 +size 952295 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/comparison.jpg b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/comparison.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7f935be8c830987af3663ca8f5a13c2daf9a7d5d --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/comparison.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2643606c86fb904bc3264e60d36d3935ff1cce4b5374e902970c9726230474eb +size 167067 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/comparison.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/comparison.json new file mode 100644 index 0000000000000000000000000000000000000000..cf94359e75669f7dcf859810b43a0c60f575879e --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/comparison.json @@ -0,0 +1,81 @@ +{ + "case": "comparison", + "raw_rgb_psnr": [ + 19.905391693115234, + 18.204139709472656, + 17.303102493286133, + 16.15292739868164, + 15.123891830444336, + 14.838737487792969, + 15.071209907531738, + 15.314916610717773, + 15.406350135803223, + 15.718154907226562, + 15.977568626403809, + 15.988106727600098, + 15.825580596923828, + 15.36284351348877, + 14.823203086853027, + 14.14748764038086, + 14.317941665649414, + 15.000207901000977, + 15.61587142944336, + 16.046274185180664, + 16.163511276245117, + 16.180030822753906, + 15.998974800109863, + 15.597412109375 + ], + "raw_rgb_mse": [ + 0.010220236144959927, + 0.015121194534003735, + 0.018607575446367264, + 0.024249756708741188, + 0.030733417719602585, + 0.032819073647260666, + 0.031108494848012924, + 0.02941090054810047, + 0.0287981815636158, + 0.026803065091371536, + 0.0252489373087883, + 0.025187749415636063, + 0.02614821307361126, + 0.02908812090754509, + 0.032936666160821915, + 0.03848142921924591, + 0.037000350654125214, + 0.03162126988172531, + 0.02744181640446186, + 0.02485264651477337, + 0.02419072389602661, + 0.02409888431429863, + 0.025124792009592056, + 0.02755870297551155 + ], + "mean_rgb": [ + 0.7165936827659607, + 0.7167513370513916, + 0.7154880166053772, + 0.709321916103363, + 0.6940903067588806, + 0.6899892091751099, + 0.6924728155136108, + 0.6968027353286743, + 0.6972663402557373, + 0.7005922198295593, + 0.7014625668525696, + 0.700640857219696, + 0.6989141702651978, + 0.6952425241470337, + 0.690796434879303, + 0.6834492087364197, + 0.6836293339729309, + 0.6919822692871094, + 0.6983417868614197, + 0.7024022936820984, + 0.7042455673217773, + 0.7036704421043396, + 0.7022319436073303, + 0.6999043822288513 + ] +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/demo.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a0863370ed2a5137eab0af8828fdc6bc25fb05e4 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/demo.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ba986ff3f0dba42253509f0669020d0b3e72ac771d10191f192318634255b95 +size 118777 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/demo_icon.mp4 b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/demo_icon.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..601817a3755ff1861dac2f3eba5765e5a40c76cd --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/demo_icon.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:191b7f0987fbf02f8e1347c03c45c20c9f9355710fa1b26f76d4d641deadaefc +size 120969 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/input.png b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/input.png new file mode 100644 index 0000000000000000000000000000000000000000..a240efc2cac61bce8c2f601e02d0eb3207816689 Binary files /dev/null and b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/input.png differ diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/inputs.npz b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/inputs.npz new file mode 100644 index 0000000000000000000000000000000000000000..2c0556d95d70117252d9d743a93a4a206c2b8606 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/case1/inputs.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd706d5d2daa33ae15c69bdb605527b2a0bfda59c64eb9c71a593ba7a26843f2 +size 951986 diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/complete.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/complete.json new file mode 100644 index 0000000000000000000000000000000000000000..efcf1d7d0c4ba1ac5c58aca0c1bac96dadaff6c6 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/complete.json @@ -0,0 +1 @@ +{"mode": "small_mouse", "complete": true} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/inference.py b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/inference.py new file mode 100644 index 0000000000000000000000000000000000000000..f4df03bda84a07a365507a5146938effb5352ffe --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/inference.py @@ -0,0 +1,169 @@ +import os +import argparse +import torch +import numpy as np + +from omegaconf import OmegaConf +from torchvision.transforms import v2 +from diffusers.utils import load_image +from einops import rearrange +from pipeline import CausalInferencePipeline +from wan.vae.wanx_vae import get_wanx_vae_wrapper +from demo_utils.vae_block3 import VAEDecoderWrapper +from utils.visualize import process_video +from utils.misc import set_seed +from utils.conditions import * +from utils.wan_wrapper import WanDiffusionWrapper +from safetensors.torch import load_file + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("--config_path", type=str, default="configs/inference_yaml/inference_universal.yaml", help="Path to the config file") + parser.add_argument("--checkpoint_path", type=str, default="", help="Path to the checkpoint") + parser.add_argument("--img_path", type=str, default="demo_images/universal/0000.png", help="Path to the image") + parser.add_argument("--output_folder", type=str, default="outputs/", help="Output folder") + parser.add_argument("--num_output_frames", type=int, default=150, + help="Number of output latent frames") + parser.add_argument("--seed", type=int, default=0, help="Random seed") + parser.add_argument("--pretrained_model_path", type=str, default="Matrix-Game-2.0", help="Path to the VAE model folder") + args = parser.parse_args() + return args + +class InteractiveGameInference: + def __init__(self, args): + self.args = args + self.device = torch.device("cuda") + self.weight_dtype = torch.bfloat16 + + self._init_config() + self._init_models() + + self.frame_process = v2.Compose([ + v2.Resize(size=(352, 640), antialias=True), + v2.ToTensor(), + v2.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]), + ]) + + def _init_config(self): + self.config = OmegaConf.load(self.args.config_path) + + def _init_models(self): + # Initialize pipeline + generator = WanDiffusionWrapper( + **getattr(self.config, "model_kwargs", {}), is_causal=True) + current_vae_decoder = VAEDecoderWrapper() + vae_state_dict = torch.load(os.path.join(self.args.pretrained_model_path, "Wan2.1_VAE.pth"), map_location="cpu") + decoder_state_dict = {} + for key, value in vae_state_dict.items(): + if 'decoder.' in key or 'conv2' in key: + decoder_state_dict[key] = value + current_vae_decoder.load_state_dict(decoder_state_dict) + current_vae_decoder.to(self.device, torch.float16) + current_vae_decoder.requires_grad_(False) + current_vae_decoder.eval() + current_vae_decoder.compile(mode="max-autotune-no-cudagraphs") + pipeline = CausalInferencePipeline(self.config, generator=generator, vae_decoder=current_vae_decoder) + if self.args.checkpoint_path: + print("Loading Pretrained Model...") + state_dict = load_file(self.args.checkpoint_path) + pipeline.generator.load_state_dict(state_dict) + + self.pipeline = pipeline.to(device=self.device, dtype=self.weight_dtype) + self.pipeline.vae_decoder.to(torch.float16) + + vae = get_wanx_vae_wrapper(self.args.pretrained_model_path, torch.float16) + vae.requires_grad_(False) + vae.eval() + self.vae = vae.to(self.device, self.weight_dtype) + + def _resizecrop(self, image, th, tw): + w, h = image.size + if h / w > th / tw: + new_w = int(w) + new_h = int(new_w * th / tw) + else: + new_h = int(h) + new_w = int(new_h * tw / th) + left = (w - new_w) / 2 + top = (h - new_h) / 2 + right = (w + new_w) / 2 + bottom = (h + new_h) / 2 + image = image.crop((left, top, right, bottom)) + return image + + def generate_videos(self): + mode = self.config.pop('mode') + assert mode in ['universal', 'gta_drive', 'templerun'] + + image = load_image(self.args.img_path) + image = self._resizecrop(image, 352, 640) + image = self.frame_process(image)[None, :, None, :, :].to(dtype=self.weight_dtype, device=self.device) + # Encode the input image as the first latent + padding_video = torch.zeros_like(image).repeat(1, 1, 4 * (self.args.num_output_frames - 1), 1, 1) + img_cond = torch.concat([image, padding_video], dim=2) + tiler_kwargs={"tiled": True, "tile_size": [44, 80], "tile_stride": [23, 38]} + img_cond = self.vae.encode(img_cond, device=self.device, **tiler_kwargs).to(self.device) + mask_cond = torch.ones_like(img_cond) + mask_cond[:, :, 1:] = 0 + cond_concat = torch.cat([mask_cond[:, :4], img_cond], dim=1) + visual_context = self.vae.clip.encode_video(image) + sampled_noise = torch.randn( + [1, 16,self.args.num_output_frames, 44, 80], device=self.device, dtype=self.weight_dtype + ) + num_frames = (self.args.num_output_frames - 1) * 4 + 1 + + conditional_dict = { + "cond_concat": cond_concat.to(device=self.device, dtype=self.weight_dtype), + "visual_context": visual_context.to(device=self.device, dtype=self.weight_dtype) + } + + if mode == 'universal': + cond_data = Bench_actions_universal(num_frames) + mouse_condition = cond_data['mouse_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['mouse_cond'] = mouse_condition + elif mode == 'gta_drive': + cond_data = Bench_actions_gta_drive(num_frames) + mouse_condition = cond_data['mouse_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['mouse_cond'] = mouse_condition + else: + cond_data = Bench_actions_templerun(num_frames) + keyboard_condition = cond_data['keyboard_condition'].unsqueeze(0).to(device=self.device, dtype=self.weight_dtype) + conditional_dict['keyboard_cond'] = keyboard_condition + + with torch.no_grad(): + videos = self.pipeline.inference( + noise=sampled_noise, + conditional_dict=conditional_dict, + return_latents=False, + mode=mode, + profile=False + ) + + videos_tensor = torch.cat(videos, dim=1) + videos = rearrange(videos_tensor, "B T C H W -> B T H W C") + videos = ((videos.float() + 1) * 127.5).clip(0, 255).cpu().numpy().astype(np.uint8)[0] + video = np.ascontiguousarray(videos) + mouse_icon = 'assets/images/mouse.png' + if mode != 'templerun': + config = ( + keyboard_condition[0].float().cpu().numpy(), + mouse_condition[0].float().cpu().numpy() + ) + else: + config = ( + keyboard_condition[0].float().cpu().numpy() + ) + process_video(video.astype(np.uint8), self.args.output_folder+f'/demo.mp4', config, mouse_icon, mouse_scale=0.1, process_icon=False, mode=mode) + process_video(video.astype(np.uint8), self.args.output_folder+f'/demo_icon.mp4', config, mouse_icon, mouse_scale=0.1, process_icon=True, mode=mode) + print("Done") + +def main(): + """Main entry point for video generation.""" + args = parse_args() + set_seed(args.seed) + os.makedirs(args.output_folder, exist_ok=True) + pipeline = InteractiveGameInference(args) + pipeline.generate_videos() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/inference_universal.yaml b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/inference_universal.yaml new file mode 100644 index 0000000000000000000000000000000000000000..adec83e8175fbe1c0159e0e39e34e7635c319de4 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/inference_universal.yaml @@ -0,0 +1,21 @@ +denoising_step_list: +- 1000 +- 666 +- 333 +warp_denoising_step: true +ts_schedule: false +mixed_precision: true +seed: 42 +image_or_video_shape: +- 1 +- 16 +- 15 +- 44 +- 80 +num_frame_per_block: 3 +context_noise: 0 +mode: universal +causal: true +model_kwargs: + timestep_shift: 5.0 + model_config: configs/distilled_model/universal \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/launcher.sh b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/launcher.sh new file mode 100644 index 0000000000000000000000000000000000000000..b8daac36b612494e3b61040c1e52ac4e5de3b54b --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/launcher.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +#SBATCH --job-name=matrix-game2-native-control +#SBATCH --array=0-4 +#SBATCH --nodes=1 +#SBATCH --ntasks=1 +#SBATCH --cpus-per-task=14 +#SBATCH --gres=gpu:1 +#SBATCH --time=02:00:00 +#SBATCH --account=berzelius-2026-196 +#SBATCH --chdir=/proj/cvl/users/x_fahkh2/worldmem-baseline-evals +#SBATCH --output=slurm_logs/%x-%A_%a.out +#SBATCH --error=slurm_logs/%x-%A_%a.out +set -euo pipefail +module load buildenv-gcccuda/12.9.1-gcc11 +ROOT=/proj/cvl/users/x_fahkh2/worldmem-baseline-evals +PYTHON=/proj/cvl/users/x_fahkh2/envs/matrix-game2-eval/bin/python +DATA_ROOT=/proj/cvl/users/x_fahkh2/WorldMem_Repro/datasets/minecraft +MODES=(official_demo demo_actions neutral recorded small_mouse) +MODE=${MODES[$SLURM_ARRAY_TASK_ID]} +OUTPUT=$ROOT/Matrix-Game/Matrix-Game-2/outputs/diagnostic_native_${MODE}_job${SLURM_ARRAY_JOB_ID}_task${SLURM_ARRAY_TASK_ID} +export TMPDIR=$ROOT/cache +export TRITON_CACHE_DIR=$ROOT/cache +export TORCHINDUCTOR_CACHE_DIR=$ROOT/cache/torchinductor +export HF_HOME=$ROOT/cache/huggingface +export TORCH_HOME=$ROOT/cache/torch +export XDG_CACHE_HOME=$ROOT/cache +export MPLCONFIGDIR=$ROOT/cache/matplotlib +export PYTHONPATH=$ROOT/Matrix-Game/Matrix-Game-2 +export PYTHONNOUSERSITE=1 PYTHONUNBUFFERED=1 OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 +export WANDB_MODE=disabled HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 +mkdir -p "$TMPDIR" "$TORCHINDUCTOR_CACHE_DIR" "$OUTPUT" +"$PYTHON" "$ROOT/deployment/verify_node.py" --expected-gpus 1 --output "$OUTPUT" +cp "$0" "$OUTPUT/launcher.sh" +cp "$ROOT/deployment/matrix_native_controls.py" "$OUTPUT/probe.py" +cp "$ROOT/Matrix-Game/Matrix-Game-2/inference.py" "$ROOT/Matrix-Game/Matrix-Game-2/configs/inference_yaml/inference_universal.yaml" "$OUTPUT/" +srun --ntasks=1 --gpus-per-task=1 --cpus-per-task=14 --cpu-bind=cores \ + "$PYTHON" "$ROOT/deployment/matrix_native_controls.py" \ + --mode "$MODE" --data-root "$DATA_ROOT" --output "$OUTPUT" diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/manifest.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..eb66b217d45d969e9ba985073f6d07ea542c8603 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/manifest.json @@ -0,0 +1,50 @@ +{ + "mode": "small_mouse", + "diagnostic_only": true, + "checkpoint": "/proj/cvl/users/x_fahkh2/worldmem-baseline-evals/checkpoints/matrix-game2", + "upstream_revision": "71c3cd7f741311f8100f6cf9cde942b6c1378d11", + "weight_policy": "released raw distilled; original normalization; no optimizer or updates", + "expected_generator_parameters": 1619242304, + "expected_vae_parameters": 126892531, + "expected_clip_parameters": 1193014785, + "batch_size": 1, + "lora": null, + "lr": null, + "activation_checkpointing": false, + "steps": 3, + "shift": 5, + "cache_latents": 6, + "decoder": "official compiled max-autotune-no-cudagraphs", + "official_demo": "unchanged inference.py; supplied painting0000.png; seed0;150latents=597RGB", + "minecraft": { + "anchor": 699, + "native_latents": 9, + "native_rgb": 33, + "scored_slice": [ + 1, + 25 + ], + "targets": [ + 700, + 724 + ], + "recorded_control_alignment": "incoming700:724 plus9noops; small_mouse scales camera only", + "reference": "rawRGB with official center crop and frame_process" + }, + "score_caveat": "Only recorded controls replay GT actions; other modes test stability, not benchmark accuracy", + "cases": [ + { + "index": "0", + "path": "test/val_plains/2/000034.mp4", + "seed": 42000000 + }, + { + "index": "1", + "path": "test/val_desert/1/000029.mp4", + "seed": 42000001 + } + ], + "output_frames_per_case": 33, + "generator_requires_grad_parameters": 1619242304, + "inference_grad_policy": "unchanged native no_grad; parameter flags unmodified" +} \ No newline at end of file diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/node.json b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/node.json new file mode 100644 index 0000000000000000000000000000000000000000..c7b31051c846c653dcca93c4fe5bee55bce45b69 --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/node.json @@ -0,0 +1,7 @@ +{ + "devices": [ + "NVIDIA H200" + ], + "torch": "2.7.0+cu126", + "slurm_job_id": "85112" +} diff --git a/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/probe.py b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/probe.py new file mode 100644 index 0000000000000000000000000000000000000000..8c5e386fea438328f89a79c076453c94e2f09ecb --- /dev/null +++ b/results/worldmem-baseline-evals/matrix-game2-native-controls/diagnostic_native_small_mouse_job85112_task4/probe.py @@ -0,0 +1,106 @@ +"""Official Matrix demo and native-image controls; all scores are diagnostic.""" +import argparse +import json +import os +import subprocess +import sys +from pathlib import Path +import numpy as np +import torch +from PIL import Image +from diagnose_matrix_game2 import save_result +from protocol import minecraft_actions, read_frames, select_cases +from worldmem_adapter import map_actions + +ROOT = Path(__file__).resolve().parents[1] +REPO = ROOT / 'Matrix-Game/Matrix-Game-2' +MODES = ['official_demo', 'demo_actions', 'neutral', 'recorded', 'small_mouse'] + +def replay_controls(raw, mode, length): + keyboard, mouse = map_actions(minecraft_actions(raw), 1.0) + keys, turns = torch.zeros(length, 4), torch.zeros(length, 2) + if mode != 'neutral': + keys[:24], turns[:24] = keyboard, mouse * (0.1 if mode == 'small_mouse' else 1.0) + return {'keyboard_condition': keys, 'mouse_condition': turns} + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--mode', choices=MODES, required=True) + parser.add_argument('--data-root', type=Path, required=True) + parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--dry-run', action='store_true') + args = parser.parse_args() + checkpoint = ROOT / 'checkpoints/matrix-game2' + rows = select_cases(ROOT / 'deployment/manifests/minecraft_test_300.csv', limit=2) + manifest = {'mode': args.mode, 'diagnostic_only': True, 'checkpoint': str(checkpoint), + 'upstream_revision': '71c3cd7f741311f8100f6cf9cde942b6c1378d11', + 'weight_policy': 'released raw distilled; original normalization; no optimizer or updates', + 'expected_generator_parameters': 1619242304, 'expected_vae_parameters': 126892531, + 'expected_clip_parameters': 1193014785, 'batch_size': 1, 'lora': None, 'lr': None, + 'activation_checkpointing': False, 'steps': 3, 'shift': 5, 'cache_latents': 6, + 'decoder': 'official compiled max-autotune-no-cudagraphs', + 'official_demo': 'unchanged inference.py; supplied painting0000.png; seed0;150latents=597RGB', + 'minecraft': {'anchor': 699, 'native_latents': 9, 'native_rgb': 33, 'scored_slice': [1, 25], + 'targets': [700, 724], 'recorded_control_alignment': 'incoming700:724 plus9noops; small_mouse scales camera only', + 'reference': 'rawRGB with official center crop and frame_process'}, + 'score_caveat': 'Only recorded controls replay GT actions; other modes test stability, not benchmark accuracy', + 'cases': ([{'image': 'demo_images/universal/0000.png', 'seed': 0}] if args.mode == 'official_demo' + else [{'index': r['global_test_index'], 'path': r['relative_path'], + 'seed': 42000000 + int(r['global_test_index'])} for r in rows]), + 'output_frames_per_case': 597 if args.mode == 'official_demo' else 33} + if args.dry_run: + print(json.dumps(manifest, indent=2)) + return + args.output.mkdir(parents=True, exist_ok=True) + (args.output / 'manifest.json').write_text(json.dumps(manifest, indent=2)) + os.chdir(REPO) + if args.mode == 'official_demo': + subprocess.run([sys.executable, 'inference.py', '--checkpoint_path', str(checkpoint / 'base_distilled_model/base_distill.safetensors'), + '--pretrained_model_path', str(checkpoint), '--img_path', 'demo_images/universal/0000.png', + '--config_path', 'configs/inference_yaml/inference_universal.yaml', '--seed', '0', + '--num_output_frames', '150', '--output_folder', str(args.output)], check=True) + from torchvision.io import read_video + video, _, _ = read_video(str(args.output / 'demo.mp4'), pts_unit='sec') + assert len(video) == 597 + Image.fromarray(torch.cat([video[t] for t in [0, 1, 2, 24, 100, 596]], dim=1).numpy()).save(args.output / 'samples.jpg') + else: + import inference as native + native.set_seed(0) + model_args = argparse.Namespace(config_path='configs/inference_yaml/inference_universal.yaml', + checkpoint_path=str(checkpoint / 'base_distilled_model/base_distill.safetensors'), + pretrained_model_path=str(checkpoint), num_output_frames=9, seed=0, img_path='', output_folder='') + engine = native.InteractiveGameInference(model_args) + manifest['generator_requires_grad_parameters'] = sum(p.numel() for p in engine.pipeline.generator.parameters() if p.requires_grad) + manifest['inference_grad_policy'] = 'unchanged native no_grad; parameter flags unmodified' + (args.output / 'manifest.json').write_text(json.dumps(manifest, indent=2)) + original_inference, native_controls = engine.pipeline.inference, native.Bench_actions_universal + captured = {} + def capture(**kwargs): + condition = kwargs['conditional_dict'] + np.savez_compressed(case_dir / 'inputs.npz', initial_noise=kwargs['noise'].float().cpu().numpy(), + keyboard=condition['keyboard_cond'][0].float().cpu().numpy(), mouse=condition['mouse_cond'][0].float().cpu().numpy()) + videos = original_inference(**kwargs) + captured['prediction'] = torch.cat(videos, dim=1)[0, 1:25].detach().float().cpu().add(1).div(2) + return videos + engine.pipeline.inference = capture + for row in rows: + case_dir = args.output / f"case{row['global_test_index']}" + case_dir.mkdir(exist_ok=True) + path = args.data_root / row['relative_path'] + rgb = read_frames(path, torch.arange(699, 724)) + images = [Image.fromarray(frame.mul(255).round().byte().permute(1, 2, 0).numpy()) for frame in rgb] + images[0].save(case_dir / 'input.png') + reference = torch.stack([engine.frame_process(engine._resizecrop(im, 352, 640)).add(1).div(2) for im in images[1:]]) + with np.load(path.with_suffix('.npz')) as annotation: + controls = replay_controls(annotation['actions'][700:724], args.mode, 33) + native.Bench_actions_universal = native_controls if args.mode == 'demo_actions' else lambda length: controls + model_args.img_path, model_args.output_folder = str(case_dir / 'input.png'), str(case_dir) + engine.config['mode'] = 'universal' + native.set_seed(42000000 + int(row['global_test_index'])) + engine.generate_videos() + save_result(case_dir, 'comparison', captured.pop('prediction'), reference) + (args.output / 'complete.json').write_text(json.dumps({'mode': args.mode, 'complete': True})) + print('NATIVE_CONTROL_COMPLETE', flush=True) + +if __name__ == '__main__': + main()