ckadirt commited on
Commit
ca1ebdb
·
verified ·
1 Parent(s): 1b78df8

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. MindEyeV2/src/TestUnclip.ipynb +0 -0
  2. MindEyeV2/src/TrainB5k.py +1438 -0
  3. MindEyeV2/src/TrainBold5000-Copy1.ipynb +1669 -0
  4. MindEyeV2/src/TrainCluster-Copy2.ipynb +1910 -0
  5. MindEyeV2/src/TrainCluster.ipynb +1785 -0
  6. MindEyeV2/src/TrainCluster.py +1078 -0
  7. MindEyeV2/src/accel.slurm +43 -0
  8. MindEyeV2/src/accelSM.slurm +42 -0
  9. MindEyeV2/src/accel_recon_imagery.slurm +58 -0
  10. MindEyeV2/src/accel_recon_shared1000.slurm +53 -0
  11. MindEyeV2/src/autoencoder/convnext.py +239 -0
  12. MindEyeV2/src/bold5k_preproc.ipynb +0 -0
  13. MindEyeV2/src/enhanced_recon_inference.ipynb +891 -0
  14. MindEyeV2/src/enhanced_recon_inference_old.ipynb +0 -0
  15. MindEyeV2/src/final_evaluations.ipynb +0 -0
  16. MindEyeV2/src/recon_inference.py +580 -0
  17. MindEyeV2/src/recon_inference_old.ipynb +0 -0
  18. MindEyeV2/src/recon_inference_old.py +492 -0
  19. MindEyeV2/src/wandb/debug-cli.ckadirt.log +0 -0
  20. MindEyeV2/src/wandb/debug-internal.log +0 -0
  21. MindEyeV2/src/wandb/debug.log +30 -0
  22. MindEyeV2/src/wandb/run-20240618_035407-rr-test/files/config.yaml +102 -0
  23. MindEyeV2/src/wandb/run-20240618_035407-rr-test/logs/debug-internal.log +61 -0
  24. MindEyeV2/src/wandb/run-20240618_035407-rr-test/logs/debug.log +29 -0
  25. MindEyeV2/src/wandb/run-20240618_035407-rr-test/run-rr-test.wandb +0 -0
  26. MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/code/src/TrainCluster.py +1069 -0
  27. MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/config.yaml +103 -0
  28. MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/diff.patch +230 -0
  29. MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/requirements.txt +214 -0
  30. MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/wandb-metadata.json +1057 -0
  31. MindEyeV2/src/wandb/run-20240618_121613-rr-test/logs/debug-internal.log +52 -0
  32. MindEyeV2/src/wandb/run-20240618_121613-rr-test/logs/debug.log +28 -0
  33. MindEyeV2/src/wandb/run-20240618_121613-rr-test/run-rr-test.wandb +0 -0
  34. MindEyeV2/src/wandb/run-20240618_123614-testing/files/config.yaml +115 -0
  35. MindEyeV2/src/wandb/run-20240618_123614-testing/files/diff.patch +239 -0
  36. MindEyeV2/src/wandb/run-20240618_123614-testing/files/output.log +0 -0
  37. MindEyeV2/src/wandb/run-20240618_123614-testing/files/requirements.txt +214 -0
  38. MindEyeV2/src/wandb/run-20240618_123614-testing/files/wandb-metadata.json +1035 -0
  39. MindEyeV2/src/wandb/run-20240618_123614-testing/files/wandb-summary.json +1 -0
  40. MindEyeV2/src/wandb/run-20240618_123614-testing/logs/debug-internal.log +0 -0
  41. MindEyeV2/src/wandb/run-20240618_123614-testing/logs/debug.log +69 -0
  42. MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/config.yaml +115 -0
  43. MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/diff.patch +240 -0
  44. MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log +19 -0
  45. MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/requirements.txt +214 -0
  46. MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/wandb-metadata.json +1035 -0
  47. MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/wandb-summary.json +1 -0
  48. MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/logs/debug-internal.log +432 -0
  49. MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/logs/debug.log +48 -0
  50. MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/run-testing-tt2.wandb +0 -0
MindEyeV2/src/TestUnclip.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
MindEyeV2/src/TrainB5k.py ADDED
@@ -0,0 +1,1438 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # # Import packages & functions
5
+
6
+ # In[1]:
7
+
8
+
9
+ import os
10
+ import sys
11
+ import json
12
+ import argparse
13
+ import numpy as np
14
+ import math
15
+ from einops import rearrange
16
+ import time
17
+ import random
18
+ import string
19
+ import h5py
20
+ from tqdm import tqdm
21
+ import webdataset as wds
22
+
23
+ import matplotlib.pyplot as plt
24
+ import torch
25
+ import torch.nn as nn
26
+ from torchvision import transforms
27
+ from accelerate import Accelerator
28
+
29
+ # SDXL unCLIP requires code from https://github.com/Stability-AI/generative-models/tree/main
30
+ sys.path.append('generative_models/')
31
+ import sgm
32
+ from generative_models.sgm.modules.encoders.modules import FrozenOpenCLIPImageEmbedder # bigG embedder
33
+
34
+ # tf32 data type is faster than standard float32
35
+ torch.backends.cuda.matmul.allow_tf32 = True
36
+
37
+ # custom functions #
38
+ import utils
39
+
40
+
41
+ # In[2]:
42
+
43
+
44
+ ### Multi-GPU config ###
45
+ local_rank = os.getenv('RANK')
46
+ if local_rank is None:
47
+ local_rank = 0
48
+ else:
49
+ local_rank = int(local_rank)
50
+ print("LOCAL RANK ", local_rank)
51
+
52
+ data_type = torch.float16 # change depending on your mixed_precision
53
+ num_devices = torch.cuda.device_count()
54
+ if num_devices==0: num_devices = 1
55
+
56
+ # First use "accelerate config" in terminal and setup using deepspeed stage 2 with CPU offloading!
57
+ accelerator = Accelerator(split_batches=False, mixed_precision="fp16")
58
+ if utils.is_interactive(): # set batch size here if using interactive notebook instead of submitting job
59
+ global_batch_size = batch_size = 16
60
+
61
+ else:
62
+ global_batch_size = os.environ["GLOBAL_BATCH_SIZE"]
63
+ batch_size = int(os.environ["GLOBAL_BATCH_SIZE"]) // num_devices
64
+
65
+
66
+ # In[3]:
67
+
68
+
69
+ print("PID of this process =",os.getpid())
70
+ device = accelerator.device
71
+ print("device:",device)
72
+ world_size = accelerator.state.num_processes
73
+ distributed = not accelerator.state.distributed_type == 'NO'
74
+ num_devices = torch.cuda.device_count()
75
+ if num_devices==0 or not distributed: num_devices = 1
76
+ num_workers = num_devices
77
+ print(accelerator.state)
78
+
79
+ print("distributed =",distributed, "num_devices =", num_devices, "local rank =", local_rank, "world size =", world_size, "data_type =", data_type)
80
+ print = accelerator.print # only print if local_rank=0
81
+
82
+
83
+ # # Configurations
84
+
85
+ # In[4]:
86
+
87
+
88
+ # if running this interactively, can specify jupyter_args here for argparser to use
89
+ if utils.is_interactive():
90
+ model_name = "testing"
91
+ print("model_name:", model_name)
92
+
93
+ # global_batch_size and batch_size should already be defined in the 2nd cell block
94
+ jupyter_args = f"--data_path=/weka/proj-medarc/shared/bold5000/nsd_general \
95
+ --cache_dir=/weka/proj-medarc/shared/cache \
96
+ --model_name={model_name} \
97
+ --no-multi_subject --subj=1 --batch_size={batch_size} --num_sessions=15 \
98
+ --hidden_dim=1024 --clip_scale=1. \
99
+ --no-blurry_recon --blur_scale=.5 \
100
+ --use_prior --prior_scale=30 \
101
+ --n_blocks=4 --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --no-use_image_aug \
102
+ --ckpt_interval=999 --no-ckpt_saving --no-wandb_log"
103
+ # --multisubject_ckpt=../train_logs/multisubject_subj01_1024_24bs_nolow
104
+
105
+ print(jupyter_args)
106
+ jupyter_args = jupyter_args.split()
107
+
108
+ from IPython.display import clear_output # function to clear print outputs in cell
109
+ get_ipython().run_line_magic('load_ext', 'autoreload')
110
+ # this allows you to change functions in models.py or utils.py and have this notebook automatically update with your revisions
111
+ get_ipython().run_line_magic('autoreload', '2')
112
+
113
+
114
+ # In[5]:
115
+
116
+
117
+ parser = argparse.ArgumentParser(description="Model Training Configuration")
118
+ parser.add_argument(
119
+ "--model_name", type=str, default="testing",
120
+ help="name of model, used for ckpt saving and wandb logging (if enabled)",
121
+ )
122
+ parser.add_argument(
123
+ "--data_path", type=str, default=os.getcwd(),
124
+ help="Path to where NSD data is stored / where to download it to",
125
+ )
126
+ parser.add_argument(
127
+ "--cache_dir", type=str, default=os.getcwd(),
128
+ help="Path to where misc. files downloaded from huggingface are stored. Defaults to current src directory.",
129
+ )
130
+ parser.add_argument(
131
+ "--subj",type=int, default=1, choices=[1,2,3,4,5,6,7,8],
132
+ help="Validate on which subject?",
133
+ )
134
+ parser.add_argument(
135
+ "--multisubject_ckpt", type=str, default=None,
136
+ help="Path to pre-trained multisubject model to finetune a single subject from. multisubject must be False.",
137
+ )
138
+ parser.add_argument(
139
+ "--num_sessions", type=int, default=1,
140
+ help="Number of training sessions to include",
141
+ )
142
+ parser.add_argument(
143
+ "--use_prior",action=argparse.BooleanOptionalAction,default=True,
144
+ help="whether to train diffusion prior (True) or just rely on retrieval part of the pipeline (False)",
145
+ )
146
+ parser.add_argument(
147
+ "--batch_size", type=int, default=16,
148
+ help="Batch size can be increased by 10x if only training retreival submodule and not diffusion prior",
149
+ )
150
+ parser.add_argument(
151
+ "--wandb_log",action=argparse.BooleanOptionalAction,default=False,
152
+ help="whether to log to wandb",
153
+ )
154
+ parser.add_argument(
155
+ "--wandb_project",type=str,default="stability",
156
+ help="wandb project name",
157
+ )
158
+ parser.add_argument(
159
+ "--mixup_pct",type=float,default=.33,
160
+ help="proportion of way through training when to switch from BiMixCo to SoftCLIP",
161
+ )
162
+ parser.add_argument(
163
+ "--blurry_recon",action=argparse.BooleanOptionalAction,default=True,
164
+ help="whether to output blurry reconstructions",
165
+ )
166
+ parser.add_argument(
167
+ "--blur_scale",type=float,default=.5,
168
+ help="multiply loss from blurry recons by this number",
169
+ )
170
+ parser.add_argument(
171
+ "--clip_scale",type=float,default=1.,
172
+ help="multiply contrastive loss by this number",
173
+ )
174
+ parser.add_argument(
175
+ "--prior_scale",type=float,default=30,
176
+ help="multiply diffusion prior loss by this",
177
+ )
178
+ parser.add_argument(
179
+ "--use_image_aug",action=argparse.BooleanOptionalAction,default=False,
180
+ help="whether to use image augmentation",
181
+ )
182
+ parser.add_argument(
183
+ "--num_epochs",type=int,default=150,
184
+ help="number of epochs of training",
185
+ )
186
+ parser.add_argument(
187
+ "--multi_subject",action=argparse.BooleanOptionalAction,default=False,
188
+ )
189
+ parser.add_argument(
190
+ "--new_test",action=argparse.BooleanOptionalAction,default=True,
191
+ )
192
+ parser.add_argument(
193
+ "--n_blocks",type=int,default=4,
194
+ )
195
+ parser.add_argument(
196
+ "--hidden_dim",type=int,default=1024,
197
+ )
198
+ parser.add_argument(
199
+ "--lr_scheduler_type",type=str,default='cycle',choices=['cycle','linear'],
200
+ )
201
+ parser.add_argument(
202
+ "--ckpt_saving",action=argparse.BooleanOptionalAction,default=True,
203
+ )
204
+ parser.add_argument(
205
+ "--ckpt_interval",type=int,default=5,
206
+ help="save backup ckpt and reconstruct every x epochs",
207
+ )
208
+ parser.add_argument(
209
+ "--seed",type=int,default=42,
210
+ )
211
+ parser.add_argument(
212
+ "--max_lr",type=float,default=3e-4,
213
+ )
214
+
215
+ if utils.is_interactive():
216
+ args = parser.parse_args(jupyter_args)
217
+ else:
218
+ args = parser.parse_args()
219
+
220
+ # create global variables without the args prefix
221
+ for attribute_name in vars(args).keys():
222
+ globals()[attribute_name] = getattr(args, attribute_name)
223
+
224
+ # seed all random functions
225
+ utils.seed_everything(seed)
226
+
227
+ outdir = os.path.abspath(f'../train_logs/{model_name}')
228
+ if not os.path.exists(outdir) and ckpt_saving:
229
+ os.makedirs(outdir,exist_ok=True)
230
+
231
+ if use_image_aug or blurry_recon:
232
+ import kornia
233
+ from kornia.augmentation.container import AugmentationSequential
234
+ if use_image_aug:
235
+ img_augment = AugmentationSequential(
236
+ kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1, p=0.3),
237
+ same_on_batch=False,
238
+ data_keys=["input"],
239
+ )
240
+
241
+ if multi_subject:
242
+ subj_list = np.arange(1,9)
243
+ subj_list = subj_list[subj_list != subj]
244
+ else:
245
+ subj_list = [subj]
246
+
247
+ print("subj_list", subj_list, "num_sessions", num_sessions)
248
+
249
+
250
+ # # Prep data, models, and dataloaders
251
+
252
+ # ### Creating wds dataloader, preload betas and all 73k possible images
253
+
254
+ # In[6]:
255
+
256
+
257
+ def my_split_by_node(urls): return urls
258
+ num_voxels_list = []
259
+
260
+ if multi_subject:
261
+ nsessions_allsubj=np.array([15, 15, 15, 9])
262
+ num_samples_per_epoch = (370*15) // num_devices
263
+ else:
264
+ num_samples_per_epoch = (370*num_sessions) // num_devices
265
+
266
+ print("dividing batch size by subj_list, which will then be concatenated across subj during training...")
267
+ batch_size = batch_size // len(subj_list)
268
+ samples_per_session = 370
269
+
270
+
271
+ # In[9]:
272
+
273
+
274
+ from torch.utils.data import DataLoader, Dataset
275
+ from torch.utils.data.distributed import DistributedSampler
276
+ from sklearn.model_selection import train_test_split
277
+
278
+ class BoldDataset(Dataset):
279
+ def __init__(self, voxels, images, sessions_mask, indexes):
280
+ self.voxels = voxels
281
+ self.images = images
282
+ self.sessions_mask = sessions_mask
283
+ self.indexes = indexes
284
+ self.num_samples = len(voxels)
285
+ def __len__(self):
286
+ return self.num_samples
287
+ def __getitem__(self, idx):
288
+ return self.voxels[idx], self.images[idx], self.sessions_mask[idx], self.indexes[idx]
289
+
290
+ def get_voxels_and_images(subj, num_sessions, data_path, mode, random_state = 42):
291
+ """
292
+ subj: int, subject number
293
+ num_sessions: int, number of sessions to include, can be -1 for all
294
+ data_path: str, path to the data
295
+ mode: str, mode can be 'train', 'val', 'shared' and 'all' and "t&v"
296
+ random_state: int, random state for train_test_split
297
+ """
298
+
299
+ # load the voxels
300
+ all_voxels = torch.load(os.path.join(data_path, f"subj{subj}/wholebrain.pt"))
301
+ # all_voxels = torch.load(os.path.join(data_path, f"subj{subj}/voxels.pt"))
302
+ all_voxels = torch.where(torch.isnan(all_voxels), torch.zeros_like(all_voxels), all_voxels)
303
+ # load the other files
304
+ all_images = torch.load(os.path.join(data_path, f"subj{subj}/images_stimuli.pt"))
305
+ shared_images_mask = torch.load(os.path.join(data_path, f"subj{subj}/shared_images_mask.pt"))
306
+ sessions_mask = torch.load(os.path.join(data_path, f"subj{subj}/sessions_mask.pt"))
307
+ indexes = np.linspace(0, all_voxels.shape[0],num=all_voxels.shape[0], dtype=int)
308
+ # split the data into train and val with sklearn train_test_split
309
+ voxels_train, voxels_val, images_train, images_val, shared_images_mask_train, shared_images_mask_val, sessions_mask_train, sessions_mask_val, indexes_train, indexes_val = train_test_split(all_voxels, all_images, shared_images_mask, sessions_mask, indexes, test_size=0.1, random_state=random_state)
310
+
311
+ if mode == 'train':
312
+ # apply the shared images mask removing the ones in which is 1
313
+ voxels_train = voxels_train[shared_images_mask_train==0]
314
+ images_train = images_train[shared_images_mask_train==0]
315
+ sessions_mask_train = sessions_mask_train[shared_images_mask_train==0]
316
+ indexes_train = indexes_train[shared_images_mask_train==0]
317
+
318
+ # apply the sessions mask, the mask has values from 1 to 15, if num_sessions is 4, we will take the elements in which the value is 1 to 4
319
+ if num_sessions != -1:
320
+ voxels_train = voxels_train[sessions_mask_train <= num_sessions]
321
+ images_train = images_train[sessions_mask_train <= num_sessions]
322
+ indexes_train = indexes_train[sessions_mask_train <= num_sessions]
323
+ sessions_mask_train = sessions_mask_train[sessions_mask_train <= num_sessions]
324
+
325
+ return voxels_train, images_train, sessions_mask_train, indexes_train
326
+
327
+ elif mode == 'val':
328
+ # apply the shared images mask removing the ones in which is 1
329
+ voxels_val = voxels_val[shared_images_mask_val==0]
330
+ images_val = images_val[shared_images_mask_val==0]
331
+ sessions_mask_val = sessions_mask_val[shared_images_mask_val==0]
332
+ indexes_val = indexes_val[shared_images_mask_val==0]
333
+
334
+ return voxels_val, images_val, sessions_mask_val, indexes_val
335
+
336
+ elif mode == 'shared':
337
+ # apply the shared images mask taking only the ones in which is 1
338
+ voxels_shared = all_voxels[shared_images_mask==1]
339
+ images_shared = all_images[shared_images_mask==1]
340
+ indexes_shared = indexes[shared_images_mask==1]
341
+ sessions_mask_shared = sessions_mask[shared_images_mask==1]
342
+
343
+ return voxels_shared, images_shared, sessions_mask_shared, indexes_shared
344
+
345
+ elif mode == 't&v':
346
+ voxels_tv = all_voxels[shared_images_mask==0]
347
+ images_tv = all_images[shared_images_mask==0]
348
+ indexes_tv = indexes[shared_images_mask==0]
349
+ sessions_mask_tv = sessions_mask[shared_images_mask==0]
350
+
351
+ return voxels_tv, images_tv, sessions_mask_tv, indexes_tv
352
+
353
+ elif mode == 'all':
354
+ return all_voxels, all_images, sessions_mask, indexes
355
+
356
+ # voxels, images, sessions_idx, sample_idx = get_voxels_and_images(subj, num_sessions, data_path, 'train')
357
+ # print("voxels.shape", voxels.shape, "images.shape", images.shape, "sessions_idx.shape", sessions_idx.shape, "sample_idx.shape", sample_idx.shape)
358
+
359
+
360
+ # In[11]:
361
+
362
+
363
+ train_data = {}
364
+ train_dl = {}
365
+ num_voxels = {}
366
+ voxels = {}
367
+ for s in subj_list:
368
+ # TODO: Check num_sessions is working, replace -1
369
+ voxels_train, images_train, sessions_idx_train, sample_idx_train = get_voxels_and_images(s, -1, data_path, 'train')
370
+ train_data[f'subj0{s}'] = BoldDataset(voxels_train, images_train, sessions_idx_train, sample_idx_train)
371
+ train_dl[f'subj0{s}'] = DataLoader(train_data[f'subj0{s}'], batch_size=batch_size, shuffle=True, num_workers=num_workers, pin_memory=True, drop_last=True)
372
+ print(f"Training with {num_sessions} sessions")
373
+ num_voxels[f'subj0{s}'] = voxels_train.shape[-1]
374
+ num_voxels_list.append(num_voxels[f'subj0{s}'])
375
+ # TODO: Delete this part if it's not needed and delete the variable declaration above as well
376
+ voxels[f'subj0{s}'] = voxels_train
377
+
378
+ print("Loaded all subj train dls and betas!\n")
379
+
380
+ # if multi_subject:
381
+ # train_url = f"{data_path}/wds/subj0{s}/train/" + "{0.." + f"{nsessions_allsubj[s-1]-1}" + "}.tar"
382
+ # else:
383
+ # train_url = f"{data_path}/wds/subj0{s}/train/" + "{0.." + f"{num_sessions-1}" + "}.tar"
384
+ # print(train_url)
385
+
386
+ # train_data[f'subj0{s}'] = wds.WebDataset(train_url,resampled=True,nodesplitter=my_split_by_node)\
387
+ # .shuffle(750, initial=1500, rng=random.Random(42))\
388
+ # .decode("torch")\
389
+ # .rename(behav="behav.npy", past_behav="past_behav.npy", future_behav="future_behav.npy", olds_behav="olds_behav.npy")\
390
+ # .to_tuple(*["behav", "past_behav", "future_behav", "olds_behav"])
391
+ # train_dl[f'subj0{s}'] = torch.utils.data.DataLoader(train_data[f'subj0{s}'], batch_size=batch_size, shuffle=False, drop_last=False, pin_memory=True)
392
+
393
+ # f = h5py.File(f'{data_path}/betas_all_subj0{s}_fp32_renorm.hdf5', 'r')
394
+ # betas = f['betas'][:]
395
+ # betas = torch.Tensor(betas).to("cpu").to(data_type)
396
+ # num_voxels_list.append(betas[0].shape[-1])
397
+ # num_voxels[f'subj0{s}'] = betas[0].shape[-1]
398
+ # voxels[f'subj0{s}'] = betas
399
+ # print(f"num_voxels for subj0{s}: {num_voxels[f'subj0{s}']}")
400
+
401
+ print("Loaded all subj train dls and betas!\n")
402
+
403
+ # Validate only on one subject
404
+ if multi_subject:
405
+ subj = subj_list[0] # cant validate on the actual held out person so picking first in subj_list
406
+ # if not new_test: # using old test set from before full dataset released (used in original MindEye paper)
407
+ # if subj==3:
408
+ # num_test=2113
409
+ # elif subj==4:
410
+ # num_test=1985
411
+ # elif subj==6:
412
+ # num_test=2113
413
+ # elif subj==8:
414
+ # num_test=1985
415
+ # else:
416
+ # num_test=2770
417
+ # test_url = f"{data_path}/wds/subj0{subj}/test/" + "0.tar"
418
+ # elif new_test: # using larger test set from after full dataset released
419
+ # if subj==3:
420
+ # num_test=2371
421
+ # elif subj==4:
422
+ # num_test=2188
423
+ # elif subj==6:
424
+ # num_test=2371
425
+ # elif subj==8:
426
+ # num_test=2188
427
+ # else:
428
+ # num_test=3000
429
+ # test_url = f"{data_path}/wds/subj0{subj}/new_test/" + "0.tar"
430
+ # print(test_url)
431
+
432
+ voxels_test, images_test, sessions_idx_test, sample_idx_test = get_voxels_and_images(subj, num_sessions, data_path, 'val')
433
+ test_data = BoldDataset(voxels_test, images_test, sessions_idx_test, sample_idx_test)
434
+ test_dl = DataLoader(test_data, batch_size=voxels_test.shape[0], shuffle=False, num_workers=num_workers, pin_memory=True)
435
+ num_test = voxels_test.shape[0]
436
+ # test_data = wds.WebDataset(test_url,resampled=False,nodesplitter=my_split_by_node)\
437
+ # .shuffle(750, initial=1500, rng=random.Random(42))\
438
+ # .decode("torch")\
439
+ # .rename(behav="behav.npy", past_behav="past_behav.npy", future_behav="future_behav.npy", olds_behav="olds_behav.npy")\
440
+ # .to_tuple(*["behav", "past_behav", "future_behav", "olds_behav"])
441
+ # test_dl = torch.utils.data.DataLoader(test_data, batch_size=num_test, shuffle=False, drop_last=True, pin_memory=True)
442
+ print(f"Loaded test dl for subj{subj}!\n")
443
+
444
+
445
+ # In[13]:
446
+
447
+
448
+ num_samples_per_epoch = 0
449
+ for dt_c in train_data:
450
+ num_samples_per_epoch = num_samples_per_epoch + train_data[dt_c].voxels.shape[0]
451
+ # num_iterations_per_epoch = num_samples_per_epoch // (batch_size*len(subj_list))
452
+ num_iterations_per_epoch = num_samples_per_epoch // (batch_size*len(subj_list))
453
+
454
+ print("batch_size =", batch_size, "num_iterations_per_epoch =",num_iterations_per_epoch, "num_samples_per_epoch =",num_samples_per_epoch)
455
+
456
+
457
+ # In[14]:
458
+
459
+
460
+ # # now plot inside the traning loop
461
+ # for batch in train_dl[f'subj0{subj}']:
462
+ # voxels, images, sessions_idx, sample_idx = batch
463
+ # print("voxels.shape", voxels.shape, "images.shape", images.shape, "sessions_idx.shape", sessions_idx.shape, "sample_idx.shape", sample_idx.shape)
464
+ # indexes_to_plot = [1,3,4,5,6]
465
+ # fig, axs = plt.subplots(1, len(indexes_to_plot), figsize=(20, 5))
466
+ # for i, idx in enumerate(indexes_to_plot):
467
+ # axs[i].imshow(images[idx].permute(1, 2, 0))
468
+ # axs[i].axis('off')
469
+ # plt.show()
470
+ # break
471
+
472
+ # # now plot inside the traning loop
473
+ # for batch in test_dl:
474
+ # voxels, images, sessions_idx, sample_idx = batch
475
+ # print("voxels.shape", voxels.shape, "images.shape", images.shape, "sessions_idx.shape", sessions_idx.shape, "sample_idx.shape", sample_idx.shape)
476
+ # indexes_to_plot = [1,3,4,5,6]
477
+ # fig, axs = plt.subplots(1, len(indexes_to_plot), figsize=(20, 5))
478
+ # for i, idx in enumerate(indexes_to_plot):
479
+ # axs[i].imshow(images[idx].permute(1, 2, 0))
480
+ # axs[i].axis('off')
481
+ # plt.show()
482
+ # break
483
+
484
+
485
+ # In[15]:
486
+
487
+
488
+ # train_data = {}
489
+ # train_dl = {}
490
+ # num_voxels = {}
491
+ # voxels = {}
492
+ # for s in subj_list:
493
+ # print(f"Training with {num_sessions} sessions")
494
+ # if multi_subject:
495
+ # train_url = f"{data_path}/wds/subj0{s}/train/" + "{0.." + f"{nsessions_allsubj[s-1]-1}" + "}.tar"
496
+ # else:
497
+ # train_url = f"{data_path}/wds/subj0{s}/train/" + "{0.." + f"{num_sessions-1}" + "}.tar"
498
+ # print(train_url)
499
+
500
+ # train_data[f'subj0{s}'] = wds.WebDataset(train_url,resampled=True,nodesplitter=my_split_by_node)\
501
+ # .shuffle(750, initial=1500, rng=random.Random(42))\
502
+ # .decode("torch")\
503
+ # .rename(behav="behav.npy", past_behav="past_behav.npy", future_behav="future_behav.npy", olds_behav="olds_behav.npy")\
504
+ # .to_tuple(*["behav", "past_behav", "future_behav", "olds_behav"])
505
+ # train_dl[f'subj0{s}'] = torch.utils.data.DataLoader(train_data[f'subj0{s}'], batch_size=batch_size, shuffle=False, drop_last=False, pin_memory=True)
506
+
507
+ # f = h5py.File(f'{data_path}/betas_all_subj0{s}_fp32_renorm.hdf5', 'r')
508
+ # betas = f['betas'][:]
509
+ # betas = torch.Tensor(betas).to("cpu").to(data_type)
510
+ # num_voxels_list.append(betas[0].shape[-1])
511
+ # num_voxels[f'subj0{s}'] = betas[0].shape[-1]
512
+ # voxels[f'subj0{s}'] = betas
513
+ # print(f"num_voxels for subj0{s}: {num_voxels[f'subj0{s}']}")
514
+
515
+ # print("Loaded all subj train dls and betas!\n")
516
+
517
+ # # Validate only on one subject
518
+ # if multi_subject:
519
+ # subj = subj_list[0] # cant validate on the actual held out person so picking first in subj_list
520
+ # if not new_test: # using old test set from before full dataset released (used in original MindEye paper)
521
+ # if subj==3:
522
+ # num_test=2113
523
+ # elif subj==4:
524
+ # num_test=1985
525
+ # elif subj==6:
526
+ # num_test=2113
527
+ # elif subj==8:
528
+ # num_test=1985
529
+ # else:
530
+ # num_test=2770
531
+ # test_url = f"{data_path}/wds/subj0{subj}/test/" + "0.tar"
532
+ # elif new_test: # using larger test set from after full dataset released
533
+ # if subj==3:
534
+ # num_test=2371
535
+ # elif subj==4:
536
+ # num_test=2188
537
+ # elif subj==6:
538
+ # num_test=2371
539
+ # elif subj==8:
540
+ # num_test=2188
541
+ # else:
542
+ # num_test=3000
543
+ # test_url = f"{data_path}/wds/subj0{subj}/new_test/" + "0.tar"
544
+ # print(test_url)
545
+ # test_data = wds.WebDataset(test_url,resampled=False,nodesplitter=my_split_by_node)\
546
+ # .shuffle(750, initial=1500, rng=random.Random(42))\
547
+ # .decode("torch")\
548
+ # .rename(behav="behav.npy", past_behav="past_behav.npy", future_behav="future_behav.npy", olds_behav="olds_behav.npy")\
549
+ # .to_tuple(*["behav", "past_behav", "future_behav", "olds_behav"])
550
+ # test_dl = torch.utils.data.DataLoader(test_data, batch_size=num_test, shuffle=False, drop_last=True, pin_memory=True)
551
+ # print(f"Loaded test dl for subj{subj}!\n")
552
+
553
+
554
+ # In[16]:
555
+
556
+
557
+ # # Load 73k NSD images
558
+ # f = h5py.File(f'{data_path}/coco_images_224_float16.hdf5', 'r')
559
+ # images = f['images']
560
+ # print("Loaded all 73k possible NSD images to cpu!", images.shape)
561
+
562
+
563
+ # ## Load models
564
+
565
+ # ### CLIP image embeddings model
566
+
567
+ # In[17]:
568
+
569
+
570
+ clip_img_embedder = FrozenOpenCLIPImageEmbedder(
571
+ arch="ViT-bigG-14",
572
+ version="laion2b_s39b_b160k",
573
+ output_tokens=True,
574
+ only_tokens=True,
575
+ )
576
+ clip_img_embedder.to(device)
577
+
578
+ clip_seq_dim = 256
579
+ clip_emb_dim = 1664
580
+
581
+
582
+ # ### SD VAE
583
+
584
+ # In[18]:
585
+
586
+
587
+ if blurry_recon:
588
+ from diffusers import AutoencoderKL
589
+ autoenc = AutoencoderKL(
590
+ down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D'],
591
+ up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D'],
592
+ block_out_channels=[128, 256, 512, 512],
593
+ layers_per_block=2,
594
+ sample_size=256,
595
+ )
596
+ ckpt = torch.load(f'{cache_dir}/sd_image_var_autoenc.pth')
597
+ autoenc.load_state_dict(ckpt)
598
+
599
+ autoenc.eval()
600
+ autoenc.requires_grad_(False)
601
+ autoenc.to(device)
602
+ utils.count_params(autoenc)
603
+
604
+ from autoencoder.convnext import ConvnextXL
605
+ cnx = ConvnextXL(f'{cache_dir}/convnext_xlarge_alpha0.75_fullckpt.pth')
606
+ cnx.requires_grad_(False)
607
+ cnx.eval()
608
+ cnx.to(device)
609
+
610
+ mean = torch.tensor([0.485, 0.456, 0.406]).to(device).reshape(1,3,1,1)
611
+ std = torch.tensor([0.228, 0.224, 0.225]).to(device).reshape(1,3,1,1)
612
+
613
+ blur_augs = AugmentationSequential(
614
+ kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1, p=0.8),
615
+ kornia.augmentation.RandomGrayscale(p=0.1),
616
+ kornia.augmentation.RandomSolarize(p=0.1),
617
+ kornia.augmentation.RandomResizedCrop((224,224), scale=(.9,.9), ratio=(1,1), p=1.0),
618
+ data_keys=["input"],
619
+ )
620
+
621
+
622
+ # ### MindEye modules
623
+
624
+ # In[19]:
625
+
626
+
627
+ class MindEyeModule(nn.Module):
628
+ def __init__(self):
629
+ super(MindEyeModule, self).__init__()
630
+ def forward(self, x):
631
+ return x
632
+
633
+ model = MindEyeModule()
634
+ model
635
+
636
+
637
+ # In[20]:
638
+
639
+
640
+ class RidgeRegression(torch.nn.Module):
641
+ # make sure to add weight_decay when initializing optimizer to enable regularization
642
+ def __init__(self, input_sizes, out_features):
643
+ super(RidgeRegression, self).__init__()
644
+ self.out_features = out_features
645
+ self.linears = torch.nn.ModuleList([
646
+ torch.nn.Linear(input_size, out_features) for input_size in input_sizes
647
+ ])
648
+ def forward(self, x, subj_idx):
649
+ out = self.linears[subj_idx](x[:,0]).unsqueeze(1)
650
+ return out
651
+
652
+ model.ridge = RidgeRegression(num_voxels_list, out_features=hidden_dim)
653
+ utils.count_params(model.ridge)
654
+ utils.count_params(model)
655
+
656
+ # test on subject 1 with fake data
657
+ b = torch.randn((2,1,num_voxels_list[0]))
658
+ print(b.shape, model.ridge(b,0).shape)
659
+
660
+
661
+ # In[21]:
662
+
663
+
664
+ from models import BrainNetwork
665
+ model.backbone = BrainNetwork(h=hidden_dim, in_dim=hidden_dim, seq_len=1, n_blocks=n_blocks,
666
+ clip_size=clip_emb_dim, out_dim=clip_emb_dim*clip_seq_dim,
667
+ blurry_recon=blurry_recon, clip_scale=clip_scale)
668
+ utils.count_params(model.backbone)
669
+ utils.count_params(model)
670
+
671
+ # test that the model works on some fake data
672
+ b = torch.randn((2,1,hidden_dim))
673
+ print("b.shape",b.shape)
674
+
675
+ backbone_, clip_, blur_ = model.backbone(b)
676
+ print(backbone_.shape, clip_.shape, blur_[0].shape, blur_[1].shape)
677
+
678
+
679
+ # ### Adding diffusion prior + unCLIP if use_prior=True
680
+
681
+ # In[22]:
682
+
683
+
684
+ if use_prior:
685
+ from models import *
686
+
687
+ # setup diffusion prior network
688
+ out_dim = clip_emb_dim
689
+ depth = 6
690
+ dim_head = 52
691
+ heads = clip_emb_dim//52 # heads * dim_head = clip_emb_dim
692
+ timesteps = 100
693
+
694
+ prior_network = PriorNetwork(
695
+ dim=out_dim,
696
+ depth=depth,
697
+ dim_head=dim_head,
698
+ heads=heads,
699
+ causal=False,
700
+ num_tokens = clip_seq_dim,
701
+ learned_query_mode="pos_emb"
702
+ )
703
+
704
+ model.diffusion_prior = BrainDiffusionPrior(
705
+ net=prior_network,
706
+ image_embed_dim=out_dim,
707
+ condition_on_text_encodings=False,
708
+ timesteps=timesteps,
709
+ cond_drop_prob=0.2,
710
+ image_embed_scale=None,
711
+ )
712
+
713
+ utils.count_params(model.diffusion_prior)
714
+ utils.count_params(model)
715
+
716
+
717
+ # ### Setup optimizer / lr / ckpt saving
718
+
719
+ # In[23]:
720
+
721
+
722
+ no_decay = ['bias', 'LayerNorm.bias', 'LayerNorm.weight']
723
+
724
+ opt_grouped_parameters = [
725
+ {'params': [p for n, p in model.ridge.named_parameters()], 'weight_decay': 1e-2},
726
+ {'params': [p for n, p in model.backbone.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},
727
+ {'params': [p for n, p in model.backbone.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0},
728
+ ]
729
+ if use_prior:
730
+ opt_grouped_parameters.extend([
731
+ {'params': [p for n, p in model.diffusion_prior.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},
732
+ {'params': [p for n, p in model.diffusion_prior.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0}
733
+ ])
734
+
735
+ optimizer = torch.optim.AdamW(opt_grouped_parameters, lr=max_lr)
736
+
737
+ if lr_scheduler_type == 'linear':
738
+ lr_scheduler = torch.optim.lr_scheduler.LinearLR(
739
+ optimizer,
740
+ total_iters=int(np.floor(num_epochs*num_iterations_per_epoch)),
741
+ last_epoch=-1
742
+ )
743
+ elif lr_scheduler_type == 'cycle':
744
+ total_steps=int(np.floor(num_epochs*num_iterations_per_epoch))
745
+ print("total_steps", total_steps)
746
+ lr_scheduler = torch.optim.lr_scheduler.OneCycleLR(
747
+ optimizer,
748
+ max_lr=max_lr,
749
+ total_steps=total_steps,
750
+ final_div_factor=1000,
751
+ last_epoch=-1, pct_start=2/num_epochs
752
+ )
753
+
754
+ def save_ckpt(tag):
755
+ ckpt_path = outdir+f'/{tag}.pth'
756
+ if accelerator.is_main_process:
757
+ unwrapped_model = accelerator.unwrap_model(model)
758
+ torch.save({
759
+ 'epoch': epoch,
760
+ 'model_state_dict': unwrapped_model.state_dict(),
761
+ 'optimizer_state_dict': optimizer.state_dict(),
762
+ 'lr_scheduler': lr_scheduler.state_dict(),
763
+ 'train_losses': losses,
764
+ 'test_losses': test_losses,
765
+ 'lrs': lrs,
766
+ }, ckpt_path)
767
+ print(f"\n---saved {outdir}/{tag} ckpt!---\n")
768
+
769
+ def load_ckpt(tag,load_lr=True,load_optimizer=True,load_epoch=True,strict=True,outdir=outdir,multisubj_loading=False):
770
+ print(f"\n---loading {outdir}/{tag}.pth ckpt---\n")
771
+ checkpoint = torch.load(outdir+'/last.pth', map_location='cpu')
772
+ state_dict = checkpoint['model_state_dict']
773
+ if multisubj_loading: # remove incompatible ridge layer that will otherwise error
774
+ state_dict.pop('ridge.linears.0.weight',None)
775
+ model.load_state_dict(state_dict, strict=strict)
776
+ if load_epoch:
777
+ globals()["epoch"] = checkpoint['epoch']
778
+ print("Epoch",epoch)
779
+ if load_optimizer:
780
+ optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
781
+ if load_lr:
782
+ lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])
783
+ del checkpoint
784
+
785
+ print("\nDone with model preparations!")
786
+ num_params = utils.count_params(model)
787
+
788
+
789
+ # # Weights and Biases
790
+
791
+ # In[24]:
792
+
793
+
794
+ if local_rank==0 and wandb_log: # only use main process for wandb logging
795
+ import wandb
796
+ wandb_project = 'mindeye'
797
+ print(f"wandb {wandb_project} run {model_name}")
798
+ # need to configure wandb beforehand in terminal with "wandb init"!
799
+ wandb_config = {
800
+ "model_name": model_name,
801
+ "global_batch_size": global_batch_size,
802
+ "batch_size": batch_size,
803
+ "num_epochs": num_epochs,
804
+ "num_sessions": num_sessions,
805
+ "num_params": num_params,
806
+ "clip_scale": clip_scale,
807
+ "prior_scale": prior_scale,
808
+ "blur_scale": blur_scale,
809
+ "use_image_aug": use_image_aug,
810
+ "max_lr": max_lr,
811
+ "mixup_pct": mixup_pct,
812
+ "num_samples_per_epoch": num_samples_per_epoch,
813
+ "num_test": num_test,
814
+ "ckpt_interval": ckpt_interval,
815
+ "ckpt_saving": ckpt_saving,
816
+ "seed": seed,
817
+ "distributed": distributed,
818
+ "num_devices": num_devices,
819
+ "world_size": world_size,
820
+ # "train_url": train_url,
821
+ # "test_url": test_url,
822
+ }
823
+ print("wandb_config:\n",wandb_config)
824
+ print("wandb_id:",model_name)
825
+ wandb.init(
826
+ id=model_name,
827
+ project=wandb_project,
828
+ name=model_name,
829
+ config=wandb_config,
830
+ resume="allow",
831
+ )
832
+ else:
833
+ wandb_log = False
834
+
835
+
836
+ # # Main
837
+
838
+ # In[25]:
839
+
840
+
841
+ epoch = 0
842
+ losses, test_losses, lrs = [], [], []
843
+ best_test_loss = 1e9
844
+ torch.cuda.empty_cache()
845
+
846
+
847
+ # In[26]:
848
+
849
+
850
+ # load multisubject stage1 ckpt if set
851
+ if multisubject_ckpt is not None:
852
+ load_ckpt("last",outdir=multisubject_ckpt,load_lr=False,load_optimizer=False,load_epoch=False,strict=False,multisubj_loading=True)
853
+
854
+
855
+ # In[27]:
856
+
857
+
858
+ train_dls = [train_dl[f'subj0{s}'] for s in subj_list]
859
+
860
+ model, optimizer, *train_dls, lr_scheduler = accelerator.prepare(model, optimizer, *train_dls, lr_scheduler)
861
+ # leaving out test_dl since we will only have local_rank 0 device do evals
862
+
863
+
864
+ # In[28]:
865
+
866
+
867
+ for voxels, images, sessions_mask, sample_idx in train_dls[0]:
868
+ print(voxels.shape, images.shape, sessions_mask.shape, sample_idx.shape)
869
+ break
870
+
871
+
872
+ # In[29]:
873
+
874
+
875
+ print(f"{model_name} starting with epoch {epoch} / {num_epochs}")
876
+ progress_bar = tqdm(range(epoch,num_epochs), ncols=1200, disable=(local_rank!=0))
877
+ test_image, test_voxel = None, None
878
+ mse = nn.MSELoss()
879
+ l1 = nn.L1Loss()
880
+ soft_loss_temps = utils.cosine_anneal(0.004, 0.0075, num_epochs - int(mixup_pct * num_epochs))
881
+
882
+ for epoch in progress_bar:
883
+ model.train()
884
+
885
+ fwd_percent_correct = 0.
886
+ bwd_percent_correct = 0.
887
+ test_fwd_percent_correct = 0.
888
+ test_bwd_percent_correct = 0.
889
+
890
+ recon_cossim = 0.
891
+ test_recon_cossim = 0.
892
+ recon_mse = 0.
893
+ test_recon_mse = 0.
894
+
895
+ loss_clip_total = 0.
896
+ loss_blurry_total = 0.
897
+ loss_blurry_cont_total = 0.
898
+ test_loss_clip_total = 0.
899
+
900
+ loss_prior_total = 0.
901
+ test_loss_prior_total = 0.
902
+
903
+ blurry_pixcorr = 0.
904
+ test_blurry_pixcorr = 0. # needs >.456 to beat low-level subj01 results in mindeye v1
905
+
906
+ # pre-load all batches for this epoch (it's MUCH faster to pre-load in bulk than to separate loading per batch)
907
+ voxel_iters = {} # empty dict because diff subjects have differing # of voxels
908
+ image_iters = torch.zeros(num_iterations_per_epoch, batch_size*len(subj_list), 3, 224, 224).float()
909
+ annot_iters = {}
910
+ perm_iters, betas_iters, select_iters = {}, {}, {}
911
+ for s, train_dl in enumerate(train_dls):
912
+ with torch.cuda.amp.autocast(dtype=data_type):
913
+ iter = -1
914
+ for voxels, images, sessions_mask, sample_idx in train_dl:
915
+ # for behav0, past_behav0, future_behav0, old_behav0 in train_dl:
916
+ # Load images to cpu from hdf5 (requires sorted indexing)
917
+ # image_idx = behav0[:,0,0].cpu().long().numpy()
918
+ # image0, image_sorted_idx = np.unique(image_idx, return_index=True)
919
+ # if len(image0) != len(image_idx): # hdf5 cant handle duplicate indexing
920
+ # continue
921
+ iter += 1
922
+ # image0 = torch.tensor(images[image0], dtype=data_type)
923
+ # image_iters[iter,s*batch_size:s*batch_size+batch_size] = image0
924
+ image_iters[iter,s*batch_size:s*batch_size+batch_size] = images
925
+
926
+ # Load voxels for current batch, matching above indexing
927
+ # voxel_idx = behav0[:,0,5].cpu().long().numpy()
928
+ # voxel_sorted_idx = voxel_idx[image_sorted_idx]
929
+ # voxel0 = voxels[f'subj0{subj_list[s]}'][voxel_sorted_idx]
930
+ # voxel0 = torch.Tensor(voxel0).unsqueeze(1)
931
+ # print(voxels.shape)
932
+ voxel0 = voxels.unsqueeze(1)
933
+ # print(voxel0.shape)
934
+ if epoch < int(mixup_pct * num_epochs):
935
+ voxel0, perm, betas, select = utils.mixco(voxel0)
936
+ # voxel0, perm, betas, select = utils.mixco(voxel0)
937
+ perm_iters[f"subj0{subj_list[s]}_iter{iter}"] = perm
938
+ betas_iters[f"subj0{subj_list[s]}_iter{iter}"] = betas
939
+ select_iters[f"subj0{subj_list[s]}_iter{iter}"] = select
940
+
941
+ voxel_iters[f"subj0{subj_list[s]}_iter{iter}"] = voxel0
942
+ # print(voxel0.shape)
943
+
944
+ if iter >= num_iterations_per_epoch-1:
945
+ break
946
+
947
+ # you now have voxel_iters and image_iters with num_iterations_per_epoch batches each
948
+ for train_i in range(num_iterations_per_epoch):
949
+ with torch.cuda.amp.autocast(dtype=data_type):
950
+ optimizer.zero_grad()
951
+ loss=0.
952
+
953
+ voxel_list = [voxel_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
954
+ image = image_iters[train_i].detach()
955
+ image = image.to(device)
956
+
957
+ if use_image_aug:
958
+ image = img_augment(image)
959
+
960
+ clip_target = clip_img_embedder(image)
961
+ assert not torch.any(torch.isnan(clip_target))
962
+
963
+ if epoch < int(mixup_pct * num_epochs):
964
+ perm_list = [perm_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
965
+ perm = torch.cat(perm_list, dim=0)
966
+ betas_list = [betas_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
967
+ betas = torch.cat(betas_list, dim=0)
968
+ select_list = [select_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
969
+ select = torch.cat(select_list, dim=0)
970
+
971
+ voxel_ridge_list = [model.ridge(voxel_list[si],si) for si,s in enumerate(subj_list)]
972
+ voxel_ridge = torch.cat(voxel_ridge_list, dim=0)
973
+
974
+ backbone, clip_voxels, blurry_image_enc_ = model.backbone(voxel_ridge)
975
+
976
+ if clip_scale>0:
977
+ clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)
978
+ clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)
979
+
980
+ if use_prior:
981
+ loss_prior, prior_out = model.diffusion_prior(text_embed=backbone, image_embed=clip_target)
982
+ loss_prior_total += loss_prior.item()
983
+ loss_prior *= prior_scale
984
+ loss += loss_prior
985
+
986
+ recon_cossim += nn.functional.cosine_similarity(prior_out, clip_target).mean().item()
987
+ recon_mse += mse(prior_out, clip_target).item()
988
+
989
+ if clip_scale>0:
990
+ if epoch < int(mixup_pct * num_epochs):
991
+ loss_clip = utils.mixco_nce(
992
+ clip_voxels_norm,
993
+ clip_target_norm,
994
+ temp=.006,
995
+ perm=perm, betas=betas, select=select)
996
+ else:
997
+ epoch_temp = soft_loss_temps[epoch-int(mixup_pct*num_epochs)]
998
+ loss_clip = utils.soft_clip_loss(
999
+ clip_voxels_norm,
1000
+ clip_target_norm,
1001
+ temp=epoch_temp)
1002
+
1003
+ loss_clip_total += loss_clip.item()
1004
+ loss_clip *= clip_scale
1005
+ loss += loss_clip
1006
+
1007
+ if blurry_recon:
1008
+ image_enc_pred, transformer_feats = blurry_image_enc_
1009
+
1010
+ image_enc = autoenc.encode(2*image-1).latent_dist.mode() * 0.18215
1011
+ loss_blurry = l1(image_enc_pred, image_enc)
1012
+ loss_blurry_total += loss_blurry.item()
1013
+
1014
+ if epoch < int(mixup_pct * num_epochs):
1015
+ image_enc_shuf = image_enc[perm]
1016
+ betas_shape = [-1] + [1]*(len(image_enc.shape)-1)
1017
+ image_enc[select] = image_enc[select] * betas[select].reshape(*betas_shape) + \
1018
+ image_enc_shuf[select] * (1 - betas[select]).reshape(*betas_shape)
1019
+
1020
+ image_norm = (image - mean)/std
1021
+ image_aug = (blur_augs(image) - mean)/std
1022
+ _, cnx_embeds = cnx(image_norm)
1023
+ _, cnx_aug_embeds = cnx(image_aug)
1024
+
1025
+ cont_loss = utils.soft_cont_loss(
1026
+ nn.functional.normalize(transformer_feats.reshape(-1, transformer_feats.shape[-1]), dim=-1),
1027
+ nn.functional.normalize(cnx_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),
1028
+ nn.functional.normalize(cnx_aug_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),
1029
+ temp=0.2)
1030
+ loss_blurry_cont_total += cont_loss.item()
1031
+
1032
+ loss += (loss_blurry + 0.1*cont_loss) * blur_scale #/.18215
1033
+
1034
+ if clip_scale>0:
1035
+ # forward and backward top 1 accuracy
1036
+ labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device)
1037
+ fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()
1038
+ bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()
1039
+ # print(utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item(), utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item())
1040
+ if blurry_recon:
1041
+ with torch.no_grad():
1042
+ # only doing pixcorr eval on a subset of the samples per batch because its costly & slow to compute autoenc.decode()
1043
+ random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)
1044
+ blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample/ 2 + 0.5).clamp(0,1)
1045
+ pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)
1046
+ blurry_pixcorr += pixcorr.item()
1047
+
1048
+ utils.check_loss(loss)
1049
+ accelerator.backward(loss)
1050
+ optimizer.step()
1051
+
1052
+ losses.append(loss.item())
1053
+ lrs.append(optimizer.param_groups[0]['lr'])
1054
+
1055
+ if lr_scheduler_type is not None:
1056
+ lr_scheduler.step()
1057
+
1058
+ model.eval()
1059
+ if local_rank==0:
1060
+ with torch.no_grad(), torch.cuda.amp.autocast(dtype=data_type):
1061
+ # for test_i, (behav, past_behav, future_behav, old_behav) in enumerate(test_dl):
1062
+ for test_i, (voxels, images, sessions_mask, sample_idx) in enumerate(test_dl):
1063
+ # all test samples should be loaded per batch such that test_i should never exceed 0
1064
+ # assert len(behav) == num_test
1065
+
1066
+ ## Average same-image repeats ##
1067
+ # if test_image is None:
1068
+ # # voxel = voxels[f'subj0{subj}'][behav[:,0,5].cpu().long()].unsqueeze(1)
1069
+ # voxel = voxels.unsqueeze(1)
1070
+ # # image = behav[:,0,0].cpu().long()
1071
+ # image = images
1072
+
1073
+ # unique_image, sort_indices = torch.unique(image, return_inverse=True)
1074
+ # for im in unique_image:
1075
+ # locs = torch.where(im == image)[0]
1076
+ # if len(locs)==1:
1077
+ # locs = locs.repeat(3)
1078
+ # elif len(locs)==2:
1079
+ # locs = locs.repeat(2)[:3]
1080
+ # assert len(locs)==3
1081
+ # if test_image is None:
1082
+ # test_image = torch.Tensor(images[im][None])
1083
+ # test_voxel = voxel[locs][None]
1084
+ # else:
1085
+ # test_image = torch.vstack((test_image, torch.Tensor(images[im][None])))
1086
+ # test_voxel = torch.vstack((test_voxel, voxel[locs][None]))
1087
+ test_image = images
1088
+ test_voxel = voxels.unsqueeze(1)
1089
+
1090
+ loss=0.
1091
+
1092
+ # test_indices = torch.arange(len(test_voxel))[:]
1093
+ # voxel = test_voxel[test_indices].to(device)
1094
+ # image = test_image[test_indices].to(device)
1095
+ # assert len(image) == 100
1096
+ image = test_image.to(device)
1097
+ voxel = test_voxel.to(device)
1098
+
1099
+ clip_target = clip_img_embedder(image.float())
1100
+
1101
+ # REPETITION AVERAGING INFERENCE DOESN'T APPLY SINCE WE'RE USING VALIDATION SET
1102
+ # for rep in range(3):
1103
+ # voxel_ridge = model.ridge(voxel[:,rep],0) # 0th index of subj_list
1104
+ # backbone0, clip_voxels0, blurry_image_enc_ = model.backbone(voxel_ridge)
1105
+ # if rep==0:
1106
+ # clip_voxels = clip_voxels0
1107
+ # backbone = backbone0
1108
+ # else:
1109
+ # clip_voxels += clip_voxels0
1110
+ # backbone += backbone0
1111
+ # clip_voxels /= 3
1112
+ # backbone /= 3
1113
+
1114
+ voxel_ridge = model.ridge(voxel,0) # 0th index of subj_list
1115
+
1116
+ backbone, clip_voxels, blurry_image_enc_ = model.backbone(voxel_ridge)
1117
+
1118
+ if clip_scale>0:
1119
+ clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)
1120
+ clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)
1121
+
1122
+ # for some evals, only doing a subset of the samples per batch because of computational cost
1123
+ random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)
1124
+
1125
+ if use_prior:
1126
+ loss_prior, contaminated_prior_out = model.diffusion_prior(text_embed=backbone[random_samps], image_embed=clip_target[random_samps])
1127
+ test_loss_prior_total += loss_prior.item()
1128
+ loss_prior *= prior_scale
1129
+ loss += loss_prior
1130
+
1131
+ if clip_scale>0:
1132
+ loss_clip = utils.soft_clip_loss(
1133
+ clip_voxels_norm,
1134
+ clip_target_norm,
1135
+ temp=.006)
1136
+
1137
+ test_loss_clip_total += loss_clip.item()
1138
+ loss_clip = loss_clip * clip_scale
1139
+ loss += loss_clip
1140
+
1141
+ if blurry_recon:
1142
+ image_enc_pred, _ = blurry_image_enc_
1143
+ blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample / 2 + 0.5).clamp(0,1)
1144
+ pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)
1145
+ test_blurry_pixcorr += pixcorr.item()
1146
+
1147
+ if clip_scale>0:
1148
+ # forward and backward top 1 accuracy
1149
+ labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device)
1150
+ test_fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()
1151
+ test_bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()
1152
+
1153
+ utils.check_loss(loss)
1154
+ test_losses.append(loss.item())
1155
+
1156
+ assert (test_i+1) == 1
1157
+ logs = {"train/loss": np.mean(losses[-(train_i+1):]),
1158
+ "test/loss": np.mean(test_losses[-(test_i+1):]),
1159
+ "train/lr": lrs[-1],
1160
+ "train/num_steps": len(losses),
1161
+ "test/num_steps": len(test_losses),
1162
+ "train/fwd_pct_correct": fwd_percent_correct / (train_i + 1),
1163
+ "train/bwd_pct_correct": bwd_percent_correct / (train_i + 1),
1164
+ "test/test_fwd_pct_correct": test_fwd_percent_correct / (test_i + 1),
1165
+ "test/test_bwd_pct_correct": test_bwd_percent_correct / (test_i + 1),
1166
+ "train/loss_clip_total": loss_clip_total / (train_i + 1),
1167
+ "train/loss_blurry_total": loss_blurry_total / (train_i + 1),
1168
+ "train/loss_blurry_cont_total": loss_blurry_cont_total / (train_i + 1),
1169
+ "test/loss_clip_total": test_loss_clip_total / (test_i + 1),
1170
+ "train/blurry_pixcorr": blurry_pixcorr / (train_i + 1),
1171
+ "test/blurry_pixcorr": test_blurry_pixcorr / (test_i + 1),
1172
+ "train/recon_cossim": recon_cossim / (train_i + 1),
1173
+ "test/recon_cossim": test_recon_cossim / (test_i + 1),
1174
+ "train/recon_mse": recon_mse / (train_i + 1),
1175
+ "test/recon_mse": test_recon_mse / (test_i + 1),
1176
+ "train/loss_prior": loss_prior_total / (train_i + 1),
1177
+ "test/loss_prior": test_loss_prior_total / (test_i + 1),
1178
+ }
1179
+
1180
+ # if finished training, save jpg recons if they exist
1181
+ if (epoch == num_epochs-1) or (epoch % ckpt_interval == 0):
1182
+ if blurry_recon:
1183
+ image_enc = autoenc.encode(2*image[:4]-1).latent_dist.mode() * 0.18215
1184
+ # transform blurry recon latents to images and plot it
1185
+ fig, axes = plt.subplots(1, 8, figsize=(10, 4))
1186
+ jj=-1
1187
+ for j in [0,1,2,3]:
1188
+ jj+=1
1189
+ axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))
1190
+ axes[jj].axis('off')
1191
+ jj+=1
1192
+ axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc_pred[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))
1193
+ axes[jj].axis('off')
1194
+
1195
+ if wandb_log:
1196
+ logs[f"test/blur_recons"] = wandb.Image(fig, caption=f"epoch{epoch:03d}")
1197
+ plt.close()
1198
+ else:
1199
+ plt.show()
1200
+
1201
+ progress_bar.set_postfix(**logs)
1202
+
1203
+ if wandb_log: wandb.log(logs)
1204
+
1205
+ # Save model checkpoint and reconstruct
1206
+ if (ckpt_saving) and (epoch % ckpt_interval == 0):
1207
+ save_ckpt(f'last')
1208
+
1209
+ # wait for other GPUs to catch up if needed
1210
+ accelerator.wait_for_everyone()
1211
+ torch.cuda.empty_cache()
1212
+
1213
+ print("\n===Finished!===\n")
1214
+ if ckpt_saving:
1215
+ save_ckpt(f'last')
1216
+
1217
+
1218
+ # In[ ]:
1219
+
1220
+
1221
+ # voxel_iters.keys()
1222
+
1223
+
1224
+ # In[ ]:
1225
+
1226
+
1227
+ # # create a new dl
1228
+ # test_voxels, test_images, test_sessions_idx, test_sample_idx = get_voxels_and_images(subj, num_sessions, data_path, 'shared')
1229
+ # test_data = BoldDataset(test_voxels, test_images, test_sessions_idx, test_sample_idx)
1230
+ # test_dl = DataLoader(test_data, batch_size=test_voxels.shape[0], shuffle=False, num_workers=num_workers, pin_memory=True)
1231
+
1232
+
1233
+ # In[ ]:
1234
+
1235
+
1236
+ aaa
1237
+
1238
+
1239
+ # In[ ]:
1240
+
1241
+
1242
+ # # find the unique images in the test set
1243
+ # unique_images = torch.unique(test_images, dim=0)
1244
+ # print("unique_images.shape", unique_images.shape)
1245
+
1246
+
1247
+ # In[ ]:
1248
+
1249
+
1250
+ v1_images = torch.load('/weka/proj-medarc/shared/bold5000/v1/subj1/images_stimuli.pt')
1251
+ wb_images = torch.load('/weka/proj-medarc/shared/bold5000/formated/subj1/images_stimuli.pt')
1252
+
1253
+
1254
+ # In[ ]:
1255
+
1256
+
1257
+ wb_images.device
1258
+
1259
+
1260
+ # In[ ]:
1261
+
1262
+
1263
+ # wb_images = torch.load('/weka/proj-medarc/shared/bold5000/formated/subj1/images_stimuli.pt') # (5254, 3, 224, 224)
1264
+
1265
+ # iterate one in train_dl
1266
+ for b1_voxels, b1_images, b1_sessions_idx, b1_sample_idx in test_dl:
1267
+ print(b1_voxels.shape, b1_images.shape, b1_sessions_idx.shape, b1_sample_idx.shape)
1268
+ break
1269
+
1270
+ b1_sample = b1_images[1].to('cpu') # (3, 224, 224)
1271
+ # check the index of the first image b1_images[1] in wb_images
1272
+
1273
+ mask = (wb_images == b1_sample.unsqueeze(0))
1274
+ # Reduce over the last three dimensions one by one:
1275
+ mask = mask.all(dim=3).all(dim=2).all(dim=1)
1276
+
1277
+ indices = torch.where(mask)[0]
1278
+ if len(indices) > 0:
1279
+ print("Found b1_images[1] at index(es):", indices.tolist())
1280
+ else:
1281
+ print("No exact match found.")
1282
+
1283
+
1284
+ # In[ ]:
1285
+
1286
+
1287
+ v1_images[4095,0,0,10:100], b1_images[1,0,0,10:100], wb_voxels[4095,1000:1020], b1_voxels[1,1000:1020]
1288
+
1289
+
1290
+ # In[ ]:
1291
+
1292
+
1293
+ b1_voxels.min()
1294
+
1295
+
1296
+ # In[ ]:
1297
+
1298
+
1299
+ wb_images.shape
1300
+
1301
+
1302
+ # In[ ]:
1303
+
1304
+
1305
+ v1_voxels = torch.load(f'/weka/proj-medarc/shared/bold5000/v1/subj1/voxels.pt')
1306
+ wb_voxels = torch.load(f'/weka/proj-medarc/shared/bold5000/formated/subj1/wholebrain.pt')
1307
+
1308
+
1309
+ # In[ ]:
1310
+
1311
+
1312
+ v1_voxels.max(), v1_voxels.min(), wb_voxels.max(), wb_voxels.min()
1313
+
1314
+
1315
+ # In[ ]:
1316
+
1317
+
1318
+ # for i in train_dl
1319
+
1320
+
1321
+ # In[ ]:
1322
+
1323
+
1324
+ from tqdm import tqdm
1325
+ import torch
1326
+
1327
+ # Extract the first example from each tensor
1328
+ v1_example = v1_voxels[0] # shape: [1685]
1329
+ wb_example = wb_voxels[0] # shape: [174019]
1330
+
1331
+ # Round both sets of voxels to 4 decimal places
1332
+ v1_rounded = torch.round(v1_example * 1000) / 1000
1333
+ wb_rounded = torch.round(wb_example * 1000) / 1000
1334
+
1335
+ # Convert wb_rounded to a set for O(1) membership checks
1336
+ wb_set = set(wb_rounded.tolist())
1337
+
1338
+ count = 0
1339
+ # Iterate over each voxel in v1_rounded and check if it exists in wb_rounded
1340
+ for voxel in tqdm(v1_rounded, desc="Checking V1 voxels"):
1341
+ if voxel.item() in wb_set:
1342
+ count += 1
1343
+
1344
+ print(f"Number of V1 voxels present in the WB example (up to 4 decimals): {count}")
1345
+
1346
+
1347
+ # In[ ]:
1348
+
1349
+
1350
+
1351
+
1352
+
1353
+ # In[ ]:
1354
+
1355
+
1356
+ # Extract the first example from each tensor
1357
+ v1_example = v1_voxels[0] # shape: [1685]
1358
+ wb_example = wb_voxels[0] # shape: [174019]
1359
+
1360
+ # Convert wb_example to a set for O(1) membership checks
1361
+ wb_set = set(wb_example.tolist())
1362
+
1363
+ count = 0
1364
+ # Iterate over each voxel in v1_example and check if it exists in wb_example
1365
+ for voxel in tqdm(v1_example, desc="Checking V1 voxels"):
1366
+ value = voxel.item()
1367
+ if count == 0:
1368
+ value = 1.0938
1369
+
1370
+ if value in wb_set:
1371
+ count += 1
1372
+
1373
+ print(f"Number of V1 voxels present in the WB example: {count}")
1374
+
1375
+
1376
+ # In[ ]:
1377
+
1378
+
1379
+ v1_voxels = torch.load(f'/weka/proj-medarc/shared/bold5000/v1/subj1/voxels.pt')
1380
+ wb_voxels = torch.load(f'/weka/proj-medarc/shared/bold5000/formated/subj1/wholebrain.pt')
1381
+
1382
+
1383
+ # In[ ]:
1384
+
1385
+
1386
+ v1_voxels.shape, wb_voxels[0,1006:1060]
1387
+
1388
+
1389
+ # In[ ]:
1390
+
1391
+
1392
+ v1_voxels.shape, wb_voxels[0,1006:1060]
1393
+
1394
+
1395
+ # In[ ]:
1396
+
1397
+
1398
+ # # plot train images
1399
+ indexes_to_plot = [1,3,4,5,6]
1400
+ fig, axs = plt.subplots(1, len(indexes_to_plot), figsize=(20, 5))
1401
+ for i, idx in enumerate(indexes_to_plot):
1402
+ axs[i].imshow(v1_images[idx].permute(1, 2, 0))
1403
+ axs[i].axis('off')
1404
+ plt.show()
1405
+
1406
+
1407
+ # In[ ]:
1408
+
1409
+
1410
+ # # plot train images
1411
+ indexes_to_plot = [1,3,4,5,6]
1412
+ fig, axs = plt.subplots(1, len(indexes_to_plot), figsize=(20, 5))
1413
+ for i, idx in enumerate(indexes_to_plot):
1414
+ axs[i].imshow(wb_images[idx].permute(1, 2, 0))
1415
+ axs[i].axis('off')
1416
+ plt.show()
1417
+
1418
+
1419
+ # In[ ]:
1420
+
1421
+
1422
+ # train_i
1423
+
1424
+
1425
+ # In[ ]:
1426
+
1427
+
1428
+ # fwd_percent_correct/
1429
+
1430
+
1431
+ # In[ ]:
1432
+
1433
+
1434
+ plt.plot(losses)
1435
+ plt.show()
1436
+ plt.plot(test_losses)
1437
+ plt.show()
1438
+
MindEyeV2/src/TrainBold5000-Copy1.ipynb ADDED
@@ -0,0 +1,1669 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "b0f0f4f3",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Import packages & functions"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": 1,
14
+ "id": "5bad764b-45c1-45ce-a716-8d055e09821a",
15
+ "metadata": {
16
+ "tags": []
17
+ },
18
+ "outputs": [],
19
+ "source": [
20
+ "import os\n",
21
+ "import sys\n",
22
+ "import json\n",
23
+ "import argparse\n",
24
+ "import numpy as np\n",
25
+ "import math\n",
26
+ "from einops import rearrange\n",
27
+ "import time\n",
28
+ "import random\n",
29
+ "import string\n",
30
+ "import h5py\n",
31
+ "from tqdm import tqdm\n",
32
+ "import webdataset as wds\n",
33
+ "\n",
34
+ "import matplotlib.pyplot as plt\n",
35
+ "import torch\n",
36
+ "import torch.nn as nn\n",
37
+ "from torchvision import transforms\n",
38
+ "from accelerate import Accelerator\n",
39
+ "\n",
40
+ "# SDXL unCLIP requires code from https://github.com/Stability-AI/generative-models/tree/main\n",
41
+ "sys.path.append('generative_models/')\n",
42
+ "import sgm\n",
43
+ "from generative_models.sgm.modules.encoders.modules import FrozenOpenCLIPImageEmbedder # bigG embedder\n",
44
+ "\n",
45
+ "# tf32 data type is faster than standard float32\n",
46
+ "torch.backends.cuda.matmul.allow_tf32 = True\n",
47
+ "\n",
48
+ "# custom functions #\n",
49
+ "import utils"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 2,
55
+ "id": "cc5d2e32-6027-4a19-bef4-5ca068db35bb",
56
+ "metadata": {
57
+ "tags": []
58
+ },
59
+ "outputs": [
60
+ {
61
+ "name": "stdout",
62
+ "output_type": "stream",
63
+ "text": [
64
+ "LOCAL RANK 0\n"
65
+ ]
66
+ }
67
+ ],
68
+ "source": [
69
+ "### Multi-GPU config ###\n",
70
+ "local_rank = os.getenv('RANK')\n",
71
+ "if local_rank is None: \n",
72
+ " local_rank = 0\n",
73
+ "else:\n",
74
+ " local_rank = int(local_rank)\n",
75
+ "print(\"LOCAL RANK \", local_rank) \n",
76
+ "\n",
77
+ "data_type = torch.float16 # change depending on your mixed_precision\n",
78
+ "num_devices = torch.cuda.device_count()\n",
79
+ "if num_devices==0: num_devices = 1\n",
80
+ "\n",
81
+ "# First use \"accelerate config\" in terminal and setup using deepspeed stage 2 with CPU offloading!\n",
82
+ "accelerator = Accelerator(split_batches=False, mixed_precision=\"fp16\")\n",
83
+ "if utils.is_interactive(): # set batch size here if using interactive notebook instead of submitting job\n",
84
+ " global_batch_size = batch_size = 8\n",
85
+ "else:\n",
86
+ " global_batch_size = os.environ[\"GLOBAL_BATCH_SIZE\"]\n",
87
+ " batch_size = int(os.environ[\"GLOBAL_BATCH_SIZE\"]) // num_devices"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": 3,
93
+ "id": "b767ab6f-d4a9-47a5-b3bf-f56bf6760c0c",
94
+ "metadata": {
95
+ "tags": []
96
+ },
97
+ "outputs": [
98
+ {
99
+ "name": "stdout",
100
+ "output_type": "stream",
101
+ "text": [
102
+ "PID of this process = 2098275\n",
103
+ "device: cuda\n",
104
+ "Distributed environment: DistributedType.NO\n",
105
+ "Num processes: 1\n",
106
+ "Process index: 0\n",
107
+ "Local process index: 0\n",
108
+ "Device: cuda\n",
109
+ "\n",
110
+ "Mixed precision type: fp16\n",
111
+ "\n",
112
+ "distributed = False num_devices = 1 local rank = 0 world size = 1 data_type = torch.float16\n"
113
+ ]
114
+ }
115
+ ],
116
+ "source": [
117
+ "print(\"PID of this process =\",os.getpid())\n",
118
+ "device = accelerator.device\n",
119
+ "print(\"device:\",device)\n",
120
+ "world_size = accelerator.state.num_processes\n",
121
+ "distributed = not accelerator.state.distributed_type == 'NO'\n",
122
+ "num_devices = torch.cuda.device_count()\n",
123
+ "if num_devices==0 or not distributed: num_devices = 1\n",
124
+ "num_workers = num_devices\n",
125
+ "print(accelerator.state)\n",
126
+ "\n",
127
+ "print(\"distributed =\",distributed, \"num_devices =\", num_devices, \"local rank =\", local_rank, \"world size =\", world_size, \"data_type =\", data_type)\n",
128
+ "print = accelerator.print # only print if local_rank=0"
129
+ ]
130
+ },
131
+ {
132
+ "cell_type": "markdown",
133
+ "id": "9018b82b-c054-4463-9527-4b0c2a75bda6",
134
+ "metadata": {
135
+ "tags": []
136
+ },
137
+ "source": [
138
+ "# Configurations"
139
+ ]
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "execution_count": 4,
144
+ "id": "2b61fec7-72a0-4b67-86da-1375f1d9fbd3",
145
+ "metadata": {
146
+ "tags": []
147
+ },
148
+ "outputs": [
149
+ {
150
+ "name": "stdout",
151
+ "output_type": "stream",
152
+ "text": [
153
+ "model_name: testingbold5000\n",
154
+ "--data_path=/weka/proj-medarc/shared/bold5000/v1 --cache_dir=/weka/proj-medarc/shared/cache --model_name=testingbold5000 --no-multi_subject --subj=1 --batch_size=8 --num_sessions=14 --hidden_dim=1024 --clip_scale=1. --no-blurry_recon --blur_scale=.5 --use_prior --prior_scale=30 --n_blocks=4 --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --no-use_image_aug --ckpt_interval=999 --no-ckpt_saving --wandb_log\n"
155
+ ]
156
+ }
157
+ ],
158
+ "source": [
159
+ "# if running this interactively, can specify jupyter_args here for argparser to use\n",
160
+ "if utils.is_interactive():\n",
161
+ " model_name = \"testingbold5000\"\n",
162
+ " print(\"model_name:\", model_name)\n",
163
+ " \n",
164
+ " # global_batch_size and batch_size should already be defined in the 2nd cell block\n",
165
+ " jupyter_args = f\"--data_path=/weka/proj-medarc/shared/bold5000/v1 \\\n",
166
+ " --cache_dir=/weka/proj-medarc/shared/cache \\\n",
167
+ " --model_name={model_name} \\\n",
168
+ " --no-multi_subject --subj=1 --batch_size={batch_size} --num_sessions=14 \\\n",
169
+ " --hidden_dim=1024 --clip_scale=1. \\\n",
170
+ " --no-blurry_recon --blur_scale=.5 \\\n",
171
+ " --use_prior --prior_scale=30 \\\n",
172
+ " --n_blocks=4 --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --no-use_image_aug \\\n",
173
+ " --ckpt_interval=999 --no-ckpt_saving --wandb_log\"\n",
174
+ " # --multisubject_ckpt=../train_logs/multisubject_subj01_1024_24bs_nolow\n",
175
+ "\n",
176
+ " print(jupyter_args)\n",
177
+ " jupyter_args = jupyter_args.split()\n",
178
+ " \n",
179
+ " from IPython.display import clear_output # function to clear print outputs in cell\n",
180
+ " %load_ext autoreload \n",
181
+ " # this allows you to change functions in models.py or utils.py and have this notebook automatically update with your revisions\n",
182
+ " %autoreload 2 "
183
+ ]
184
+ },
185
+ {
186
+ "cell_type": "code",
187
+ "execution_count": 5,
188
+ "id": "2028bdf0-2f41-46d9-b6e7-86b870dbf16c",
189
+ "metadata": {
190
+ "tags": []
191
+ },
192
+ "outputs": [
193
+ {
194
+ "name": "stdout",
195
+ "output_type": "stream",
196
+ "text": [
197
+ "subj_list [1] num_sessions 14\n"
198
+ ]
199
+ }
200
+ ],
201
+ "source": [
202
+ "parser = argparse.ArgumentParser(description=\"Model Training Configuration\")\n",
203
+ "parser.add_argument(\n",
204
+ " \"--model_name\", type=str, default=\"testing\",\n",
205
+ " help=\"name of model, used for ckpt saving and wandb logging (if enabled)\",\n",
206
+ ")\n",
207
+ "parser.add_argument(\n",
208
+ " \"--data_path\", type=str, default=os.getcwd(),\n",
209
+ " help=\"Path to where NSD data is stored / where to download it to\",\n",
210
+ ")\n",
211
+ "parser.add_argument(\n",
212
+ " \"--cache_dir\", type=str, default=os.getcwd(),\n",
213
+ " help=\"Path to where misc. files downloaded from huggingface are stored. Defaults to current src directory.\",\n",
214
+ ")\n",
215
+ "parser.add_argument(\n",
216
+ " \"--subj\",type=int, default=1, choices=[1,2,3,4,5,6,7,8],\n",
217
+ " help=\"Validate on which subject?\",\n",
218
+ ")\n",
219
+ "parser.add_argument(\n",
220
+ " \"--multisubject_ckpt\", type=str, default=None,\n",
221
+ " help=\"Path to pre-trained multisubject model to finetune a single subject from. multisubject must be False.\",\n",
222
+ ")\n",
223
+ "parser.add_argument(\n",
224
+ " \"--num_sessions\", type=int, default=1,\n",
225
+ " help=\"Number of training sessions to include\",\n",
226
+ ")\n",
227
+ "parser.add_argument(\n",
228
+ " \"--use_prior\",action=argparse.BooleanOptionalAction,default=True,\n",
229
+ " help=\"whether to train diffusion prior (True) or just rely on retrieval part of the pipeline (False)\",\n",
230
+ ")\n",
231
+ "parser.add_argument(\n",
232
+ " \"--batch_size\", type=int, default=16,\n",
233
+ " help=\"Batch size can be increased by 10x if only training retreival submodule and not diffusion prior\",\n",
234
+ ")\n",
235
+ "parser.add_argument(\n",
236
+ " \"--wandb_log\",action=argparse.BooleanOptionalAction,default=False,\n",
237
+ " help=\"whether to log to wandb\",\n",
238
+ ")\n",
239
+ "parser.add_argument(\n",
240
+ " \"--wandb_project\",type=str,default=\"stability\",\n",
241
+ " help=\"wandb project name\",\n",
242
+ ")\n",
243
+ "parser.add_argument(\n",
244
+ " \"--mixup_pct\",type=float,default=.33,\n",
245
+ " help=\"proportion of way through training when to switch from BiMixCo to SoftCLIP\",\n",
246
+ ")\n",
247
+ "parser.add_argument(\n",
248
+ " \"--blurry_recon\",action=argparse.BooleanOptionalAction,default=True,\n",
249
+ " help=\"whether to output blurry reconstructions\",\n",
250
+ ")\n",
251
+ "parser.add_argument(\n",
252
+ " \"--blur_scale\",type=float,default=.5,\n",
253
+ " help=\"multiply loss from blurry recons by this number\",\n",
254
+ ")\n",
255
+ "parser.add_argument(\n",
256
+ " \"--clip_scale\",type=float,default=1.,\n",
257
+ " help=\"multiply contrastive loss by this number\",\n",
258
+ ")\n",
259
+ "parser.add_argument(\n",
260
+ " \"--prior_scale\",type=float,default=30,\n",
261
+ " help=\"multiply diffusion prior loss by this\",\n",
262
+ ")\n",
263
+ "parser.add_argument(\n",
264
+ " \"--use_image_aug\",action=argparse.BooleanOptionalAction,default=False,\n",
265
+ " help=\"whether to use image augmentation\",\n",
266
+ ")\n",
267
+ "parser.add_argument(\n",
268
+ " \"--num_epochs\",type=int,default=150,\n",
269
+ " help=\"number of epochs of training\",\n",
270
+ ")\n",
271
+ "parser.add_argument(\n",
272
+ " \"--multi_subject\",action=argparse.BooleanOptionalAction,default=False,\n",
273
+ ")\n",
274
+ "parser.add_argument(\n",
275
+ " \"--new_test\",action=argparse.BooleanOptionalAction,default=True,\n",
276
+ ")\n",
277
+ "parser.add_argument(\n",
278
+ " \"--n_blocks\",type=int,default=4,\n",
279
+ ")\n",
280
+ "parser.add_argument(\n",
281
+ " \"--hidden_dim\",type=int,default=1024,\n",
282
+ ")\n",
283
+ "parser.add_argument(\n",
284
+ " \"--lr_scheduler_type\",type=str,default='cycle',choices=['cycle','linear'],\n",
285
+ ")\n",
286
+ "parser.add_argument(\n",
287
+ " \"--ckpt_saving\",action=argparse.BooleanOptionalAction,default=True,\n",
288
+ ")\n",
289
+ "parser.add_argument(\n",
290
+ " \"--ckpt_interval\",type=int,default=5,\n",
291
+ " help=\"save backup ckpt and reconstruct every x epochs\",\n",
292
+ ")\n",
293
+ "parser.add_argument(\n",
294
+ " \"--seed\",type=int,default=42,\n",
295
+ ")\n",
296
+ "parser.add_argument(\n",
297
+ " \"--max_lr\",type=float,default=3e-4,\n",
298
+ ")\n",
299
+ "\n",
300
+ "if utils.is_interactive():\n",
301
+ " args = parser.parse_args(jupyter_args)\n",
302
+ "else:\n",
303
+ " args = parser.parse_args()\n",
304
+ "\n",
305
+ "# create global variables without the args prefix\n",
306
+ "for attribute_name in vars(args).keys():\n",
307
+ " globals()[attribute_name] = getattr(args, attribute_name)\n",
308
+ " \n",
309
+ "# seed all random functions\n",
310
+ "utils.seed_everything(seed)\n",
311
+ "\n",
312
+ "outdir = os.path.abspath(f'../train_logs/{model_name}')\n",
313
+ "if not os.path.exists(outdir) and ckpt_saving:\n",
314
+ " os.makedirs(outdir,exist_ok=True)\n",
315
+ " \n",
316
+ "if use_image_aug or blurry_recon:\n",
317
+ " import kornia\n",
318
+ " from kornia.augmentation.container import AugmentationSequential\n",
319
+ "if use_image_aug:\n",
320
+ " img_augment = AugmentationSequential(\n",
321
+ " kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1, p=0.3),\n",
322
+ " same_on_batch=False,\n",
323
+ " data_keys=[\"input\"],\n",
324
+ " )\n",
325
+ " \n",
326
+ "if multi_subject:\n",
327
+ " subj_list = np.arange(1,9)\n",
328
+ " subj_list = subj_list[subj_list != subj]\n",
329
+ "else:\n",
330
+ " subj_list = [subj]\n",
331
+ "\n",
332
+ "print(\"subj_list\", subj_list, \"num_sessions\", num_sessions)"
333
+ ]
334
+ },
335
+ {
336
+ "cell_type": "markdown",
337
+ "id": "42d13c25-1369-4c49-81d4-83d713586096",
338
+ "metadata": {
339
+ "tags": []
340
+ },
341
+ "source": [
342
+ "# Prep data, models, and dataloaders"
343
+ ]
344
+ },
345
+ {
346
+ "cell_type": "markdown",
347
+ "id": "1c023f24-5233-4a15-a2f5-78487b3a8546",
348
+ "metadata": {},
349
+ "source": [
350
+ "### Creating wds dataloader, preload betas and all 73k possible images"
351
+ ]
352
+ },
353
+ {
354
+ "cell_type": "code",
355
+ "execution_count": 6,
356
+ "id": "aefe7c27-ab39-4b2c-90f4-480f4087b7ab",
357
+ "metadata": {
358
+ "tags": []
359
+ },
360
+ "outputs": [
361
+ {
362
+ "name": "stdout",
363
+ "output_type": "stream",
364
+ "text": [
365
+ "dividing batch size by subj_list, which will then be concatenated across subj during training...\n",
366
+ "batch_size = 8 num_iterations_per_epoch = 656 num_samples_per_epoch = 5254\n"
367
+ ]
368
+ }
369
+ ],
370
+ "source": [
371
+ "def my_split_by_node(urls): return urls\n",
372
+ "num_voxels_list = []\n",
373
+ "\n",
374
+ "n_trials_per_subject = [5254, 5254, 5254, 3108] \n",
375
+ "\n",
376
+ "if multi_subject:\n",
377
+ " nsessions_allsubj=np.array([15,15,15,9])\n",
378
+ " num_samples_per_epoch = (750*40) // num_devices \n",
379
+ "else:\n",
380
+ " num_samples_per_epoch = n_trials_per_subject[subj_list[0]] // num_devices \n",
381
+ "\n",
382
+ "print(\"dividing batch size by subj_list, which will then be concatenated across subj during training...\") \n",
383
+ "batch_size = batch_size // len(subj_list)\n",
384
+ "\n",
385
+ "num_iterations_per_epoch = num_samples_per_epoch // (batch_size*len(subj_list))\n",
386
+ "\n",
387
+ "print(\"batch_size =\", batch_size, \"num_iterations_per_epoch =\",num_iterations_per_epoch, \"num_samples_per_epoch =\",num_samples_per_epoch)"
388
+ ]
389
+ },
390
+ {
391
+ "cell_type": "code",
392
+ "execution_count": 7,
393
+ "id": "8e8a3cc6-0627-4b61-b826-a6d2df93f122",
394
+ "metadata": {},
395
+ "outputs": [],
396
+ "source": [
397
+ "# load the data\n",
398
+ "images1 = torch.load('/weka/proj-medarc/shared/bold5000/v1/subj1/images_stimuli.pt')\n",
399
+ "voxelsv1 = torch.load('/weka/proj-medarc/shared/bold5000/v1/subj1/voxels.pt')\n",
400
+ "\n",
401
+ "voxels1 = torch.load('/weka/proj-medarc/shared/bold5000/formated/subj1/wholebrain.pt')\n",
402
+ "sessions_mask = torch.load(os.path.join('/weka/proj-medarc/shared/bold5000/formated/', f\"subj{subj}/sessions_mask.pt\"))"
403
+ ]
404
+ },
405
+ {
406
+ "cell_type": "code",
407
+ "execution_count": 8,
408
+ "id": "9f412984-30f6-46d5-9d00-f8277aa0e30c",
409
+ "metadata": {},
410
+ "outputs": [
411
+ {
412
+ "name": "stdout",
413
+ "output_type": "stream",
414
+ "text": [
415
+ "torch.Size([5254, 174019]) torch.Size([5254])\n"
416
+ ]
417
+ }
418
+ ],
419
+ "source": [
420
+ "print(voxels1.shape, sessions_mask.shape)"
421
+ ]
422
+ },
423
+ {
424
+ "cell_type": "code",
425
+ "execution_count": 9,
426
+ "id": "74070791-7980-49aa-a8d3-0c238432c62f",
427
+ "metadata": {},
428
+ "outputs": [],
429
+ "source": [
430
+ "unique_sessions = sessions_mask.unique()\n",
431
+ "\n",
432
+ "# Prepare a container for the output (copy first, or you can create a new one)\n",
433
+ "voxels1_zscore = torch.empty_like(voxels1)\n",
434
+ "\n",
435
+ "# Loop over sessions\n",
436
+ "for sess in unique_sessions:\n",
437
+ " # Create a boolean mask for trials belonging to the current session\n",
438
+ " sess_mask = (sessions_mask == sess)\n",
439
+ "\n",
440
+ " # Extract the trials corresponding to this session\n",
441
+ " sess_data = voxels1[sess_mask, :] # shape: [num_session_trials, num_voxels]\n",
442
+ "\n",
443
+ " # Compute mean and std along trials (dim=0 is trials, dim=1 is voxels)\n",
444
+ " mean_sess = sess_data.mean(dim=0) # shape: [num_voxels]\n",
445
+ " std_sess = sess_data.std(dim=0) # shape: [num_voxels]\n",
446
+ "\n",
447
+ " # Avoid division by zero: if std is zero, set it to 1 (or handle as desired)\n",
448
+ " std_sess[std_sess == 0] = 1.0\n",
449
+ "\n",
450
+ " # Z-score the session data\n",
451
+ " sess_data_zscore = (sess_data - mean_sess) / std_sess\n",
452
+ "\n",
453
+ " # Place the z-scored data back into the output tensor\n",
454
+ " voxels1_zscore[sess_mask, :] = sess_data_zscore"
455
+ ]
456
+ },
457
+ {
458
+ "cell_type": "code",
459
+ "execution_count": 10,
460
+ "id": "8a402d18-641f-45b4-aecd-cf6c7ec38447",
461
+ "metadata": {},
462
+ "outputs": [
463
+ {
464
+ "name": "stdout",
465
+ "output_type": "stream",
466
+ "text": [
467
+ "--- Summary for voxelsv1 ---\n",
468
+ "Min: -10.2188\n",
469
+ "Max: 8.6066\n",
470
+ "Mean: -0.0000\n",
471
+ "Std: 1.0000\n",
472
+ "Number of Outliers (|value - mean| > 3*std): 30371\n",
473
+ "--- Summary for voxels1 ---\n",
474
+ "Min: -5801.5703\n",
475
+ "Max: 4001.2046\n",
476
+ "Mean: 0.0192\n",
477
+ "Std: 1.7900\n",
478
+ "Number of Outliers (|value - mean| > 3*std): 8926010\n",
479
+ "--- Summary for voxels1_zscore ---\n",
480
+ "Min: -14.8227\n",
481
+ "Max: 11.8500\n",
482
+ "Mean: 0.0000\n",
483
+ "Std: 0.9876\n",
484
+ "Number of Outliers (|value - mean| > 3*std): 3272907\n"
485
+ ]
486
+ }
487
+ ],
488
+ "source": [
489
+ "\n",
490
+ "def print_summary(tensor, name=\"Tensor\"):\n",
491
+ " # Convert tensor to CPU if needed, and flatten for convenience\n",
492
+ " data = tensor.detach().cpu().numpy().flatten() if torch.is_tensor(tensor) else tensor\n",
493
+ "\n",
494
+ " # Compute basic statistics\n",
495
+ " t_min = data.min()\n",
496
+ " t_max = data.max()\n",
497
+ " t_mean = data.mean()\n",
498
+ " t_std = data.std()\n",
499
+ "\n",
500
+ " # Simple outlier detection using a threshold, e.g., values beyond mean ± 3*std\n",
501
+ " lower_bound = t_mean - 3 * t_std\n",
502
+ " upper_bound = t_mean + 3 * t_std\n",
503
+ " outliers = data[(data < lower_bound) | (data > upper_bound)]\n",
504
+ "\n",
505
+ " # Print the summary\n",
506
+ " print(f\"--- Summary for {name} ---\")\n",
507
+ " print(f\"Min: {t_min:.4f}\")\n",
508
+ " print(f\"Max: {t_max:.4f}\")\n",
509
+ " print(f\"Mean: {t_mean:.4f}\")\n",
510
+ " print(f\"Std: {t_std:.4f}\")\n",
511
+ " print(f\"Number of Outliers (|value - mean| > 3*std): {len(outliers)}\")\n",
512
+ "\n",
513
+ "# Example usage:\n",
514
+ "print_summary(voxelsv1, \"voxelsv1\")\n",
515
+ "print_summary(voxels1, \"voxels1\")\n",
516
+ "print_summary(voxels1_zscore, \"voxels1_zscore\")\n",
517
+ "\n"
518
+ ]
519
+ },
520
+ {
521
+ "cell_type": "code",
522
+ "execution_count": 11,
523
+ "id": "7eaebdf4-22b7-4c9a-9572-9e69870735df",
524
+ "metadata": {},
525
+ "outputs": [],
526
+ "source": [
527
+ "voxels1 = voxels1_zscore"
528
+ ]
529
+ },
530
+ {
531
+ "cell_type": "code",
532
+ "execution_count": 12,
533
+ "id": "81084834-035f-4465-ad59-59e6b806a2f5",
534
+ "metadata": {
535
+ "tags": []
536
+ },
537
+ "outputs": [
538
+ {
539
+ "data": {
540
+ "text/plain": [
541
+ "'train_data = {}\\ntrain_dl = {}\\nnum_voxels = {}\\nvoxels = {}\\nfor s in subj_list:\\n print(f\"Training with {num_sessions} sessions\")\\n if multi_subject:\\n train_url = f\"{data_path}/wds/subj0{s}/train/\" + \"{0..\" + f\"{nsessions_allsubj[s-1]-1}\" + \"}.tar\"\\n else:\\n train_url = f\"{data_path}/wds/subj0{s}/train/\" + \"{0..\" + f\"{num_sessions-1}\" + \"}.tar\"\\n print(train_url)\\n \\n train_data[f\\'subj0{s}\\'] = wds.WebDataset(train_url,resampled=True,nodesplitter=my_split_by_node) .shuffle(750, initial=1500, rng=random.Random(42)) .decode(\"torch\") .rename(behav=\"behav.npy\", past_behav=\"past_behav.npy\", future_behav=\"future_behav.npy\", olds_behav=\"olds_behav.npy\") .to_tuple(*[\"behav\", \"past_behav\", \"future_behav\", \"olds_behav\"])\\n train_dl[f\\'subj0{s}\\'] = torch.utils.data.DataLoader(train_data[f\\'subj0{s}\\'], batch_size=batch_size, shuffle=False, drop_last=False, pin_memory=True)\\n\\n f = h5py.File(f\\'{data_path}/betas_all_subj0{s}_fp32_renorm.hdf5\\', \\'r\\')\\n betas = f[\\'betas\\'][:]\\n betas = torch.Tensor(betas).to(\"cpu\").to(data_type)\\n num_voxels_list.append(betas[0].shape[-1])\\n num_voxels[f\\'subj0{s}\\'] = betas[0].shape[-1]\\n voxels[f\\'subj0{s}\\'] = betas\\n print(f\"num_voxels for subj0{s}: {num_voxels[f\\'subj0{s}\\']}\")\\n\\nprint(\"Loaded all subj train dls and betas!\\n\")\\n\\n# Validate only on one subject\\nif multi_subject: \\n subj = subj_list[0] # cant validate on the actual held out person so picking first in subj_list\\nif not new_test: # using old test set from before full dataset released (used in original MindEye paper)\\n if subj==3:\\n num_test=2113\\n elif subj==4:\\n num_test=1985\\n elif subj==6:\\n num_test=2113\\n elif subj==8:\\n num_test=1985\\n else:\\n num_test=2770\\n test_url = f\"{data_path}/wds/subj0{subj}/test/\" + \"0.tar\"\\nelif new_test: # using larger test set from after full dataset released\\n if subj==3:\\n num_test=2371\\n elif subj==4:\\n num_test=2188\\n elif subj==6:\\n num_test=2371\\n elif subj==8:\\n num_test=2188\\n else:\\n num_test=3000\\n test_url = f\"{data_path}/wds/subj0{subj}/new_test/\" + \"0.tar\"\\nprint(test_url)\\ntest_data = wds.WebDataset(test_url,resampled=False,nodesplitter=my_split_by_node) .shuffle(750, initial=1500, rng=random.Random(42)) .decode(\"torch\") .rename(behav=\"behav.npy\", past_behav=\"past_behav.npy\", future_behav=\"future_behav.npy\", olds_behav=\"olds_behav.npy\") .to_tuple(*[\"behav\", \"past_behav\", \"future_behav\", \"olds_behav\"])\\ntest_dl = torch.utils.data.DataLoader(test_data, batch_size=num_test, shuffle=False, drop_last=True, pin_memory=True)\\nprint(f\"Loaded test dl for subj{subj}!\\n\")'"
542
+ ]
543
+ },
544
+ "execution_count": 12,
545
+ "metadata": {},
546
+ "output_type": "execute_result"
547
+ }
548
+ ],
549
+ "source": [
550
+ "\"\"\"train_data = {}\n",
551
+ "train_dl = {}\n",
552
+ "num_voxels = {}\n",
553
+ "voxels = {}\n",
554
+ "for s in subj_list:\n",
555
+ " print(f\"Training with {num_sessions} sessions\")\n",
556
+ " if multi_subject:\n",
557
+ " train_url = f\"{data_path}/wds/subj0{s}/train/\" + \"{0..\" + f\"{nsessions_allsubj[s-1]-1}\" + \"}.tar\"\n",
558
+ " else:\n",
559
+ " train_url = f\"{data_path}/wds/subj0{s}/train/\" + \"{0..\" + f\"{num_sessions-1}\" + \"}.tar\"\n",
560
+ " print(train_url)\n",
561
+ " \n",
562
+ " train_data[f'subj0{s}'] = wds.WebDataset(train_url,resampled=True,nodesplitter=my_split_by_node)\\\n",
563
+ " .shuffle(750, initial=1500, rng=random.Random(42))\\\n",
564
+ " .decode(\"torch\")\\\n",
565
+ " .rename(behav=\"behav.npy\", past_behav=\"past_behav.npy\", future_behav=\"future_behav.npy\", olds_behav=\"olds_behav.npy\")\\\n",
566
+ " .to_tuple(*[\"behav\", \"past_behav\", \"future_behav\", \"olds_behav\"])\n",
567
+ " train_dl[f'subj0{s}'] = torch.utils.data.DataLoader(train_data[f'subj0{s}'], batch_size=batch_size, shuffle=False, drop_last=False, pin_memory=True)\n",
568
+ "\n",
569
+ " f = h5py.File(f'{data_path}/betas_all_subj0{s}_fp32_renorm.hdf5', 'r')\n",
570
+ " betas = f['betas'][:]\n",
571
+ " betas = torch.Tensor(betas).to(\"cpu\").to(data_type)\n",
572
+ " num_voxels_list.append(betas[0].shape[-1])\n",
573
+ " num_voxels[f'subj0{s}'] = betas[0].shape[-1]\n",
574
+ " voxels[f'subj0{s}'] = betas\n",
575
+ " print(f\"num_voxels for subj0{s}: {num_voxels[f'subj0{s}']}\")\n",
576
+ "\n",
577
+ "print(\"Loaded all subj train dls and betas!\\n\")\n",
578
+ "\n",
579
+ "# Validate only on one subject\n",
580
+ "if multi_subject: \n",
581
+ " subj = subj_list[0] # cant validate on the actual held out person so picking first in subj_list\n",
582
+ "if not new_test: # using old test set from before full dataset released (used in original MindEye paper)\n",
583
+ " if subj==3:\n",
584
+ " num_test=2113\n",
585
+ " elif subj==4:\n",
586
+ " num_test=1985\n",
587
+ " elif subj==6:\n",
588
+ " num_test=2113\n",
589
+ " elif subj==8:\n",
590
+ " num_test=1985\n",
591
+ " else:\n",
592
+ " num_test=2770\n",
593
+ " test_url = f\"{data_path}/wds/subj0{subj}/test/\" + \"0.tar\"\n",
594
+ "elif new_test: # using larger test set from after full dataset released\n",
595
+ " if subj==3:\n",
596
+ " num_test=2371\n",
597
+ " elif subj==4:\n",
598
+ " num_test=2188\n",
599
+ " elif subj==6:\n",
600
+ " num_test=2371\n",
601
+ " elif subj==8:\n",
602
+ " num_test=2188\n",
603
+ " else:\n",
604
+ " num_test=3000\n",
605
+ " test_url = f\"{data_path}/wds/subj0{subj}/new_test/\" + \"0.tar\"\n",
606
+ "print(test_url)\n",
607
+ "test_data = wds.WebDataset(test_url,resampled=False,nodesplitter=my_split_by_node)\\\n",
608
+ " .shuffle(750, initial=1500, rng=random.Random(42))\\\n",
609
+ " .decode(\"torch\")\\\n",
610
+ " .rename(behav=\"behav.npy\", past_behav=\"past_behav.npy\", future_behav=\"future_behav.npy\", olds_behav=\"olds_behav.npy\")\\\n",
611
+ " .to_tuple(*[\"behav\", \"past_behav\", \"future_behav\", \"olds_behav\"])\n",
612
+ "test_dl = torch.utils.data.DataLoader(test_data, batch_size=num_test, shuffle=False, drop_last=True, pin_memory=True)\n",
613
+ "print(f\"Loaded test dl for subj{subj}!\\n\")\"\"\""
614
+ ]
615
+ },
616
+ {
617
+ "cell_type": "code",
618
+ "execution_count": 13,
619
+ "id": "c13b4b84-094c-4b5b-bace-26c155aa6181",
620
+ "metadata": {
621
+ "tags": []
622
+ },
623
+ "outputs": [
624
+ {
625
+ "data": {
626
+ "text/plain": [
627
+ "'# Load 73k NSD images\\nf = h5py.File(f\\'{data_path}/coco_images_224_float16.hdf5\\', \\'r\\')\\nimages = f[\\'images\\']\\nprint(\"Loaded all 73k possible NSD images to cpu!\", images.shape)'"
628
+ ]
629
+ },
630
+ "execution_count": 13,
631
+ "metadata": {},
632
+ "output_type": "execute_result"
633
+ }
634
+ ],
635
+ "source": [
636
+ "\"\"\"# Load 73k NSD images\n",
637
+ "f = h5py.File(f'{data_path}/coco_images_224_float16.hdf5', 'r')\n",
638
+ "images = f['images']\n",
639
+ "print(\"Loaded all 73k possible NSD images to cpu!\", images.shape)\"\"\""
640
+ ]
641
+ },
642
+ {
643
+ "cell_type": "markdown",
644
+ "id": "10ec4517-dbdf-4ece-98f6-4714d5de4e15",
645
+ "metadata": {},
646
+ "source": [
647
+ "## Load models"
648
+ ]
649
+ },
650
+ {
651
+ "cell_type": "markdown",
652
+ "id": "48d6160e-1ee8-4da7-a755-9dbb452a6fa5",
653
+ "metadata": {},
654
+ "source": [
655
+ "### CLIP image embeddings model"
656
+ ]
657
+ },
658
+ {
659
+ "cell_type": "code",
660
+ "execution_count": 14,
661
+ "id": "b0420dc0-199e-4c1a-857d-b1747058b467",
662
+ "metadata": {
663
+ "tags": []
664
+ },
665
+ "outputs": [],
666
+ "source": [
667
+ "clip_img_embedder = FrozenOpenCLIPImageEmbedder(\n",
668
+ " arch=\"ViT-bigG-14\",\n",
669
+ " version=\"laion2b_s39b_b160k\",\n",
670
+ " output_tokens=True,\n",
671
+ " only_tokens=True,\n",
672
+ ")\n",
673
+ "clip_img_embedder.to(device)\n",
674
+ "\n",
675
+ "clip_seq_dim = 256\n",
676
+ "clip_emb_dim = 1664"
677
+ ]
678
+ },
679
+ {
680
+ "cell_type": "markdown",
681
+ "id": "5b79bd38-6990-4504-8d45-4a68d57d8885",
682
+ "metadata": {},
683
+ "source": [
684
+ "### SD VAE"
685
+ ]
686
+ },
687
+ {
688
+ "cell_type": "code",
689
+ "execution_count": 15,
690
+ "id": "01baff79-8114-482b-b115-6f05aa8ad691",
691
+ "metadata": {
692
+ "tags": []
693
+ },
694
+ "outputs": [],
695
+ "source": [
696
+ "if blurry_recon:\n",
697
+ " from diffusers import AutoencoderKL \n",
698
+ " autoenc = AutoencoderKL(\n",
699
+ " down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D'],\n",
700
+ " up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D'],\n",
701
+ " block_out_channels=[128, 256, 512, 512],\n",
702
+ " layers_per_block=2,\n",
703
+ " sample_size=256,\n",
704
+ " )\n",
705
+ " ckpt = torch.load(f'{cache_dir}/sd_image_var_autoenc.pth')\n",
706
+ " autoenc.load_state_dict(ckpt)\n",
707
+ " \n",
708
+ " autoenc.eval()\n",
709
+ " autoenc.requires_grad_(False)\n",
710
+ " autoenc.to(device)\n",
711
+ " utils.count_params(autoenc)\n",
712
+ " \n",
713
+ " from autoencoder.convnext import ConvnextXL\n",
714
+ " cnx = ConvnextXL(f'{cache_dir}/convnext_xlarge_alpha0.75_fullckpt.pth')\n",
715
+ " cnx.requires_grad_(False)\n",
716
+ " cnx.eval()\n",
717
+ " cnx.to(device)\n",
718
+ " \n",
719
+ " mean = torch.tensor([0.485, 0.456, 0.406]).to(device).reshape(1,3,1,1)\n",
720
+ " std = torch.tensor([0.228, 0.224, 0.225]).to(device).reshape(1,3,1,1)\n",
721
+ " \n",
722
+ " blur_augs = AugmentationSequential(\n",
723
+ " kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1, p=0.8),\n",
724
+ " kornia.augmentation.RandomGrayscale(p=0.1),\n",
725
+ " kornia.augmentation.RandomSolarize(p=0.1),\n",
726
+ " kornia.augmentation.RandomResizedCrop((224,224), scale=(.9,.9), ratio=(1,1), p=1.0),\n",
727
+ " data_keys=[\"input\"],\n",
728
+ " )"
729
+ ]
730
+ },
731
+ {
732
+ "cell_type": "markdown",
733
+ "id": "260e5e4a-f697-4b2c-88fc-01f6a54886c0",
734
+ "metadata": {},
735
+ "source": [
736
+ "### MindEye modules"
737
+ ]
738
+ },
739
+ {
740
+ "cell_type": "code",
741
+ "execution_count": 16,
742
+ "id": "c44c271b-173f-472e-b059-a2eda0f4c4c5",
743
+ "metadata": {
744
+ "tags": []
745
+ },
746
+ "outputs": [
747
+ {
748
+ "data": {
749
+ "text/plain": [
750
+ "MindEyeModule()"
751
+ ]
752
+ },
753
+ "execution_count": 16,
754
+ "metadata": {},
755
+ "output_type": "execute_result"
756
+ }
757
+ ],
758
+ "source": [
759
+ "class MindEyeModule(nn.Module):\n",
760
+ " def __init__(self):\n",
761
+ " super(MindEyeModule, self).__init__()\n",
762
+ " def forward(self, x):\n",
763
+ " return x\n",
764
+ " \n",
765
+ "model = MindEyeModule()\n",
766
+ "model"
767
+ ]
768
+ },
769
+ {
770
+ "cell_type": "code",
771
+ "execution_count": 17,
772
+ "id": "038a5d61-4769-40b9-a004-f4e7b5b38bb0",
773
+ "metadata": {
774
+ "tags": []
775
+ },
776
+ "outputs": [
777
+ {
778
+ "name": "stdout",
779
+ "output_type": "stream",
780
+ "text": [
781
+ "param counts:\n",
782
+ "178,196,480 total\n",
783
+ "178,196,480 trainable\n",
784
+ "param counts:\n",
785
+ "178,196,480 total\n",
786
+ "178,196,480 trainable\n",
787
+ "torch.Size([2, 1, 174019]) torch.Size([2, 1, 1024])\n"
788
+ ]
789
+ }
790
+ ],
791
+ "source": [
792
+ "num_voxels_list = [voxels1.shape[-1]]\n",
793
+ "class RidgeRegression(torch.nn.Module):\n",
794
+ " # make sure to add weight_decay when initializing optimizer to enable regularization\n",
795
+ " def __init__(self, input_sizes, out_features): \n",
796
+ " super(RidgeRegression, self).__init__()\n",
797
+ " self.out_features = out_features\n",
798
+ " self.linears = torch.nn.ModuleList([\n",
799
+ " torch.nn.Linear(input_size, out_features) for input_size in input_sizes\n",
800
+ " ])\n",
801
+ " def forward(self, x, subj_idx):\n",
802
+ " out = self.linears[subj_idx](x[:,0]).unsqueeze(1)\n",
803
+ " return out\n",
804
+ " \n",
805
+ "model.ridge = RidgeRegression(num_voxels_list, out_features=hidden_dim)\n",
806
+ "utils.count_params(model.ridge)\n",
807
+ "utils.count_params(model)\n",
808
+ "\n",
809
+ "# test on subject 1 with fake data\n",
810
+ "b = torch.randn((2,1,num_voxels_list[0]))\n",
811
+ "print(b.shape, model.ridge(b,0).shape)"
812
+ ]
813
+ },
814
+ {
815
+ "cell_type": "code",
816
+ "execution_count": 18,
817
+ "id": "7b8de65a-6d3b-4248-bea9-9b6f4d562321",
818
+ "metadata": {
819
+ "tags": []
820
+ },
821
+ "outputs": [
822
+ {
823
+ "name": "stdout",
824
+ "output_type": "stream",
825
+ "text": [
826
+ "param counts:\n",
827
+ "453,360,280 total\n",
828
+ "453,360,280 trainable\n",
829
+ "param counts:\n",
830
+ "631,556,760 total\n",
831
+ "631,556,760 trainable\n",
832
+ "b.shape torch.Size([2, 1, 1024])\n",
833
+ "torch.Size([2, 256, 1664]) torch.Size([2, 256, 1664]) torch.Size([1]) torch.Size([1])\n"
834
+ ]
835
+ }
836
+ ],
837
+ "source": [
838
+ "from models import BrainNetwork\n",
839
+ "model.backbone = BrainNetwork(h=hidden_dim, in_dim=hidden_dim, seq_len=1, n_blocks=n_blocks,\n",
840
+ " clip_size=clip_emb_dim, out_dim=clip_emb_dim*clip_seq_dim, \n",
841
+ " blurry_recon=blurry_recon, clip_scale=clip_scale)\n",
842
+ "utils.count_params(model.backbone)\n",
843
+ "utils.count_params(model)\n",
844
+ "\n",
845
+ "# test that the model works on some fake data\n",
846
+ "b = torch.randn((2,1,hidden_dim))\n",
847
+ "print(\"b.shape\",b.shape)\n",
848
+ "\n",
849
+ "backbone_, clip_, blur_ = model.backbone(b)\n",
850
+ "print(backbone_.shape, clip_.shape, blur_[0].shape, blur_[1].shape)"
851
+ ]
852
+ },
853
+ {
854
+ "cell_type": "markdown",
855
+ "id": "b397c0d7-52a3-4153-823b-c27d2eb3eeba",
856
+ "metadata": {},
857
+ "source": [
858
+ "### Adding diffusion prior + unCLIP if use_prior=True"
859
+ ]
860
+ },
861
+ {
862
+ "cell_type": "code",
863
+ "execution_count": 19,
864
+ "id": "69965344-9346-4592-9cc5-e537e31d5fce",
865
+ "metadata": {
866
+ "tags": []
867
+ },
868
+ "outputs": [
869
+ {
870
+ "name": "stdout",
871
+ "output_type": "stream",
872
+ "text": [
873
+ "param counts:\n",
874
+ "259,865,216 total\n",
875
+ "259,865,200 trainable\n",
876
+ "param counts:\n",
877
+ "891,421,976 total\n",
878
+ "891,421,960 trainable\n"
879
+ ]
880
+ }
881
+ ],
882
+ "source": [
883
+ "if use_prior:\n",
884
+ " from models import *\n",
885
+ "\n",
886
+ " # setup diffusion prior network\n",
887
+ " out_dim = clip_emb_dim\n",
888
+ " depth = 6\n",
889
+ " dim_head = 52\n",
890
+ " heads = clip_emb_dim//52 # heads * dim_head = clip_emb_dim\n",
891
+ " timesteps = 100\n",
892
+ "\n",
893
+ " prior_network = PriorNetwork(\n",
894
+ " dim=out_dim,\n",
895
+ " depth=depth,\n",
896
+ " dim_head=dim_head,\n",
897
+ " heads=heads,\n",
898
+ " causal=False,\n",
899
+ " num_tokens = clip_seq_dim,\n",
900
+ " learned_query_mode=\"pos_emb\"\n",
901
+ " )\n",
902
+ "\n",
903
+ " model.diffusion_prior = BrainDiffusionPrior(\n",
904
+ " net=prior_network,\n",
905
+ " image_embed_dim=out_dim,\n",
906
+ " condition_on_text_encodings=False,\n",
907
+ " timesteps=timesteps,\n",
908
+ " cond_drop_prob=0.2,\n",
909
+ " image_embed_scale=None,\n",
910
+ " )\n",
911
+ " \n",
912
+ " utils.count_params(model.diffusion_prior)\n",
913
+ " utils.count_params(model)"
914
+ ]
915
+ },
916
+ {
917
+ "cell_type": "markdown",
918
+ "id": "ec25271a-2209-400c-8026-df3b8ddc1eef",
919
+ "metadata": {},
920
+ "source": [
921
+ "### Setup optimizer / lr / ckpt saving"
922
+ ]
923
+ },
924
+ {
925
+ "cell_type": "code",
926
+ "execution_count": 20,
927
+ "id": "e14d0482-dc42-43b9-9ce1-953c32f2c9c1",
928
+ "metadata": {
929
+ "tags": []
930
+ },
931
+ "outputs": [
932
+ {
933
+ "name": "stdout",
934
+ "output_type": "stream",
935
+ "text": [
936
+ "total_steps 98400\n",
937
+ "\n",
938
+ "Done with model preparations!\n",
939
+ "param counts:\n",
940
+ "891,421,976 total\n",
941
+ "891,421,960 trainable\n"
942
+ ]
943
+ }
944
+ ],
945
+ "source": [
946
+ "no_decay = ['bias', 'LayerNorm.bias', 'LayerNorm.weight']\n",
947
+ "\n",
948
+ "opt_grouped_parameters = [\n",
949
+ " {'params': [p for n, p in model.ridge.named_parameters()], 'weight_decay': 1e-2},\n",
950
+ " {'params': [p for n, p in model.backbone.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},\n",
951
+ " {'params': [p for n, p in model.backbone.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0},\n",
952
+ "]\n",
953
+ "if use_prior:\n",
954
+ " opt_grouped_parameters.extend([\n",
955
+ " {'params': [p for n, p in model.diffusion_prior.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},\n",
956
+ " {'params': [p for n, p in model.diffusion_prior.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0}\n",
957
+ " ])\n",
958
+ "\n",
959
+ "optimizer = torch.optim.AdamW(opt_grouped_parameters, lr=max_lr)\n",
960
+ "\n",
961
+ "if lr_scheduler_type == 'linear':\n",
962
+ " lr_scheduler = torch.optim.lr_scheduler.LinearLR(\n",
963
+ " optimizer,\n",
964
+ " total_iters=int(np.floor(num_epochs*num_iterations_per_epoch)),\n",
965
+ " last_epoch=-1\n",
966
+ " )\n",
967
+ "elif lr_scheduler_type == 'cycle':\n",
968
+ " total_steps=int(np.floor(num_epochs*num_iterations_per_epoch))\n",
969
+ " print(\"total_steps\", total_steps)\n",
970
+ " lr_scheduler = torch.optim.lr_scheduler.OneCycleLR(\n",
971
+ " optimizer, \n",
972
+ " max_lr=max_lr,\n",
973
+ " total_steps=total_steps,\n",
974
+ " final_div_factor=1000,\n",
975
+ " last_epoch=-1, pct_start=2/num_epochs\n",
976
+ " )\n",
977
+ " \n",
978
+ "def save_ckpt(tag):\n",
979
+ " ckpt_path = outdir+f'/{tag}.pth'\n",
980
+ " if accelerator.is_main_process:\n",
981
+ " unwrapped_model = accelerator.unwrap_model(model)\n",
982
+ " torch.save({\n",
983
+ " 'epoch': epoch,\n",
984
+ " 'model_state_dict': unwrapped_model.state_dict(),\n",
985
+ " 'optimizer_state_dict': optimizer.state_dict(),\n",
986
+ " 'lr_scheduler': lr_scheduler.state_dict(),\n",
987
+ " 'train_losses': losses,\n",
988
+ " 'test_losses': test_losses,\n",
989
+ " 'lrs': lrs,\n",
990
+ " }, ckpt_path)\n",
991
+ " print(f\"\\n---saved {outdir}/{tag} ckpt!---\\n\")\n",
992
+ "\n",
993
+ "def load_ckpt(tag,load_lr=True,load_optimizer=True,load_epoch=True,strict=True,outdir=outdir,multisubj_loading=False): \n",
994
+ " print(f\"\\n---loading {outdir}/{tag}.pth ckpt---\\n\")\n",
995
+ " checkpoint = torch.load(outdir+'/last.pth', map_location='cpu')\n",
996
+ " state_dict = checkpoint['model_state_dict']\n",
997
+ " if multisubj_loading: # remove incompatible ridge layer that will otherwise error\n",
998
+ " state_dict.pop('ridge.linears.0.weight',None)\n",
999
+ " model.load_state_dict(state_dict, strict=strict)\n",
1000
+ " if load_epoch:\n",
1001
+ " globals()[\"epoch\"] = checkpoint['epoch']\n",
1002
+ " print(\"Epoch\",epoch)\n",
1003
+ " if load_optimizer:\n",
1004
+ " optimizer.load_state_dict(checkpoint['optimizer_state_dict'])\n",
1005
+ " if load_lr:\n",
1006
+ " lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])\n",
1007
+ " del checkpoint\n",
1008
+ "\n",
1009
+ "print(\"\\nDone with model preparations!\")\n",
1010
+ "num_params = utils.count_params(model)"
1011
+ ]
1012
+ },
1013
+ {
1014
+ "cell_type": "markdown",
1015
+ "id": "983f458b-35b8-49f2-b6db-80296cece730",
1016
+ "metadata": {},
1017
+ "source": [
1018
+ "# Weights and Biases"
1019
+ ]
1020
+ },
1021
+ {
1022
+ "cell_type": "code",
1023
+ "execution_count": 21,
1024
+ "id": "e671cfe9-3a30-461f-bfea-511ff34839b3",
1025
+ "metadata": {},
1026
+ "outputs": [],
1027
+ "source": [
1028
+ "num_test = 370"
1029
+ ]
1030
+ },
1031
+ {
1032
+ "cell_type": "code",
1033
+ "execution_count": 22,
1034
+ "id": "0a25a662-daa8-4de9-9233-8364800fcb6b",
1035
+ "metadata": {
1036
+ "tags": []
1037
+ },
1038
+ "outputs": [
1039
+ {
1040
+ "name": "stdout",
1041
+ "output_type": "stream",
1042
+ "text": [
1043
+ "wandb bold5000 run testingbold5000\n",
1044
+ "wandb_config:\n",
1045
+ " {'model_name': 'testingbold5000', 'global_batch_size': 8, 'batch_size': 8, 'num_epochs': 150, 'num_sessions': 14, 'num_params': 891421960, 'clip_scale': 1.0, 'prior_scale': 30.0, 'blur_scale': 0.5, 'use_image_aug': False, 'max_lr': 0.0003, 'mixup_pct': 0.33, 'num_samples_per_epoch': 5254, 'num_test': 370, 'ckpt_interval': 999, 'ckpt_saving': False, 'seed': 42, 'distributed': False, 'num_devices': 1, 'world_size': 1}\n",
1046
+ "wandb_id: testingbold5000\n"
1047
+ ]
1048
+ },
1049
+ {
1050
+ "name": "stderr",
1051
+ "output_type": "stream",
1052
+ "text": [
1053
+ "\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mckadirt\u001b[0m. Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n"
1054
+ ]
1055
+ },
1056
+ {
1057
+ "data": {
1058
+ "text/html": [
1059
+ "wandb version 0.19.0 is available! To upgrade, please run:\n",
1060
+ " $ pip install wandb --upgrade"
1061
+ ],
1062
+ "text/plain": [
1063
+ "<IPython.core.display.HTML object>"
1064
+ ]
1065
+ },
1066
+ "metadata": {},
1067
+ "output_type": "display_data"
1068
+ },
1069
+ {
1070
+ "data": {
1071
+ "text/html": [
1072
+ "Tracking run with wandb version 0.17.1"
1073
+ ],
1074
+ "text/plain": [
1075
+ "<IPython.core.display.HTML object>"
1076
+ ]
1077
+ },
1078
+ "metadata": {},
1079
+ "output_type": "display_data"
1080
+ },
1081
+ {
1082
+ "data": {
1083
+ "text/html": [
1084
+ "Run data is saved locally in <code>/weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20241207_162441-testingbold5000</code>"
1085
+ ],
1086
+ "text/plain": [
1087
+ "<IPython.core.display.HTML object>"
1088
+ ]
1089
+ },
1090
+ "metadata": {},
1091
+ "output_type": "display_data"
1092
+ },
1093
+ {
1094
+ "data": {
1095
+ "text/html": [
1096
+ "Resuming run <strong><a href='https://stability.wandb.io/ckadirt/bold5000/runs/testingbold5000' target=\"_blank\">testingbold5000</a></strong> to <a href='https://stability.wandb.io/ckadirt/bold5000' target=\"_blank\">Weights & Biases</a> (<a href='https://wandb.me/run' target=\"_blank\">docs</a>)<br/>"
1097
+ ],
1098
+ "text/plain": [
1099
+ "<IPython.core.display.HTML object>"
1100
+ ]
1101
+ },
1102
+ "metadata": {},
1103
+ "output_type": "display_data"
1104
+ },
1105
+ {
1106
+ "data": {
1107
+ "text/html": [
1108
+ " View project at <a href='https://stability.wandb.io/ckadirt/bold5000' target=\"_blank\">https://stability.wandb.io/ckadirt/bold5000</a>"
1109
+ ],
1110
+ "text/plain": [
1111
+ "<IPython.core.display.HTML object>"
1112
+ ]
1113
+ },
1114
+ "metadata": {},
1115
+ "output_type": "display_data"
1116
+ },
1117
+ {
1118
+ "data": {
1119
+ "text/html": [
1120
+ " View run at <a href='https://stability.wandb.io/ckadirt/bold5000/runs/testingbold5000' target=\"_blank\">https://stability.wandb.io/ckadirt/bold5000/runs/testingbold5000</a>"
1121
+ ],
1122
+ "text/plain": [
1123
+ "<IPython.core.display.HTML object>"
1124
+ ]
1125
+ },
1126
+ "metadata": {},
1127
+ "output_type": "display_data"
1128
+ }
1129
+ ],
1130
+ "source": [
1131
+ "if local_rank==0 and wandb_log: # only use main process for wandb logging\n",
1132
+ " import wandb\n",
1133
+ " wandb_project = 'bold5000'\n",
1134
+ " print(f\"wandb {wandb_project} run {model_name}\")\n",
1135
+ " # need to configure wandb beforehand in terminal with \"wandb init\"!\n",
1136
+ " wandb_config = {\n",
1137
+ " \"model_name\": model_name,\n",
1138
+ " \"global_batch_size\": global_batch_size,\n",
1139
+ " \"batch_size\": batch_size,\n",
1140
+ " \"num_epochs\": num_epochs,\n",
1141
+ " \"num_sessions\": num_sessions,\n",
1142
+ " \"num_params\": num_params,\n",
1143
+ " \"clip_scale\": clip_scale,\n",
1144
+ " \"prior_scale\": prior_scale,\n",
1145
+ " \"blur_scale\": blur_scale,\n",
1146
+ " \"use_image_aug\": use_image_aug,\n",
1147
+ " \"max_lr\": max_lr,\n",
1148
+ " \"mixup_pct\": mixup_pct,\n",
1149
+ " \"num_samples_per_epoch\": num_samples_per_epoch,\n",
1150
+ " \"num_test\": num_test,\n",
1151
+ " \"ckpt_interval\": ckpt_interval,\n",
1152
+ " \"ckpt_saving\": ckpt_saving,\n",
1153
+ " \"seed\": seed,\n",
1154
+ " \"distributed\": distributed,\n",
1155
+ " \"num_devices\": num_devices,\n",
1156
+ " \"world_size\": world_size,\n",
1157
+ " }\n",
1158
+ " print(\"wandb_config:\\n\",wandb_config)\n",
1159
+ " print(\"wandb_id:\",model_name)\n",
1160
+ " wandb.init(\n",
1161
+ " id=model_name,\n",
1162
+ " project=wandb_project,\n",
1163
+ " name=model_name,\n",
1164
+ " config=wandb_config,\n",
1165
+ " resume=\"allow\",\n",
1166
+ " )\n",
1167
+ "else:\n",
1168
+ " wandb_log = False"
1169
+ ]
1170
+ },
1171
+ {
1172
+ "cell_type": "markdown",
1173
+ "id": "d5690151-2131-4918-b750-e869cbd1a8a8",
1174
+ "metadata": {},
1175
+ "source": [
1176
+ "# Main"
1177
+ ]
1178
+ },
1179
+ {
1180
+ "cell_type": "code",
1181
+ "execution_count": 23,
1182
+ "id": "12de6387-6e18-4e4b-b5ce-a847d625330a",
1183
+ "metadata": {
1184
+ "tags": []
1185
+ },
1186
+ "outputs": [],
1187
+ "source": [
1188
+ "epoch = 0\n",
1189
+ "losses, test_losses, lrs = [], [], []\n",
1190
+ "best_test_loss = 1e9\n",
1191
+ "torch.cuda.empty_cache()"
1192
+ ]
1193
+ },
1194
+ {
1195
+ "cell_type": "code",
1196
+ "execution_count": 24,
1197
+ "id": "607a7c7b-fe5e-41a4-80bf-d2814b3a57cc",
1198
+ "metadata": {
1199
+ "tags": []
1200
+ },
1201
+ "outputs": [],
1202
+ "source": [
1203
+ "# load multisubject stage1 ckpt if set\n",
1204
+ "if multisubject_ckpt is not None:\n",
1205
+ " load_ckpt(\"last\",outdir=multisubject_ckpt,load_lr=False,load_optimizer=False,load_epoch=False,strict=False,multisubj_loading=True)"
1206
+ ]
1207
+ },
1208
+ {
1209
+ "cell_type": "code",
1210
+ "execution_count": 25,
1211
+ "id": "99f09f76-4481-4133-b09a-a22b10dbc0c4",
1212
+ "metadata": {
1213
+ "tags": []
1214
+ },
1215
+ "outputs": [],
1216
+ "source": [
1217
+ "#train_dls = [train_dl[f'subj0{s}'] for s in subj_list]\n",
1218
+ "images_train = images1[0:-370]\n",
1219
+ "images_test = images1[-370::]\n",
1220
+ "voxels_train = voxels1[0:-370]\n",
1221
+ "voxels_test = voxels1[-370::]\n",
1222
+ "\n",
1223
+ "model, optimizer, images_train, images_test, voxels_train, voxels_test, lr_scheduler = accelerator.prepare(model, optimizer, images_train, images_test, voxels_train, voxels_test, lr_scheduler)\n",
1224
+ "# leaving out test_dl since we will only have local_rank 0 device do evals"
1225
+ ]
1226
+ },
1227
+ {
1228
+ "cell_type": "code",
1229
+ "execution_count": 26,
1230
+ "id": "60be0d5f-3e94-4612-9373-61b53d836393",
1231
+ "metadata": {
1232
+ "tags": []
1233
+ },
1234
+ "outputs": [
1235
+ {
1236
+ "name": "stdout",
1237
+ "output_type": "stream",
1238
+ "text": [
1239
+ "testingbold5000 starting with epoch 0 / 150\n"
1240
+ ]
1241
+ },
1242
+ {
1243
+ "name": "stderr",
1244
+ "output_type": "stream",
1245
+ "text": [
1246
+ " 55%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌ | 83/150 [1:58:25<1:35:35, 85.61s/it, test/blurry_pixcorr=0, test/loss=19.9, test/loss_clip_total=6.55, test/loss_prior=0.443, test/num_steps=83, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.0162, test/test_fwd_pct_correct=0.0108, train/blurry_pixcorr=0, train/bwd_pct_correct=0.999, train/fwd_pct_correct=0.999, train/loss=7.47, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=0.00171, train/loss_prior=0.249, train/lr=0.000146, train/num_steps=50630, train/recon_cossim=0.813, train/recon_mse=0.249]\n"
1247
+ ]
1248
+ },
1249
+ {
1250
+ "ename": "ValueError",
1251
+ "evalue": "NaN loss",
1252
+ "output_type": "error",
1253
+ "traceback": [
1254
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1255
+ "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
1256
+ "Cell \u001b[0;32mIn[26], line 174\u001b[0m\n\u001b[1;32m 171\u001b[0m pixcorr \u001b[38;5;241m=\u001b[39m utils\u001b[38;5;241m.\u001b[39mpixcorr(image[random_samps], blurry_recon_images)\n\u001b[1;32m 172\u001b[0m blurry_pixcorr \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m pixcorr\u001b[38;5;241m.\u001b[39mitem()\n\u001b[0;32m--> 174\u001b[0m \u001b[43mutils\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcheck_loss\u001b[49m\u001b[43m(\u001b[49m\u001b[43mloss\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 175\u001b[0m accelerator\u001b[38;5;241m.\u001b[39mbackward(loss)\n\u001b[1;32m 176\u001b[0m optimizer\u001b[38;5;241m.\u001b[39mstep()\n",
1257
+ "File \u001b[0;32m/weka/proj-fmri/ckadirt/MindEyeV2/src/utils.py:209\u001b[0m, in \u001b[0;36mcheck_loss\u001b[0;34m(loss)\u001b[0m\n\u001b[1;32m 207\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcheck_loss\u001b[39m(loss):\n\u001b[1;32m 208\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m loss\u001b[38;5;241m.\u001b[39misnan()\u001b[38;5;241m.\u001b[39many():\n\u001b[0;32m--> 209\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mNaN loss\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
1258
+ "\u001b[0;31mValueError\u001b[0m: NaN loss"
1259
+ ]
1260
+ }
1261
+ ],
1262
+ "source": [
1263
+ "print(f\"{model_name} starting with epoch {epoch} / {num_epochs}\")\n",
1264
+ "progress_bar = tqdm(range(epoch,num_epochs), ncols=1200, disable=(local_rank!=0))\n",
1265
+ "test_image, test_voxel = None, None\n",
1266
+ "mse = nn.MSELoss()\n",
1267
+ "l1 = nn.L1Loss()\n",
1268
+ "soft_loss_temps = utils.cosine_anneal(0.004, 0.0075, num_epochs - int(mixup_pct * num_epochs))\n",
1269
+ "\n",
1270
+ "for epoch in progress_bar:\n",
1271
+ " model.train()\n",
1272
+ "\n",
1273
+ " fwd_percent_correct = 0.\n",
1274
+ " bwd_percent_correct = 0.\n",
1275
+ " test_fwd_percent_correct = 0.\n",
1276
+ " test_bwd_percent_correct = 0.\n",
1277
+ " \n",
1278
+ " recon_cossim = 0.\n",
1279
+ " test_recon_cossim = 0.\n",
1280
+ " recon_mse = 0.\n",
1281
+ " test_recon_mse = 0.\n",
1282
+ "\n",
1283
+ " loss_clip_total = 0.\n",
1284
+ " loss_blurry_total = 0.\n",
1285
+ " loss_blurry_cont_total = 0.\n",
1286
+ " test_loss_clip_total = 0.\n",
1287
+ " \n",
1288
+ " loss_prior_total = 0.\n",
1289
+ " test_loss_prior_total = 0.\n",
1290
+ "\n",
1291
+ " blurry_pixcorr = 0.\n",
1292
+ " test_blurry_pixcorr = 0. # needs >.456 to beat low-level subj01 results in mindeye v1\n",
1293
+ "\n",
1294
+ " # pre-load all batches for this epoch (it's MUCH faster to pre-load in bulk than to separate loading per batch)\n",
1295
+ " voxel_iters = {} # empty dict because diff subjects have differing # of voxels\n",
1296
+ " image_iters = torch.zeros(num_iterations_per_epoch, batch_size*len(subj_list), 3, 224, 224).float()\n",
1297
+ " annot_iters = {}\n",
1298
+ " perm_iters, betas_iters, select_iters = {}, {}, {}\n",
1299
+ " \"\"\"for s, train_dl in enumerate(train_dls):\n",
1300
+ " with torch.cuda.amp.autocast(dtype=data_type):\n",
1301
+ " iter = -1\n",
1302
+ " for behav0, past_behav0, future_behav0, old_behav0 in train_dl: \n",
1303
+ " # Load images to cpu from hdf5 (requires sorted indexing)\n",
1304
+ " image_idx = behav0[:,0,0].cpu().long().numpy()\n",
1305
+ " image0, image_sorted_idx = np.unique(image_idx, return_index=True) \n",
1306
+ " if len(image0) != len(image_idx): # hdf5 cant handle duplicate indexing\n",
1307
+ " continue\n",
1308
+ " iter += 1\n",
1309
+ " image0 = torch.tensor(images[image0], dtype=data_type)\n",
1310
+ " image_iters[iter,s*batch_size:s*batch_size+batch_size] = image0\n",
1311
+ " \n",
1312
+ " # Load voxels for current batch, matching above indexing\n",
1313
+ " voxel_idx = behav0[:,0,5].cpu().long().numpy()\n",
1314
+ " voxel_sorted_idx = voxel_idx[image_sorted_idx]\n",
1315
+ " voxel0 = voxels[f'subj0{subj_list[s]}'][voxel_sorted_idx]\n",
1316
+ " voxel0 = torch.Tensor(voxel0).unsqueeze(1)\n",
1317
+ "\n",
1318
+ " if epoch < int(mixup_pct * num_epochs):\n",
1319
+ " voxel0, perm, betas, select = utils.mixco(voxel0)\n",
1320
+ " perm_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = perm\n",
1321
+ " betas_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = betas\n",
1322
+ " select_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = select\n",
1323
+ "\n",
1324
+ " voxel_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = voxel0\n",
1325
+ "\n",
1326
+ " if iter >= num_iterations_per_epoch-1:\n",
1327
+ " break\"\"\"\n",
1328
+ "\n",
1329
+ " # you now have voxel_iters and image_iters with num_iterations_per_epoch batches each\n",
1330
+ " for train_i in range(int((len(voxels1)-370)/batch_size)):\n",
1331
+ " with torch.cuda.amp.autocast(dtype=data_type):\n",
1332
+ " random_numbers = [random.randint(0, len(voxels_train)-1) for _ in range(batch_size)]\n",
1333
+ " optimizer.zero_grad()\n",
1334
+ " loss=0.\n",
1335
+ "\n",
1336
+ " #voxel_list = [voxel_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1337
+ " #image = image_iters[train_i].detach()\n",
1338
+ "\n",
1339
+ " image = images_train[random_numbers]#.unsqueeze(0)\n",
1340
+ " image = image.to(device)\n",
1341
+ " #print(image.shape)\n",
1342
+ " if use_image_aug: \n",
1343
+ " image = img_augment(image)\n",
1344
+ "\n",
1345
+ " clip_target = clip_img_embedder(image)\n",
1346
+ " assert not torch.any(torch.isnan(clip_target))\n",
1347
+ "\n",
1348
+ " if False: #epoch < int(mixup_pct * num_epochs):\n",
1349
+ " perm_list = [perm_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1350
+ " perm = torch.cat(perm_list, dim=0)\n",
1351
+ " betas_list = [betas_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1352
+ " betas = torch.cat(betas_list, dim=0)\n",
1353
+ " select_list = [select_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1354
+ " select = torch.cat(select_list, dim=0)\n",
1355
+ "\n",
1356
+ " voxel = voxels_train[random_numbers].unsqueeze(1).to(device)\n",
1357
+ " #print(voxel.shape)\n",
1358
+ " #voxel_ridge_list = [model.ridge(voxel_list[si],si) for si,s in enumerate(subj_list)]\n",
1359
+ " #voxel_ridge = torch.cat(voxel_ridge_list, dim=0)\n",
1360
+ " voxel_ridge = model.ridge(voxel,0)\n",
1361
+ "\n",
1362
+ " backbone, clip_voxels, blurry_image_enc_ = model.backbone(voxel_ridge)\n",
1363
+ "\n",
1364
+ " if clip_scale>0:\n",
1365
+ " clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)\n",
1366
+ " clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)\n",
1367
+ "\n",
1368
+ " if use_prior:\n",
1369
+ " loss_prior, prior_out = model.diffusion_prior(text_embed=backbone, image_embed=clip_target)\n",
1370
+ " loss_prior_total += loss_prior.item()\n",
1371
+ " loss_prior *= prior_scale\n",
1372
+ " loss += loss_prior\n",
1373
+ "\n",
1374
+ " recon_cossim += nn.functional.cosine_similarity(prior_out, clip_target).mean().item()\n",
1375
+ " recon_mse += mse(prior_out, clip_target).item()\n",
1376
+ "\n",
1377
+ " if clip_scale>0:\n",
1378
+ " if False: #epoch < int(mixup_pct * num_epochs): \n",
1379
+ " loss_clip = utils.mixco_nce(\n",
1380
+ " clip_voxels_norm,\n",
1381
+ " clip_target_norm,\n",
1382
+ " temp=.006,\n",
1383
+ " perm=perm, betas=betas, select=select)\n",
1384
+ " else:\n",
1385
+ " epoch_temp = soft_loss_temps[epoch-int(mixup_pct*num_epochs)]\n",
1386
+ " loss_clip = utils.soft_clip_loss(\n",
1387
+ " clip_voxels_norm,\n",
1388
+ " clip_target_norm,\n",
1389
+ " temp=epoch_temp)\n",
1390
+ "\n",
1391
+ " loss_clip_total += loss_clip.item()\n",
1392
+ " loss_clip *= clip_scale\n",
1393
+ " loss += loss_clip\n",
1394
+ "\n",
1395
+ " if blurry_recon: \n",
1396
+ " image_enc_pred, transformer_feats = blurry_image_enc_\n",
1397
+ "\n",
1398
+ " image_enc = autoenc.encode(2*image-1).latent_dist.mode() * 0.18215\n",
1399
+ " loss_blurry = l1(image_enc_pred, image_enc)\n",
1400
+ " loss_blurry_total += loss_blurry.item()\n",
1401
+ "\n",
1402
+ " if False: #epoch < int(mixup_pct * num_epochs):\n",
1403
+ " image_enc_shuf = image_enc[perm]\n",
1404
+ " betas_shape = [-1] + [1]*(len(image_enc.shape)-1)\n",
1405
+ " image_enc[select] = image_enc[select] * betas[select].reshape(*betas_shape) + \\\n",
1406
+ " image_enc_shuf[select] * (1 - betas[select]).reshape(*betas_shape)\n",
1407
+ "\n",
1408
+ " image_norm = (image - mean)/std\n",
1409
+ " image_aug = (blur_augs(image) - mean)/std\n",
1410
+ " _, cnx_embeds = cnx(image_norm)\n",
1411
+ " _, cnx_aug_embeds = cnx(image_aug)\n",
1412
+ "\n",
1413
+ " cont_loss = utils.soft_cont_loss(\n",
1414
+ " nn.functional.normalize(transformer_feats.reshape(-1, transformer_feats.shape[-1]), dim=-1),\n",
1415
+ " nn.functional.normalize(cnx_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),\n",
1416
+ " nn.functional.normalize(cnx_aug_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),\n",
1417
+ " temp=0.2)\n",
1418
+ " loss_blurry_cont_total += cont_loss.item()\n",
1419
+ "\n",
1420
+ " loss += (loss_blurry + 0.1*cont_loss) * blur_scale #/.18215\n",
1421
+ "\n",
1422
+ " if clip_scale>0:\n",
1423
+ " # forward and backward top 1 accuracy \n",
1424
+ " labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device) \n",
1425
+ " fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()\n",
1426
+ " bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()\n",
1427
+ "\n",
1428
+ " if blurry_recon:\n",
1429
+ " with torch.no_grad():\n",
1430
+ " # only doing pixcorr eval on a subset of the samples per batch because its costly & slow to compute autoenc.decode()\n",
1431
+ " random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)\n",
1432
+ " blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample/ 2 + 0.5).clamp(0,1)\n",
1433
+ " pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)\n",
1434
+ " blurry_pixcorr += pixcorr.item()\n",
1435
+ "\n",
1436
+ " utils.check_loss(loss)\n",
1437
+ " accelerator.backward(loss)\n",
1438
+ " optimizer.step()\n",
1439
+ "\n",
1440
+ " losses.append(loss.item())\n",
1441
+ " lrs.append(optimizer.param_groups[0]['lr'])\n",
1442
+ "\n",
1443
+ " if lr_scheduler_type is not None:\n",
1444
+ " lr_scheduler.step()\n",
1445
+ "\n",
1446
+ " model.eval()\n",
1447
+ " if local_rank==0:\n",
1448
+ " with torch.no_grad(), torch.cuda.amp.autocast(dtype=data_type): \n",
1449
+ " for test_i in range(1):\n",
1450
+ " # all test samples should be loaded per batch such that test_i should never exceed 0\n",
1451
+ " # assert len(behav) == num_test\n",
1452
+ "\n",
1453
+ " ## Average same-image repeats ##\n",
1454
+ " if False: #test_image is None:\n",
1455
+ " voxel = voxels[f'subj0{subj}'][behav[:,0,5].cpu().long()].unsqueeze(1)\n",
1456
+ " \n",
1457
+ " image = behav[:,0,0].cpu().long()\n",
1458
+ "\n",
1459
+ " unique_image, sort_indices = torch.unique(image, return_inverse=True)\n",
1460
+ " for im in unique_image:\n",
1461
+ " locs = torch.where(im == image)[0]\n",
1462
+ " if len(locs)==1:\n",
1463
+ " locs = locs.repeat(3)\n",
1464
+ " elif len(locs)==2:\n",
1465
+ " locs = locs.repeat(2)[:3]\n",
1466
+ " assert len(locs)==3\n",
1467
+ " if test_image is None:\n",
1468
+ " test_image = torch.Tensor(images[im][None])\n",
1469
+ " test_voxel = voxel[locs][None]\n",
1470
+ " else:\n",
1471
+ " test_image = torch.vstack((test_image, torch.Tensor(images[im][None])))\n",
1472
+ " test_voxel = torch.vstack((test_voxel, voxel[locs][None]))\n",
1473
+ "\n",
1474
+ " loss=0.\n",
1475
+ " \n",
1476
+ " #test_indices = torch.arange(len(test_voxel))[:300]\n",
1477
+ " voxel = voxels_test.to(device).unsqueeze(1)\n",
1478
+ " image = images_test.to(device)\n",
1479
+ " #assert len(image) == 300\n",
1480
+ "\n",
1481
+ " clip_target = clip_img_embedder(image.float())\n",
1482
+ "\n",
1483
+ " voxel_ridge = model.ridge(voxel,0) # 0th index of subj_list\n",
1484
+ " backbone, clip_voxels, blurry_image_enc_ = model.backbone(voxel_ridge)\n",
1485
+ " \n",
1486
+ " #for rep in range(3):\n",
1487
+ " # voxel_ridge = model.ridge(voxel[:,rep],0) # 0th index of subj_list\n",
1488
+ " # backbone0, clip_voxels0, blurry_image_enc_ = model.backbone(voxel_ridge)\n",
1489
+ " # if rep==0:\n",
1490
+ " # clip_voxels = clip_voxels0\n",
1491
+ " # backbone = backbone0\n",
1492
+ " # else:\n",
1493
+ " # clip_voxels += clip_voxels0\n",
1494
+ " # backbone += backbone0\n",
1495
+ " #clip_voxels /= 3\n",
1496
+ " #backbone /= 3\n",
1497
+ "\n",
1498
+ " if clip_scale>0:\n",
1499
+ " clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)\n",
1500
+ " clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)\n",
1501
+ " \n",
1502
+ " # for some evals, only doing a subset of the samples per batch because of computational cost\n",
1503
+ " random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)\n",
1504
+ " \n",
1505
+ " if use_prior:\n",
1506
+ " loss_prior, contaminated_prior_out = model.diffusion_prior(text_embed=backbone[random_samps], image_embed=clip_target[random_samps])\n",
1507
+ " test_loss_prior_total += loss_prior.item()\n",
1508
+ " loss_prior *= prior_scale\n",
1509
+ " loss += loss_prior\n",
1510
+ " \n",
1511
+ " if clip_scale>0:\n",
1512
+ " loss_clip = utils.soft_clip_loss(\n",
1513
+ " clip_voxels_norm,\n",
1514
+ " clip_target_norm,\n",
1515
+ " temp=.006)\n",
1516
+ "\n",
1517
+ " test_loss_clip_total += loss_clip.item()\n",
1518
+ " loss_clip = loss_clip * clip_scale\n",
1519
+ " loss += loss_clip\n",
1520
+ "\n",
1521
+ " if blurry_recon:\n",
1522
+ " image_enc_pred, _ = blurry_image_enc_\n",
1523
+ " blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample / 2 + 0.5).clamp(0,1)\n",
1524
+ " pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)\n",
1525
+ " test_blurry_pixcorr += pixcorr.item()\n",
1526
+ "\n",
1527
+ " if clip_scale>0:\n",
1528
+ " # forward and backward top 1 accuracy \n",
1529
+ " labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device) \n",
1530
+ " test_fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()\n",
1531
+ " test_bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()\n",
1532
+ " \n",
1533
+ " utils.check_loss(loss) \n",
1534
+ " test_losses.append(loss.item())\n",
1535
+ "\n",
1536
+ " assert (test_i+1) == 1\n",
1537
+ " logs = {\"train/loss\": np.mean(losses[-(train_i+1):]),\n",
1538
+ " \"test/loss\": np.mean(test_losses[-(test_i+1):]),\n",
1539
+ " \"train/lr\": lrs[-1],\n",
1540
+ " \"train/num_steps\": len(losses),\n",
1541
+ " \"test/num_steps\": len(test_losses),\n",
1542
+ " \"train/fwd_pct_correct\": fwd_percent_correct / (train_i + 1),\n",
1543
+ " \"train/bwd_pct_correct\": bwd_percent_correct / (train_i + 1),\n",
1544
+ " \"test/test_fwd_pct_correct\": test_fwd_percent_correct / (test_i + 1),\n",
1545
+ " \"test/test_bwd_pct_correct\": test_bwd_percent_correct / (test_i + 1),\n",
1546
+ " \"train/loss_clip_total\": loss_clip_total / (train_i + 1),\n",
1547
+ " \"train/loss_blurry_total\": loss_blurry_total / (train_i + 1),\n",
1548
+ " \"train/loss_blurry_cont_total\": loss_blurry_cont_total / (train_i + 1),\n",
1549
+ " \"test/loss_clip_total\": test_loss_clip_total / (test_i + 1),\n",
1550
+ " \"train/blurry_pixcorr\": blurry_pixcorr / (train_i + 1),\n",
1551
+ " \"test/blurry_pixcorr\": test_blurry_pixcorr / (test_i + 1),\n",
1552
+ " \"train/recon_cossim\": recon_cossim / (train_i + 1),\n",
1553
+ " \"test/recon_cossim\": test_recon_cossim / (test_i + 1),\n",
1554
+ " \"train/recon_mse\": recon_mse / (train_i + 1),\n",
1555
+ " \"test/recon_mse\": test_recon_mse / (test_i + 1),\n",
1556
+ " \"train/loss_prior\": loss_prior_total / (train_i + 1),\n",
1557
+ " \"test/loss_prior\": test_loss_prior_total / (test_i + 1),\n",
1558
+ " }\n",
1559
+ "\n",
1560
+ " # if finished training, save jpg recons if they exist\n",
1561
+ " if (epoch == num_epochs-1) or (epoch % ckpt_interval == 0):\n",
1562
+ " if blurry_recon: \n",
1563
+ " image_enc = autoenc.encode(2*image[:4]-1).latent_dist.mode() * 0.18215\n",
1564
+ " # transform blurry recon latents to images and plot it\n",
1565
+ " fig, axes = plt.subplots(1, 8, figsize=(10, 4))\n",
1566
+ " jj=-1\n",
1567
+ " for j in [0,1,2,3]:\n",
1568
+ " jj+=1\n",
1569
+ " axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))\n",
1570
+ " axes[jj].axis('off')\n",
1571
+ " jj+=1\n",
1572
+ " axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc_pred[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))\n",
1573
+ " axes[jj].axis('off')\n",
1574
+ "\n",
1575
+ " if wandb_log:\n",
1576
+ " logs[f\"test/blur_recons\"] = wandb.Image(fig, caption=f\"epoch{epoch:03d}\")\n",
1577
+ " plt.close()\n",
1578
+ " else:\n",
1579
+ " plt.show()\n",
1580
+ "\n",
1581
+ " progress_bar.set_postfix(**logs)\n",
1582
+ "\n",
1583
+ " if wandb_log: wandb.log(logs)\n",
1584
+ " \n",
1585
+ " # Save model checkpoint and reconstruct\n",
1586
+ " if (ckpt_saving) and (epoch % ckpt_interval == 0):\n",
1587
+ " save_ckpt(f'last')\n",
1588
+ "\n",
1589
+ " # wait for other GPUs to catch up if needed\n",
1590
+ " accelerator.wait_for_everyone()\n",
1591
+ " torch.cuda.empty_cache()\n",
1592
+ "\n",
1593
+ "print(\"\\n===Finished!===\\n\")\n",
1594
+ "if ckpt_saving:\n",
1595
+ " save_ckpt(f'last')"
1596
+ ]
1597
+ },
1598
+ {
1599
+ "cell_type": "code",
1600
+ "execution_count": null,
1601
+ "id": "2e2fce4d-56aa-46dc-92e9-a15f80d0646b",
1602
+ "metadata": {},
1603
+ "outputs": [],
1604
+ "source": [
1605
+ "losses"
1606
+ ]
1607
+ },
1608
+ {
1609
+ "cell_type": "code",
1610
+ "execution_count": null,
1611
+ "id": "a7e81ae3-171f-40ad-a3e8-24bee4472325",
1612
+ "metadata": {
1613
+ "tags": []
1614
+ },
1615
+ "outputs": [],
1616
+ "source": [
1617
+ "plt.plot(losses)\n",
1618
+ "plt.show()\n",
1619
+ "plt.plot(test_losses)\n",
1620
+ "plt.show()"
1621
+ ]
1622
+ }
1623
+ ],
1624
+ "metadata": {
1625
+ "kernelspec": {
1626
+ "display_name": "fmri",
1627
+ "language": "python",
1628
+ "name": "fmri"
1629
+ },
1630
+ "language_info": {
1631
+ "codemirror_mode": {
1632
+ "name": "ipython",
1633
+ "version": 3
1634
+ },
1635
+ "file_extension": ".py",
1636
+ "mimetype": "text/x-python",
1637
+ "name": "python",
1638
+ "nbconvert_exporter": "python",
1639
+ "pygments_lexer": "ipython3",
1640
+ "version": "3.11.9"
1641
+ },
1642
+ "toc": {
1643
+ "base_numbering": 1,
1644
+ "nav_menu": {},
1645
+ "number_sections": true,
1646
+ "sideBar": true,
1647
+ "skip_h1_title": false,
1648
+ "title_cell": "Table of Contents",
1649
+ "title_sidebar": "Contents",
1650
+ "toc_cell": false,
1651
+ "toc_position": {
1652
+ "height": "calc(100% - 180px)",
1653
+ "left": "10px",
1654
+ "top": "150px",
1655
+ "width": "165px"
1656
+ },
1657
+ "toc_section_display": true,
1658
+ "toc_window_display": true
1659
+ },
1660
+ "toc-autonumbering": true,
1661
+ "vscode": {
1662
+ "interpreter": {
1663
+ "hash": "62aae01ef0cf7b6af841ab1c8ce59175c4332e693ab3d00bc32ceffb78a35376"
1664
+ }
1665
+ }
1666
+ },
1667
+ "nbformat": 4,
1668
+ "nbformat_minor": 5
1669
+ }
MindEyeV2/src/TrainCluster-Copy2.ipynb ADDED
@@ -0,0 +1,1910 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "b0f0f4f3",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Import packages & functions"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": 1,
14
+ "id": "5bad764b-45c1-45ce-a716-8d055e09821a",
15
+ "metadata": {
16
+ "tags": []
17
+ },
18
+ "outputs": [],
19
+ "source": [
20
+ "import os\n",
21
+ "import sys\n",
22
+ "import json\n",
23
+ "import argparse\n",
24
+ "import numpy as np\n",
25
+ "import math\n",
26
+ "from einops import rearrange\n",
27
+ "import time\n",
28
+ "import random\n",
29
+ "import string\n",
30
+ "import h5py\n",
31
+ "from tqdm import tqdm\n",
32
+ "import webdataset as wds\n",
33
+ "\n",
34
+ "import matplotlib.pyplot as plt\n",
35
+ "import torch\n",
36
+ "import torch.nn as nn\n",
37
+ "from torchvision import transforms\n",
38
+ "from accelerate import Accelerator\n",
39
+ "\n",
40
+ "# SDXL unCLIP requires code from https://github.com/Stability-AI/generative-models/tree/main\n",
41
+ "sys.path.append('generative_models/')\n",
42
+ "import sgm\n",
43
+ "from generative_models.sgm.modules.encoders.modules import FrozenOpenCLIPImageEmbedder # bigG embedder\n",
44
+ "\n",
45
+ "# tf32 data type is faster than standard float32\n",
46
+ "torch.backends.cuda.matmul.allow_tf32 = True\n",
47
+ "\n",
48
+ "# custom functions #\n",
49
+ "import utils"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 31,
55
+ "id": "f9cdfdb2-a81e-495f-a777-31acd22d9746",
56
+ "metadata": {},
57
+ "outputs": [
58
+ {
59
+ "name": "stdout",
60
+ "output_type": "stream",
61
+ "text": [
62
+ "Top-1 Precision: 0.00%\n"
63
+ ]
64
+ }
65
+ ],
66
+ "source": [
67
+ "import torch\n",
68
+ "import torch.nn.functional as F\n",
69
+ "\n",
70
+ "def classPrecision(logits, y_true, top=1):\n",
71
+ " \"\"\"\n",
72
+ " Calculate the precision of the top-n predictions.\n",
73
+ " \n",
74
+ " Parameters:\n",
75
+ " logits (torch.Tensor): The output logits from the model (shape: [batch_size, num_classes]).\n",
76
+ " y_true (torch.Tensor): The ground truth labels (shape: [batch_size]).\n",
77
+ " top (int): The number of top predictions to consider.\n",
78
+ " \n",
79
+ " Returns:\n",
80
+ " float: The precision percentage of the top-n predictions.\n",
81
+ " \"\"\"\n",
82
+ " # Apply softmax to get probabilities\n",
83
+ " probs = F.softmax(logits, dim=1).detach().cpu()\n",
84
+ " \n",
85
+ " # Get the top-n predictions\n",
86
+ " top_n_preds = torch.topk(probs, top, dim=1).indices.detach().cpu()\n",
87
+ "\n",
88
+ " # Move y_true to CPU and detach\n",
89
+ " y_true = y_true.detach().cpu()\n",
90
+ "\n",
91
+ " # Check if y_true is in top-n predictions\n",
92
+ " correct = top_n_preds.eq(y_true.view(-1, 1).expand_as(top_n_preds))\n",
93
+ "\n",
94
+ " # Calculate precision\n",
95
+ " precision = correct.sum().item() / y_true.size(0)\n",
96
+ " \n",
97
+ " return precision * 100\n",
98
+ "\n",
99
+ "# Example usage:\n",
100
+ "logits = torch.randn(8, 41) # Example logits tensor\n",
101
+ "y_true = torch.randint(0, 41, (8,)) # Example ground truth labels\n",
102
+ "\n",
103
+ "top_n_precision = classPrecision(logits, y_true, top=1)\n",
104
+ "print(f\"Top-1 Precision: {top_n_precision:.2f}%\")\n"
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "code",
109
+ "execution_count": 3,
110
+ "id": "cc5d2e32-6027-4a19-bef4-5ca068db35bb",
111
+ "metadata": {
112
+ "tags": []
113
+ },
114
+ "outputs": [
115
+ {
116
+ "name": "stdout",
117
+ "output_type": "stream",
118
+ "text": [
119
+ "LOCAL RANK 0\n"
120
+ ]
121
+ }
122
+ ],
123
+ "source": [
124
+ "### Multi-GPU config ###\n",
125
+ "local_rank = os.getenv('RANK')\n",
126
+ "if local_rank is None: \n",
127
+ " local_rank = 0\n",
128
+ "else:\n",
129
+ " local_rank = int(local_rank)\n",
130
+ "print(\"LOCAL RANK \", local_rank) \n",
131
+ "\n",
132
+ "data_type = torch.float16 # change depending on your mixed_precision\n",
133
+ "num_devices = torch.cuda.device_count()\n",
134
+ "if num_devices==0: num_devices = 1\n",
135
+ "\n",
136
+ "# First use \"accelerate config\" in terminal and setup using deepspeed stage 2 with CPU offloading!\n",
137
+ "accelerator = Accelerator(split_batches=False, mixed_precision=\"fp16\")\n",
138
+ "if utils.is_interactive(): # set batch size here if using interactive notebook instead of submitting job\n",
139
+ " global_batch_size = batch_size = 16\n",
140
+ "else:\n",
141
+ " global_batch_size = os.environ[\"GLOBAL_BATCH_SIZE\"]\n",
142
+ " batch_size = int(os.environ[\"GLOBAL_BATCH_SIZE\"]) // num_devices"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "execution_count": 4,
148
+ "id": "b767ab6f-d4a9-47a5-b3bf-f56bf6760c0c",
149
+ "metadata": {
150
+ "tags": []
151
+ },
152
+ "outputs": [
153
+ {
154
+ "name": "stdout",
155
+ "output_type": "stream",
156
+ "text": [
157
+ "PID of this process = 5887\n",
158
+ "device: cuda\n",
159
+ "Distributed environment: DistributedType.NO\n",
160
+ "Num processes: 1\n",
161
+ "Process index: 0\n",
162
+ "Local process index: 0\n",
163
+ "Device: cuda\n",
164
+ "\n",
165
+ "Mixed precision type: fp16\n",
166
+ "\n",
167
+ "distributed = False num_devices = 1 local rank = 0 world size = 1 data_type = torch.float16\n"
168
+ ]
169
+ }
170
+ ],
171
+ "source": [
172
+ "print(\"PID of this process =\",os.getpid())\n",
173
+ "device = accelerator.device\n",
174
+ "print(\"device:\",device)\n",
175
+ "world_size = accelerator.state.num_processes\n",
176
+ "distributed = not accelerator.state.distributed_type == 'NO'\n",
177
+ "num_devices = torch.cuda.device_count()\n",
178
+ "if num_devices==0 or not distributed: num_devices = 1\n",
179
+ "num_workers = num_devices\n",
180
+ "print(accelerator.state)\n",
181
+ "\n",
182
+ "print(\"distributed =\",distributed, \"num_devices =\", num_devices, \"local rank =\", local_rank, \"world size =\", world_size, \"data_type =\", data_type)\n",
183
+ "print = accelerator.print # only print if local_rank=0"
184
+ ]
185
+ },
186
+ {
187
+ "cell_type": "markdown",
188
+ "id": "9018b82b-c054-4463-9527-4b0c2a75bda6",
189
+ "metadata": {
190
+ "tags": []
191
+ },
192
+ "source": [
193
+ "# Configurations"
194
+ ]
195
+ },
196
+ {
197
+ "cell_type": "code",
198
+ "execution_count": 5,
199
+ "id": "2b61fec7-72a0-4b67-86da-1375f1d9fbd3",
200
+ "metadata": {
201
+ "tags": []
202
+ },
203
+ "outputs": [
204
+ {
205
+ "name": "stdout",
206
+ "output_type": "stream",
207
+ "text": [
208
+ "model_name: testing-tt3\n",
209
+ "--data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=testing-tt3 --no-multi_subject --subj=1 --batch_size=16 --num_sessions=40 --hidden_dim=1024 --clip_scale=1. --no-blurry_recon --blur_scale=.5 --use_prior --prior_scale=30 --n_blocks=4 --max_lr=1e-5 --mixup_pct=.33 --num_epochs=150 --no-use_image_aug --ckpt_interval=999 --no-ckpt_saving --wandb_log\n"
210
+ ]
211
+ }
212
+ ],
213
+ "source": [
214
+ "# if running this interactively, can specify jupyter_args here for argparser to use\n",
215
+ "if utils.is_interactive():\n",
216
+ " model_name = \"testing-tt3\"\n",
217
+ " print(\"model_name:\", model_name)\n",
218
+ " \n",
219
+ " # global_batch_size and batch_size should already be defined in the 2nd cell block\n",
220
+ " jupyter_args = f\"--data_path=/weka/proj-medarc/shared/mindeyev2_dataset \\\n",
221
+ " --cache_dir=/weka/proj-medarc/shared/cache \\\n",
222
+ " --model_name={model_name} \\\n",
223
+ " --no-multi_subject --subj=1 --batch_size={batch_size} --num_sessions=40 \\\n",
224
+ " --hidden_dim=1024 --clip_scale=1. \\\n",
225
+ " --no-blurry_recon --blur_scale=.5 \\\n",
226
+ " --use_prior --prior_scale=30 \\\n",
227
+ " --n_blocks=4 --max_lr=1e-5 --mixup_pct=.33 --num_epochs=150 --no-use_image_aug \\\n",
228
+ " --ckpt_interval=999 --no-ckpt_saving --wandb_log\"\n",
229
+ " # --multisubject_ckpt=../train_logs/multisubject_subj01_1024_24bs_nolow\n",
230
+ "\n",
231
+ " print(jupyter_args)\n",
232
+ " jupyter_args = jupyter_args.split()\n",
233
+ " \n",
234
+ " from IPython.display import clear_output # function to clear print outputs in cell\n",
235
+ " %load_ext autoreload \n",
236
+ " # this allows you to change functions in models.py or utils.py and have this notebook automatically update with your revisions\n",
237
+ " %autoreload 2 "
238
+ ]
239
+ },
240
+ {
241
+ "cell_type": "code",
242
+ "execution_count": 6,
243
+ "id": "2028bdf0-2f41-46d9-b6e7-86b870dbf16c",
244
+ "metadata": {
245
+ "tags": []
246
+ },
247
+ "outputs": [
248
+ {
249
+ "name": "stdout",
250
+ "output_type": "stream",
251
+ "text": [
252
+ "subj_list [1] num_sessions 40\n"
253
+ ]
254
+ }
255
+ ],
256
+ "source": [
257
+ "parser = argparse.ArgumentParser(description=\"Model Training Configuration\")\n",
258
+ "parser.add_argument(\n",
259
+ " \"--model_name\", type=str, default=\"testing2\",\n",
260
+ " help=\"name of model, used for ckpt saving and wandb logging (if enabled)\",\n",
261
+ ")\n",
262
+ "parser.add_argument(\n",
263
+ " \"--data_path\", type=str, default=os.getcwd(),\n",
264
+ " help=\"Path to where NSD data is stored / where to download it to\",\n",
265
+ ")\n",
266
+ "parser.add_argument(\n",
267
+ " \"--cache_dir\", type=str, default=os.getcwd(),\n",
268
+ " help=\"Path to where misc. files downloaded from huggingface are stored. Defaults to current src directory.\",\n",
269
+ ")\n",
270
+ "parser.add_argument(\n",
271
+ " \"--subj\",type=int, default=1, choices=[1,2,3,4,5,6,7,8],\n",
272
+ " help=\"Validate on which subject?\",\n",
273
+ ")\n",
274
+ "parser.add_argument(\n",
275
+ " \"--multisubject_ckpt\", type=str, default=None,\n",
276
+ " help=\"Path to pre-trained multisubject model to finetune a single subject from. multisubject must be False.\",\n",
277
+ ")\n",
278
+ "parser.add_argument(\n",
279
+ " \"--num_sessions\", type=int, default=1,\n",
280
+ " help=\"Number of training sessions to include\",\n",
281
+ ")\n",
282
+ "parser.add_argument(\n",
283
+ " \"--use_prior\",action=argparse.BooleanOptionalAction,default=True,\n",
284
+ " help=\"whether to train diffusion prior (True) or just rely on retrieval part of the pipeline (False)\",\n",
285
+ ")\n",
286
+ "parser.add_argument(\n",
287
+ " \"--batch_size\", type=int, default=16,\n",
288
+ " help=\"Batch size can be increased by 10x if only training retreival submodule and not diffusion prior\",\n",
289
+ ")\n",
290
+ "parser.add_argument(\n",
291
+ " \"--wandb_log\",action=argparse.BooleanOptionalAction,default=False,\n",
292
+ " help=\"whether to log to wandb\",\n",
293
+ ")\n",
294
+ "parser.add_argument(\n",
295
+ " \"--wandb_project\",type=str,default=\"stability\",\n",
296
+ " help=\"wandb project name\",\n",
297
+ ")\n",
298
+ "parser.add_argument(\n",
299
+ " \"--mixup_pct\",type=float,default=.33,\n",
300
+ " help=\"proportion of way through training when to switch from BiMixCo to SoftCLIP\",\n",
301
+ ")\n",
302
+ "parser.add_argument(\n",
303
+ " \"--blurry_recon\",action=argparse.BooleanOptionalAction,default=True,\n",
304
+ " help=\"whether to output blurry reconstructions\",\n",
305
+ ")\n",
306
+ "parser.add_argument(\n",
307
+ " \"--blur_scale\",type=float,default=.5,\n",
308
+ " help=\"multiply loss from blurry recons by this number\",\n",
309
+ ")\n",
310
+ "parser.add_argument(\n",
311
+ " \"--clip_scale\",type=float,default=1.,\n",
312
+ " help=\"multiply contrastive loss by this number\",\n",
313
+ ")\n",
314
+ "parser.add_argument(\n",
315
+ " \"--prior_scale\",type=float,default=30,\n",
316
+ " help=\"multiply diffusion prior loss by this\",\n",
317
+ ")\n",
318
+ "parser.add_argument(\n",
319
+ " \"--use_image_aug\",action=argparse.BooleanOptionalAction,default=False,\n",
320
+ " help=\"whether to use image augmentation\",\n",
321
+ ")\n",
322
+ "parser.add_argument(\n",
323
+ " \"--num_epochs\",type=int,default=150,\n",
324
+ " help=\"number of epochs of training\",\n",
325
+ ")\n",
326
+ "parser.add_argument(\n",
327
+ " \"--multi_subject\",action=argparse.BooleanOptionalAction,default=False,\n",
328
+ ")\n",
329
+ "parser.add_argument(\n",
330
+ " \"--new_test\",action=argparse.BooleanOptionalAction,default=True,\n",
331
+ ")\n",
332
+ "parser.add_argument(\n",
333
+ " \"--n_blocks\",type=int,default=4,\n",
334
+ ")\n",
335
+ "parser.add_argument(\n",
336
+ " \"--hidden_dim\",type=int,default=1024,\n",
337
+ ")\n",
338
+ "parser.add_argument(\n",
339
+ " \"--lr_scheduler_type\",type=str,default='cycle',choices=['cycle','linear'],\n",
340
+ ")\n",
341
+ "parser.add_argument(\n",
342
+ " \"--ckpt_saving\",action=argparse.BooleanOptionalAction,default=True,\n",
343
+ ")\n",
344
+ "parser.add_argument(\n",
345
+ " \"--ckpt_interval\",type=int,default=5,\n",
346
+ " help=\"save backup ckpt and reconstruct every x epochs\",\n",
347
+ ")\n",
348
+ "parser.add_argument(\n",
349
+ " \"--seed\",type=int,default=42,\n",
350
+ ")\n",
351
+ "parser.add_argument(\n",
352
+ " \"--max_lr\",type=float,default=3e-5,\n",
353
+ ")\n",
354
+ "\n",
355
+ "if utils.is_interactive():\n",
356
+ " args = parser.parse_args(jupyter_args)\n",
357
+ "else:\n",
358
+ " args = parser.parse_args()\n",
359
+ "\n",
360
+ "# create global variables without the args prefix\n",
361
+ "for attribute_name in vars(args).keys():\n",
362
+ " globals()[attribute_name] = getattr(args, attribute_name)\n",
363
+ " \n",
364
+ "# seed all random functions\n",
365
+ "utils.seed_everything(seed)\n",
366
+ "\n",
367
+ "outdir = os.path.abspath(f'../train_logs/{model_name}')\n",
368
+ "if not os.path.exists(outdir) and ckpt_saving:\n",
369
+ " os.makedirs(outdir,exist_ok=True)\n",
370
+ " \n",
371
+ "if use_image_aug or blurry_recon:\n",
372
+ " import kornia\n",
373
+ " from kornia.augmentation.container import AugmentationSequential\n",
374
+ "if use_image_aug:\n",
375
+ " img_augment = AugmentationSequential(\n",
376
+ " kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1, p=0.3),\n",
377
+ " same_on_batch=False,\n",
378
+ " data_keys=[\"input\"],\n",
379
+ " )\n",
380
+ " \n",
381
+ "if multi_subject:\n",
382
+ " subj_list = np.arange(1,9)\n",
383
+ " subj_list = subj_list[subj_list != subj]\n",
384
+ "else:\n",
385
+ " subj_list = [subj]\n",
386
+ "\n",
387
+ "print(\"subj_list\", subj_list, \"num_sessions\", num_sessions)"
388
+ ]
389
+ },
390
+ {
391
+ "cell_type": "code",
392
+ "execution_count": 7,
393
+ "id": "2fb18bf3-27f5-470c-be05-002215d391b9",
394
+ "metadata": {},
395
+ "outputs": [
396
+ {
397
+ "data": {
398
+ "text/plain": [
399
+ "1e-05"
400
+ ]
401
+ },
402
+ "execution_count": 7,
403
+ "metadata": {},
404
+ "output_type": "execute_result"
405
+ }
406
+ ],
407
+ "source": [
408
+ "max_lr"
409
+ ]
410
+ },
411
+ {
412
+ "cell_type": "markdown",
413
+ "id": "42d13c25-1369-4c49-81d4-83d713586096",
414
+ "metadata": {
415
+ "tags": []
416
+ },
417
+ "source": [
418
+ "# Prep data, models, and dataloaders"
419
+ ]
420
+ },
421
+ {
422
+ "cell_type": "markdown",
423
+ "id": "1c023f24-5233-4a15-a2f5-78487b3a8546",
424
+ "metadata": {},
425
+ "source": [
426
+ "### Creating wds dataloader, preload betas and all 73k possible images"
427
+ ]
428
+ },
429
+ {
430
+ "cell_type": "code",
431
+ "execution_count": 8,
432
+ "id": "aefe7c27-ab39-4b2c-90f4-480f4087b7ab",
433
+ "metadata": {
434
+ "tags": []
435
+ },
436
+ "outputs": [
437
+ {
438
+ "name": "stdout",
439
+ "output_type": "stream",
440
+ "text": [
441
+ "dividing batch size by subj_list, which will then be concatenated across subj during training...\n",
442
+ "batch_size = 16 num_iterations_per_epoch = 1875 num_samples_per_epoch = 30000\n"
443
+ ]
444
+ }
445
+ ],
446
+ "source": [
447
+ "def my_split_by_node(urls): return urls\n",
448
+ "num_voxels_list = []\n",
449
+ "\n",
450
+ "if multi_subject:\n",
451
+ " nsessions_allsubj=np.array([40, 40, 32, 30, 40, 32, 40, 30])\n",
452
+ " num_samples_per_epoch = (750*40) // num_devices \n",
453
+ "else:\n",
454
+ " num_samples_per_epoch = (750*num_sessions) // num_devices \n",
455
+ "\n",
456
+ "print(\"dividing batch size by subj_list, which will then be concatenated across subj during training...\") \n",
457
+ "batch_size = batch_size // len(subj_list)\n",
458
+ "\n",
459
+ "num_iterations_per_epoch = num_samples_per_epoch // (batch_size*len(subj_list))\n",
460
+ "\n",
461
+ "print(\"batch_size =\", batch_size, \"num_iterations_per_epoch =\",num_iterations_per_epoch, \"num_samples_per_epoch =\",num_samples_per_epoch)"
462
+ ]
463
+ },
464
+ {
465
+ "cell_type": "code",
466
+ "execution_count": 9,
467
+ "id": "81084834-035f-4465-ad59-59e6b806a2f5",
468
+ "metadata": {
469
+ "tags": []
470
+ },
471
+ "outputs": [
472
+ {
473
+ "name": "stdout",
474
+ "output_type": "stream",
475
+ "text": [
476
+ "Training with 40 sessions\n",
477
+ "/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/train/{0..39}.tar\n",
478
+ "num_voxels for subj01: 15724\n",
479
+ "Loaded all subj train dls and betas!\n",
480
+ "\n",
481
+ "/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/new_test/0.tar\n",
482
+ "Loaded test dl for subj1!\n",
483
+ "\n"
484
+ ]
485
+ }
486
+ ],
487
+ "source": [
488
+ "train_data = {}\n",
489
+ "train_dl = {}\n",
490
+ "num_voxels = {}\n",
491
+ "voxels = {}\n",
492
+ "for s in subj_list:\n",
493
+ " print(f\"Training with {num_sessions} sessions\")\n",
494
+ " if multi_subject:\n",
495
+ " train_url = f\"{data_path}/wds/subj0{s}/train/\" + \"{0..\" + f\"{nsessions_allsubj[s-1]-1}\" + \"}.tar\"\n",
496
+ " else:\n",
497
+ " train_url = f\"{data_path}/wds/subj0{s}/train/\" + \"{0..\" + f\"{num_sessions-1}\" + \"}.tar\"\n",
498
+ " print(train_url)\n",
499
+ " \n",
500
+ " train_data[f'subj0{s}'] = wds.WebDataset(train_url,resampled=True,nodesplitter=my_split_by_node)\\\n",
501
+ " .shuffle(750, initial=1500, rng=random.Random(42))\\\n",
502
+ " .decode(\"torch\")\\\n",
503
+ " .rename(behav=\"behav.npy\", past_behav=\"past_behav.npy\", future_behav=\"future_behav.npy\", olds_behav=\"olds_behav.npy\")\\\n",
504
+ " .to_tuple(*[\"behav\", \"past_behav\", \"future_behav\", \"olds_behav\"])\n",
505
+ " train_dl[f'subj0{s}'] = torch.utils.data.DataLoader(train_data[f'subj0{s}'], batch_size=batch_size, shuffle=False, drop_last=False, pin_memory=True)\n",
506
+ "\n",
507
+ " f = h5py.File(f'{data_path}/betas_all_subj0{s}_fp32_renorm.hdf5', 'r')\n",
508
+ " betas = f['betas'][:]\n",
509
+ " betas = torch.Tensor(betas).to(\"cpu\").to(data_type)\n",
510
+ " num_voxels_list.append(betas[0].shape[-1])\n",
511
+ " num_voxels[f'subj0{s}'] = betas[0].shape[-1]\n",
512
+ " voxels[f'subj0{s}'] = betas\n",
513
+ " print(f\"num_voxels for subj0{s}: {num_voxels[f'subj0{s}']}\")\n",
514
+ "\n",
515
+ "print(\"Loaded all subj train dls and betas!\\n\")\n",
516
+ "\n",
517
+ "# Validate only on one subject\n",
518
+ "if multi_subject: \n",
519
+ " subj = subj_list[0] # cant validate on the actual held out person so picking first in subj_list\n",
520
+ "if not new_test: # using old test set from before full dataset released (used in original MindEye paper)\n",
521
+ " if subj==3:\n",
522
+ " num_test=2113\n",
523
+ " elif subj==4:\n",
524
+ " num_test=1985\n",
525
+ " elif subj==6:\n",
526
+ " num_test=2113\n",
527
+ " elif subj==8:\n",
528
+ " num_test=1985\n",
529
+ " else:\n",
530
+ " num_test=2770\n",
531
+ " test_url = f\"{data_path}/wds/subj0{subj}/test/\" + \"0.tar\"\n",
532
+ "elif new_test: # using larger test set from after full dataset released\n",
533
+ " if subj==3:\n",
534
+ " num_test=2371\n",
535
+ " elif subj==4:\n",
536
+ " num_test=2188\n",
537
+ " elif subj==6:\n",
538
+ " num_test=2371\n",
539
+ " elif subj==8:\n",
540
+ " num_test=2188\n",
541
+ " else:\n",
542
+ " num_test=3000\n",
543
+ " test_url = f\"{data_path}/wds/subj0{subj}/new_test/\" + \"0.tar\"\n",
544
+ "print(test_url)\n",
545
+ "test_data = wds.WebDataset(test_url,resampled=False,nodesplitter=my_split_by_node)\\\n",
546
+ " .shuffle(750, initial=1500, rng=random.Random(42))\\\n",
547
+ " .decode(\"torch\")\\\n",
548
+ " .rename(behav=\"behav.npy\", past_behav=\"past_behav.npy\", future_behav=\"future_behav.npy\", olds_behav=\"olds_behav.npy\")\\\n",
549
+ " .to_tuple(*[\"behav\", \"past_behav\", \"future_behav\", \"olds_behav\"])\n",
550
+ "test_dl = torch.utils.data.DataLoader(test_data, batch_size=num_test, shuffle=False, drop_last=True, pin_memory=True)\n",
551
+ "print(f\"Loaded test dl for subj{subj}!\\n\")"
552
+ ]
553
+ },
554
+ {
555
+ "cell_type": "code",
556
+ "execution_count": 10,
557
+ "id": "c13b4b84-094c-4b5b-bace-26c155aa6181",
558
+ "metadata": {
559
+ "tags": []
560
+ },
561
+ "outputs": [
562
+ {
563
+ "name": "stdout",
564
+ "output_type": "stream",
565
+ "text": [
566
+ "Loaded all 73k possible NSD images to cpu! (73000, 3, 224, 224)\n"
567
+ ]
568
+ }
569
+ ],
570
+ "source": [
571
+ "# Load 73k NSD images\n",
572
+ "f = h5py.File(f'{data_path}/coco_images_224_float16.hdf5', 'r')\n",
573
+ "images = f['images']\n",
574
+ "print(\"Loaded all 73k possible NSD images to cpu!\", images.shape)"
575
+ ]
576
+ },
577
+ {
578
+ "cell_type": "markdown",
579
+ "id": "10ec4517-dbdf-4ece-98f6-4714d5de4e15",
580
+ "metadata": {},
581
+ "source": [
582
+ "## Load models"
583
+ ]
584
+ },
585
+ {
586
+ "cell_type": "markdown",
587
+ "id": "48d6160e-1ee8-4da7-a755-9dbb452a6fa5",
588
+ "metadata": {},
589
+ "source": [
590
+ "### CLIP image embeddings model"
591
+ ]
592
+ },
593
+ {
594
+ "cell_type": "code",
595
+ "execution_count": 11,
596
+ "id": "b0420dc0-199e-4c1a-857d-b1747058b467",
597
+ "metadata": {
598
+ "tags": []
599
+ },
600
+ "outputs": [],
601
+ "source": [
602
+ "clip_img_embedder = FrozenOpenCLIPImageEmbedder(\n",
603
+ " arch=\"ViT-bigG-14\",\n",
604
+ " version=\"laion2b_s39b_b160k\",\n",
605
+ " output_tokens=True,\n",
606
+ " only_tokens=True,\n",
607
+ ")\n",
608
+ "clip_img_embedder.to(device)\n",
609
+ "\n",
610
+ "clip_seq_dim = 256\n",
611
+ "clip_emb_dim = 1664"
612
+ ]
613
+ },
614
+ {
615
+ "cell_type": "markdown",
616
+ "id": "5b79bd38-6990-4504-8d45-4a68d57d8885",
617
+ "metadata": {},
618
+ "source": [
619
+ "### SD VAE"
620
+ ]
621
+ },
622
+ {
623
+ "cell_type": "code",
624
+ "execution_count": 12,
625
+ "id": "01baff79-8114-482b-b115-6f05aa8ad691",
626
+ "metadata": {
627
+ "tags": []
628
+ },
629
+ "outputs": [],
630
+ "source": [
631
+ "if blurry_recon:\n",
632
+ " from diffusers import AutoencoderKL \n",
633
+ " autoenc = AutoencoderKL(\n",
634
+ " down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D'],\n",
635
+ " up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D'],\n",
636
+ " block_out_channels=[128, 256, 512, 512],\n",
637
+ " layers_per_block=2,\n",
638
+ " sample_size=256,\n",
639
+ " )\n",
640
+ " ckpt = torch.load(f'{cache_dir}/sd_image_var_autoenc.pth')\n",
641
+ " autoenc.load_state_dict(ckpt)\n",
642
+ " \n",
643
+ " autoenc.eval()\n",
644
+ " autoenc.requires_grad_(False)\n",
645
+ " autoenc.to(device)\n",
646
+ " utils.count_params(autoenc)\n",
647
+ " \n",
648
+ " from autoencoder.convnext import ConvnextXL\n",
649
+ " cnx = ConvnextXL(f'{cache_dir}/convnext_xlarge_alpha0.75_fullckpt.pth')\n",
650
+ " cnx.requires_grad_(False)\n",
651
+ " cnx.eval()\n",
652
+ " cnx.to(device)\n",
653
+ " \n",
654
+ " mean = torch.tensor([0.485, 0.456, 0.406]).to(device).reshape(1,3,1,1)\n",
655
+ " std = torch.tensor([0.228, 0.224, 0.225]).to(device).reshape(1,3,1,1)\n",
656
+ " \n",
657
+ " blur_augs = AugmentationSequential(\n",
658
+ " kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1, p=0.8),\n",
659
+ " kornia.augmentation.RandomGrayscale(p=0.1),\n",
660
+ " kornia.augmentation.RandomSolarize(p=0.1),\n",
661
+ " kornia.augmentation.RandomResizedCrop((224,224), scale=(.9,.9), ratio=(1,1), p=1.0),\n",
662
+ " data_keys=[\"input\"],\n",
663
+ " )"
664
+ ]
665
+ },
666
+ {
667
+ "cell_type": "markdown",
668
+ "id": "260e5e4a-f697-4b2c-88fc-01f6a54886c0",
669
+ "metadata": {},
670
+ "source": [
671
+ "### MindEye modules"
672
+ ]
673
+ },
674
+ {
675
+ "cell_type": "code",
676
+ "execution_count": 13,
677
+ "id": "c44c271b-173f-472e-b059-a2eda0f4c4c5",
678
+ "metadata": {
679
+ "tags": []
680
+ },
681
+ "outputs": [
682
+ {
683
+ "data": {
684
+ "text/plain": [
685
+ "MindEyeModule()"
686
+ ]
687
+ },
688
+ "execution_count": 13,
689
+ "metadata": {},
690
+ "output_type": "execute_result"
691
+ }
692
+ ],
693
+ "source": [
694
+ "class MindEyeModule(nn.Module):\n",
695
+ " def __init__(self):\n",
696
+ " super(MindEyeModule, self).__init__()\n",
697
+ " def forward(self, x):\n",
698
+ " return x\n",
699
+ " \n",
700
+ "model = MindEyeModule()\n",
701
+ "model"
702
+ ]
703
+ },
704
+ {
705
+ "cell_type": "code",
706
+ "execution_count": 14,
707
+ "id": "038a5d61-4769-40b9-a004-f4e7b5b38bb0",
708
+ "metadata": {
709
+ "tags": []
710
+ },
711
+ "outputs": [
712
+ {
713
+ "name": "stdout",
714
+ "output_type": "stream",
715
+ "text": [
716
+ "param counts:\n",
717
+ "16,102,400 total\n",
718
+ "16,102,400 trainable\n",
719
+ "param counts:\n",
720
+ "16,102,400 total\n",
721
+ "16,102,400 trainable\n",
722
+ "torch.Size([2, 1, 15724]) torch.Size([2, 1, 1024])\n"
723
+ ]
724
+ }
725
+ ],
726
+ "source": [
727
+ "class RidgeRegression(torch.nn.Module):\n",
728
+ " # make sure to add weight_decay when initializing optimizer to enable regularization\n",
729
+ " def __init__(self, input_sizes, out_features): \n",
730
+ " super(RidgeRegression, self).__init__()\n",
731
+ " self.out_features = out_features\n",
732
+ " self.linears = torch.nn.ModuleList([\n",
733
+ " torch.nn.Linear(input_size, out_features) for input_size in input_sizes\n",
734
+ " ])\n",
735
+ " def forward(self, x, subj_idx):\n",
736
+ " out = self.linears[subj_idx](x[:,0]).unsqueeze(1)\n",
737
+ " return out\n",
738
+ " \n",
739
+ "class IndividRidgeRegression(torch.nn.Module):\n",
740
+ " def __init__(self, input_size, out_features):\n",
741
+ " super(IndividRidgeRegression, self).__init__()\n",
742
+ " self.out_features = out_features\n",
743
+ " self.linear = torch.nn.Linear(input_size, out_features)\n",
744
+ " def forward(self, x):\n",
745
+ " out = self.linear(x)\n",
746
+ " return out\n",
747
+ " \n",
748
+ "model.ridge = RidgeRegression(num_voxels_list, out_features=hidden_dim)\n",
749
+ "utils.count_params(model.ridge)\n",
750
+ "utils.count_params(model)\n",
751
+ "\n",
752
+ "# test on subject 1 with fake data\n",
753
+ "b = torch.randn((2,1,num_voxels_list[0]))\n",
754
+ "print(b.shape, model.ridge(b,0).shape)"
755
+ ]
756
+ },
757
+ {
758
+ "cell_type": "code",
759
+ "execution_count": 15,
760
+ "id": "7b8de65a-6d3b-4248-bea9-9b6f4d562321",
761
+ "metadata": {
762
+ "tags": []
763
+ },
764
+ "outputs": [
765
+ {
766
+ "name": "stdout",
767
+ "output_type": "stream",
768
+ "text": [
769
+ "param counts:\n",
770
+ "453,360,280 total\n",
771
+ "453,360,280 trainable\n",
772
+ "param counts:\n",
773
+ "469,462,680 total\n",
774
+ "469,462,680 trainable\n",
775
+ "b.shape torch.Size([2, 1, 1024])\n",
776
+ "torch.Size([2, 256, 1664]) torch.Size([2, 256, 1664]) torch.Size([1]) torch.Size([1])\n"
777
+ ]
778
+ }
779
+ ],
780
+ "source": [
781
+ "from models import BrainNetwork\n",
782
+ "model.backbone = BrainNetwork(h=hidden_dim, in_dim=hidden_dim, seq_len=1, n_blocks=n_blocks,\n",
783
+ " clip_size=clip_emb_dim, out_dim=clip_emb_dim*clip_seq_dim, \n",
784
+ " blurry_recon=blurry_recon, clip_scale=clip_scale)\n",
785
+ "utils.count_params(model.backbone)\n",
786
+ "utils.count_params(model)\n",
787
+ "\n",
788
+ "# test that the model works on some fake data\n",
789
+ "b = torch.randn((2,1,hidden_dim))\n",
790
+ "print(\"b.shape\",b.shape)\n",
791
+ "\n",
792
+ "backbone_, clip_, blur_ = model.backbone(b)\n",
793
+ "print(backbone_.shape, clip_.shape, blur_[0].shape, blur_[1].shape)"
794
+ ]
795
+ },
796
+ {
797
+ "cell_type": "markdown",
798
+ "id": "e63b26a9-3a36-4638-be3c-dbf28705dd76",
799
+ "metadata": {},
800
+ "source": [
801
+ "### Load semantic clusters"
802
+ ]
803
+ },
804
+ {
805
+ "cell_type": "code",
806
+ "execution_count": 16,
807
+ "id": "2950add9-3828-4d55-bbf7-0d9f3519de5c",
808
+ "metadata": {},
809
+ "outputs": [
810
+ {
811
+ "name": "stdout",
812
+ "output_type": "stream",
813
+ "text": [
814
+ "semantic_cluster_onehot.shape torch.Size([73000, 41])\n",
815
+ "num_seman_clusters 41\n"
816
+ ]
817
+ }
818
+ ],
819
+ "source": [
820
+ "path_semantic_names = \"/weka/proj-medarc/shared/mindeyev2_dataset/semantic_cluster_names.npy\"\n",
821
+ "path_semantic_cluster = \"/weka/proj-fmri/ckadirt/MindEyeV2/src/COCO_73k_semantic_cluster.npy\"\n",
822
+ "semantic_cluster_names = np.load(path_semantic_names)\n",
823
+ "semantic_cluster = np.load(path_semantic_cluster)\n",
824
+ "possible_semantic_clusters = np.unique(semantic_cluster)\n",
825
+ "\n",
826
+ "# one-hot encode semantic clusters\n",
827
+ "# move possible_semantic_clusters to numbers and create a dictionary\n",
828
+ "semantic_cluster_dict = {cluster: i for i, cluster in enumerate(possible_semantic_clusters)}\n",
829
+ "semantic_cluster_onehot = torch.zeros((len(semantic_cluster), len(possible_semantic_clusters)))\n",
830
+ "for i, cluster in enumerate(semantic_cluster):\n",
831
+ " semantic_cluster_onehot[i, semantic_cluster_dict[cluster]] = 1\n",
832
+ "\n",
833
+ "\n",
834
+ "print(\"semantic_cluster_onehot.shape\", semantic_cluster_onehot.shape)\n",
835
+ "\n",
836
+ "num_seman_clusters = len(np.unique(semantic_cluster))\n",
837
+ "print(\"num_seman_clusters\", num_seman_clusters)"
838
+ ]
839
+ },
840
+ {
841
+ "cell_type": "markdown",
842
+ "id": "b397c0d7-52a3-4153-823b-c27d2eb3eeba",
843
+ "metadata": {},
844
+ "source": [
845
+ "### Adding the ridge regression to the class"
846
+ ]
847
+ },
848
+ {
849
+ "cell_type": "code",
850
+ "execution_count": 17,
851
+ "id": "69965344-9346-4592-9cc5-e537e31d5fce",
852
+ "metadata": {
853
+ "tags": []
854
+ },
855
+ "outputs": [
856
+ {
857
+ "name": "stdout",
858
+ "output_type": "stream",
859
+ "text": [
860
+ "param counts:\n",
861
+ "17,465,385 total\n",
862
+ "17,465,385 trainable\n",
863
+ "param counts:\n",
864
+ "486,928,065 total\n",
865
+ "486,928,065 trainable\n"
866
+ ]
867
+ },
868
+ {
869
+ "data": {
870
+ "text/plain": [
871
+ "486928065"
872
+ ]
873
+ },
874
+ "execution_count": 17,
875
+ "metadata": {},
876
+ "output_type": "execute_result"
877
+ }
878
+ ],
879
+ "source": [
880
+ "# if use_prior:\n",
881
+ "# from models import *\n",
882
+ "\n",
883
+ "# # setup diffusion prior network\n",
884
+ "# out_dim = clip_emb_dim\n",
885
+ "# depth = 6\n",
886
+ "# dim_head = 52\n",
887
+ "# heads = clip_emb_dim//52 # heads * dim_head = clip_emb_dim\n",
888
+ "# timesteps = 100\n",
889
+ "\n",
890
+ "# prior_network = PriorNetwork(\n",
891
+ "# dim=out_dim,\n",
892
+ "# depth=depth,\n",
893
+ "# dim_head=dim_head,\n",
894
+ "# heads=heads,\n",
895
+ "# causal=False,\n",
896
+ "# num_tokens = clip_seq_dim,\n",
897
+ "# learned_query_mode=\"pos_emb\"\n",
898
+ "# )\n",
899
+ "\n",
900
+ "# model.diffusion_prior = BrainDiffusionPrior(\n",
901
+ "# net=prior_network,\n",
902
+ "# image_embed_dim=out_dim,\n",
903
+ "# condition_on_text_encodings=False,\n",
904
+ "# timesteps=timesteps,\n",
905
+ "# cond_drop_prob=0.2,\n",
906
+ "# image_embed_scale=None,\n",
907
+ "# )\n",
908
+ " \n",
909
+ "# utils.count_params(model.diffusion_prior)\n",
910
+ "# utils.count_params(model)\n",
911
+ "\n",
912
+ "model.RRClassifier = IndividRidgeRegression(clip_emb_dim*clip_seq_dim, out_features=num_seman_clusters)\n",
913
+ "utils.count_params(model.RRClassifier)\n",
914
+ "utils.count_params(model)"
915
+ ]
916
+ },
917
+ {
918
+ "cell_type": "markdown",
919
+ "id": "ec25271a-2209-400c-8026-df3b8ddc1eef",
920
+ "metadata": {},
921
+ "source": [
922
+ "### Setup optimizer / lr / ckpt saving"
923
+ ]
924
+ },
925
+ {
926
+ "cell_type": "code",
927
+ "execution_count": 18,
928
+ "id": "e14d0482-dc42-43b9-9ce1-953c32f2c9c1",
929
+ "metadata": {
930
+ "tags": []
931
+ },
932
+ "outputs": [
933
+ {
934
+ "name": "stdout",
935
+ "output_type": "stream",
936
+ "text": [
937
+ "total_steps 281250\n",
938
+ "\n",
939
+ "Done with model preparations!\n",
940
+ "param counts:\n",
941
+ "486,928,065 total\n",
942
+ "486,928,065 trainable\n"
943
+ ]
944
+ }
945
+ ],
946
+ "source": [
947
+ "no_decay = ['bias', 'LayerNorm.bias', 'LayerNorm.weight']\n",
948
+ "\n",
949
+ "opt_grouped_parameters = [\n",
950
+ " {'params': [p for n, p in model.ridge.named_parameters()], 'weight_decay': 1e-2},\n",
951
+ " {'params': [p for n, p in model.backbone.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},\n",
952
+ " {'params': [p for n, p in model.backbone.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0},\n",
953
+ " {'params': [p for n, p in model.RRClassifier.named_parameters()], 'weight_decay': 1e-2},\n",
954
+ "]\n",
955
+ "# if use_prior:\n",
956
+ "# opt_grouped_parameters.extend([\n",
957
+ "# {'params': [p for n, p in model.diffusion_prior.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},\n",
958
+ "# {'params': [p for n, p in model.diffusion_prior.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0}\n",
959
+ "# ])\n",
960
+ "# opt_grouped_parameters.extend([\n",
961
+ "# \n",
962
+ "# ])\n",
963
+ "\n",
964
+ "optimizer = torch.optim.AdamW(opt_grouped_parameters, lr=max_lr)\n",
965
+ "\n",
966
+ "if lr_scheduler_type == 'linear':\n",
967
+ " lr_scheduler = torch.optim.lr_scheduler.LinearLR(\n",
968
+ " optimizer,\n",
969
+ " total_iters=int(np.floor(num_epochs*num_iterations_per_epoch)),\n",
970
+ " last_epoch=-1\n",
971
+ " )\n",
972
+ "elif lr_scheduler_type == 'cycle':\n",
973
+ " total_steps=int(np.floor(num_epochs*num_iterations_per_epoch))\n",
974
+ " print(\"total_steps\", total_steps)\n",
975
+ " lr_scheduler = torch.optim.lr_scheduler.OneCycleLR(\n",
976
+ " optimizer, \n",
977
+ " max_lr=max_lr,\n",
978
+ " total_steps=total_steps,\n",
979
+ " final_div_factor=1000,\n",
980
+ " last_epoch=-1, pct_start=2/num_epochs\n",
981
+ " )\n",
982
+ " \n",
983
+ "def save_ckpt(tag):\n",
984
+ " ckpt_path = outdir+f'/{tag}.pth'\n",
985
+ " if accelerator.is_main_process:\n",
986
+ " unwrapped_model = accelerator.unwrap_model(model)\n",
987
+ " torch.save({\n",
988
+ " 'epoch': epoch,\n",
989
+ " 'model_state_dict': unwrapped_model.state_dict(),\n",
990
+ " 'optimizer_state_dict': optimizer.state_dict(),\n",
991
+ " 'lr_scheduler': lr_scheduler.state_dict(),\n",
992
+ " 'train_losses': losses,\n",
993
+ " 'test_losses': test_losses,\n",
994
+ " 'lrs': lrs,\n",
995
+ " }, ckpt_path)\n",
996
+ " print(f\"\\n---saved {outdir}/{tag} ckpt!---\\n\")\n",
997
+ "\n",
998
+ "def load_ckpt(tag,load_lr=True,load_optimizer=True,load_epoch=True,strict=True,outdir=outdir,multisubj_loading=False): \n",
999
+ " print(f\"\\n---loading {outdir}/{tag}.pth ckpt---\\n\")\n",
1000
+ " checkpoint = torch.load(outdir+'/last.pth', map_location='cpu')\n",
1001
+ " state_dict = checkpoint['model_state_dict']\n",
1002
+ " if multisubj_loading: # remove incompatible ridge layer that will otherwise error\n",
1003
+ " state_dict.pop('ridge.linears.0.weight',None)\n",
1004
+ " model.load_state_dict(state_dict, strict=strict)\n",
1005
+ " if load_epoch:\n",
1006
+ " globals()[\"epoch\"] = checkpoint['epoch']\n",
1007
+ " print(\"Epoch\",epoch)\n",
1008
+ " if load_optimizer:\n",
1009
+ " optimizer.load_state_dict(checkpoint['optimizer_state_dict'])\n",
1010
+ " if load_lr:\n",
1011
+ " lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])\n",
1012
+ " del checkpoint\n",
1013
+ "\n",
1014
+ "print(\"\\nDone with model preparations!\")\n",
1015
+ "num_params = utils.count_params(model)"
1016
+ ]
1017
+ },
1018
+ {
1019
+ "cell_type": "markdown",
1020
+ "id": "983f458b-35b8-49f2-b6db-80296cece730",
1021
+ "metadata": {},
1022
+ "source": [
1023
+ "# Weights and Biases"
1024
+ ]
1025
+ },
1026
+ {
1027
+ "cell_type": "code",
1028
+ "execution_count": 19,
1029
+ "id": "0a25a662-daa8-4de9-9233-8364800fcb6b",
1030
+ "metadata": {
1031
+ "tags": []
1032
+ },
1033
+ "outputs": [
1034
+ {
1035
+ "name": "stdout",
1036
+ "output_type": "stream",
1037
+ "text": [
1038
+ "wandb mindeye_semantic_cluster run testing-tt3\n",
1039
+ "wandb_config:\n",
1040
+ " {'model_name': 'testing-tt3', 'global_batch_size': 16, 'batch_size': 16, 'num_epochs': 150, 'num_sessions': 40, 'num_params': 486928065, 'clip_scale': 1.0, 'prior_scale': 30.0, 'blur_scale': 0.5, 'use_image_aug': False, 'max_lr': 1e-05, 'mixup_pct': 0.33, 'num_samples_per_epoch': 30000, 'num_test': 3000, 'ckpt_interval': 999, 'ckpt_saving': False, 'seed': 42, 'distributed': False, 'num_devices': 1, 'world_size': 1, 'train_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/train/{0..39}.tar', 'test_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/new_test/0.tar'}\n",
1041
+ "wandb_id: testing-tt3\n"
1042
+ ]
1043
+ },
1044
+ {
1045
+ "name": "stderr",
1046
+ "output_type": "stream",
1047
+ "text": [
1048
+ "\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mckadirt\u001b[0m. Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n"
1049
+ ]
1050
+ },
1051
+ {
1052
+ "data": {
1053
+ "text/html": [
1054
+ "wandb version 0.17.4 is available! To upgrade, please run:\n",
1055
+ " $ pip install wandb --upgrade"
1056
+ ],
1057
+ "text/plain": [
1058
+ "<IPython.core.display.HTML object>"
1059
+ ]
1060
+ },
1061
+ "metadata": {},
1062
+ "output_type": "display_data"
1063
+ },
1064
+ {
1065
+ "data": {
1066
+ "text/html": [
1067
+ "Tracking run with wandb version 0.17.1"
1068
+ ],
1069
+ "text/plain": [
1070
+ "<IPython.core.display.HTML object>"
1071
+ ]
1072
+ },
1073
+ "metadata": {},
1074
+ "output_type": "display_data"
1075
+ },
1076
+ {
1077
+ "data": {
1078
+ "text/html": [
1079
+ "Run data is saved locally in <code>/weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240709_011732-testing-tt3</code>"
1080
+ ],
1081
+ "text/plain": [
1082
+ "<IPython.core.display.HTML object>"
1083
+ ]
1084
+ },
1085
+ "metadata": {},
1086
+ "output_type": "display_data"
1087
+ },
1088
+ {
1089
+ "data": {
1090
+ "text/html": [
1091
+ "Syncing run <strong><a href='https://stability.wandb.io/ckadirt/mindeye_semantic_cluster/runs/testing-tt3' target=\"_blank\">testing-tt3</a></strong> to <a href='https://stability.wandb.io/ckadirt/mindeye_semantic_cluster' target=\"_blank\">Weights & Biases</a> (<a href='https://wandb.me/run' target=\"_blank\">docs</a>)<br/>"
1092
+ ],
1093
+ "text/plain": [
1094
+ "<IPython.core.display.HTML object>"
1095
+ ]
1096
+ },
1097
+ "metadata": {},
1098
+ "output_type": "display_data"
1099
+ },
1100
+ {
1101
+ "data": {
1102
+ "text/html": [
1103
+ " View project at <a href='https://stability.wandb.io/ckadirt/mindeye_semantic_cluster' target=\"_blank\">https://stability.wandb.io/ckadirt/mindeye_semantic_cluster</a>"
1104
+ ],
1105
+ "text/plain": [
1106
+ "<IPython.core.display.HTML object>"
1107
+ ]
1108
+ },
1109
+ "metadata": {},
1110
+ "output_type": "display_data"
1111
+ },
1112
+ {
1113
+ "data": {
1114
+ "text/html": [
1115
+ " View run at <a href='https://stability.wandb.io/ckadirt/mindeye_semantic_cluster/runs/testing-tt3' target=\"_blank\">https://stability.wandb.io/ckadirt/mindeye_semantic_cluster/runs/testing-tt3</a>"
1116
+ ],
1117
+ "text/plain": [
1118
+ "<IPython.core.display.HTML object>"
1119
+ ]
1120
+ },
1121
+ "metadata": {},
1122
+ "output_type": "display_data"
1123
+ }
1124
+ ],
1125
+ "source": [
1126
+ "if local_rank==0 and wandb_log: # only use main process for wandb logging\n",
1127
+ " import wandb\n",
1128
+ " wandb_project = 'mindeye_semantic_cluster'\n",
1129
+ " print(f\"wandb {wandb_project} run {model_name}\")\n",
1130
+ " # need to configure wandb beforehand in terminal with \"wandb init\"!\n",
1131
+ " wandb_config = {\n",
1132
+ " \"model_name\": model_name,\n",
1133
+ " \"global_batch_size\": global_batch_size,\n",
1134
+ " \"batch_size\": batch_size,\n",
1135
+ " \"num_epochs\": num_epochs,\n",
1136
+ " \"num_sessions\": num_sessions,\n",
1137
+ " \"num_params\": num_params,\n",
1138
+ " \"clip_scale\": clip_scale,\n",
1139
+ " \"prior_scale\": prior_scale,\n",
1140
+ " \"blur_scale\": blur_scale,\n",
1141
+ " \"use_image_aug\": use_image_aug,\n",
1142
+ " \"max_lr\": max_lr,\n",
1143
+ " \"mixup_pct\": mixup_pct,\n",
1144
+ " \"num_samples_per_epoch\": num_samples_per_epoch,\n",
1145
+ " \"num_test\": num_test,\n",
1146
+ " \"ckpt_interval\": ckpt_interval,\n",
1147
+ " \"ckpt_saving\": ckpt_saving,\n",
1148
+ " \"seed\": seed,\n",
1149
+ " \"distributed\": distributed,\n",
1150
+ " \"num_devices\": num_devices,\n",
1151
+ " \"world_size\": world_size,\n",
1152
+ " \"train_url\": train_url,\n",
1153
+ " \"test_url\": test_url,\n",
1154
+ " }\n",
1155
+ " print(\"wandb_config:\\n\",wandb_config)\n",
1156
+ " print(\"wandb_id:\",model_name)\n",
1157
+ " wandb.login(host='https://stability.wandb.io')\n",
1158
+ " wandb.init(\n",
1159
+ " id=model_name,\n",
1160
+ " project=wandb_project,\n",
1161
+ " name=model_name,\n",
1162
+ " config=wandb_config,\n",
1163
+ " resume=\"allow\",\n",
1164
+ " )\n",
1165
+ "else:\n",
1166
+ " wandb_log = False"
1167
+ ]
1168
+ },
1169
+ {
1170
+ "cell_type": "markdown",
1171
+ "id": "d5690151-2131-4918-b750-e869cbd1a8a8",
1172
+ "metadata": {},
1173
+ "source": [
1174
+ "# Main"
1175
+ ]
1176
+ },
1177
+ {
1178
+ "cell_type": "code",
1179
+ "execution_count": 20,
1180
+ "id": "12de6387-6e18-4e4b-b5ce-a847d625330a",
1181
+ "metadata": {
1182
+ "tags": []
1183
+ },
1184
+ "outputs": [],
1185
+ "source": [
1186
+ "epoch = 0\n",
1187
+ "losses, test_losses, lrs = [], [], []\n",
1188
+ "best_test_loss = 1e9\n",
1189
+ "torch.cuda.empty_cache()"
1190
+ ]
1191
+ },
1192
+ {
1193
+ "cell_type": "code",
1194
+ "execution_count": 21,
1195
+ "id": "607a7c7b-fe5e-41a4-80bf-d2814b3a57cc",
1196
+ "metadata": {
1197
+ "tags": []
1198
+ },
1199
+ "outputs": [],
1200
+ "source": [
1201
+ "# load multisubject stage1 ckpt if set\n",
1202
+ "if multisubject_ckpt is not None:\n",
1203
+ " load_ckpt(\"last\",outdir=multisubject_ckpt,load_lr=False,load_optimizer=False,load_epoch=False,strict=False,multisubj_loading=True)"
1204
+ ]
1205
+ },
1206
+ {
1207
+ "cell_type": "code",
1208
+ "execution_count": 22,
1209
+ "id": "99f09f76-4481-4133-b09a-a22b10dbc0c4",
1210
+ "metadata": {
1211
+ "tags": []
1212
+ },
1213
+ "outputs": [],
1214
+ "source": [
1215
+ "train_dls = [train_dl[f'subj0{s}'] for s in subj_list]\n",
1216
+ "\n",
1217
+ "model, optimizer, *train_dls, lr_scheduler, semantic_cluster_onehot = accelerator.prepare(model, optimizer, *train_dls, lr_scheduler, semantic_cluster_onehot)\n",
1218
+ "# leaving out test_dl since we will only have local_rank 0 device do evals"
1219
+ ]
1220
+ },
1221
+ {
1222
+ "cell_type": "code",
1223
+ "execution_count": 23,
1224
+ "id": "e16fa583-064c-4cfa-9f47-08d08f53f504",
1225
+ "metadata": {},
1226
+ "outputs": [
1227
+ {
1228
+ "name": "stdout",
1229
+ "output_type": "stream",
1230
+ "text": [
1231
+ "1875\n"
1232
+ ]
1233
+ }
1234
+ ],
1235
+ "source": [
1236
+ "print(num_iterations_per_epoch)"
1237
+ ]
1238
+ },
1239
+ {
1240
+ "cell_type": "code",
1241
+ "execution_count": 28,
1242
+ "id": "60be0d5f-3e94-4612-9373-61b53d836393",
1243
+ "metadata": {
1244
+ "tags": []
1245
+ },
1246
+ "outputs": [
1247
+ {
1248
+ "name": "stdout",
1249
+ "output_type": "stream",
1250
+ "text": [
1251
+ "testing-tt3 starting with epoch 4 / 150\n"
1252
+ ]
1253
+ },
1254
+ {
1255
+ "name": "stderr",
1256
+ "output_type": "stream",
1257
+ "text": [
1258
+ " 0%| | 0/146 [00:00<?, ?it/s]"
1259
+ ]
1260
+ },
1261
+ {
1262
+ "name": "stdout",
1263
+ "output_type": "stream",
1264
+ "text": [
1265
+ "torch.Size([16, 256, 1664])\n",
1266
+ "torch.Size([16, 41])\n",
1267
+ "['photo of tennis' 'photo of bedroom' 'photo of surfer'\n",
1268
+ " 'photo of group of people' 'photo of cat' 'photo of vehicle'\n",
1269
+ " 'photo of baseball' 'photo of bird' 'photo of train'\n",
1270
+ " 'photo of group of people' 'photo of umbrella' 'photo of food'\n",
1271
+ " 'photo of giraffe' 'photo of clocktower' 'photo of food'\n",
1272
+ " 'photo of sports']\n",
1273
+ "tensor([35., 5., 33., 20., 10., 39., 2., 7., 37., 20., 38., 17., 19., 11.,\n",
1274
+ " 17., 31.])\n",
1275
+ "torch.Size([16, 256, 1664])\n",
1276
+ "torch.Size([16, 41])\n",
1277
+ "['photo of food' 'photo of clocktower' 'photo of bedroom'\n",
1278
+ " 'photo of baseball' 'photo of group of people' 'photo of umbrella'\n",
1279
+ " 'photo of surfer' 'photo of food' 'photo of train' 'photo of bird'\n",
1280
+ " 'photo of tennis' 'photo of sports' 'photo of group of people'\n",
1281
+ " 'photo of cat' 'photo of vehicle' 'photo of giraffe']\n",
1282
+ "tensor([17., 11., 5., 2., 20., 38., 33., 17., 37., 7., 35., 31., 20., 10.,\n",
1283
+ " 39., 19.])\n",
1284
+ "torch.Size([16, 256, 1664])\n",
1285
+ "torch.Size([16, 41])\n",
1286
+ "['photo of bedroom' 'photo of tennis' 'photo of clocktower'\n",
1287
+ " 'photo of umbrella' 'photo of group of people' 'photo of group of people'\n",
1288
+ " 'photo of surfer' 'photo of food' 'photo of giraffe' 'photo of cat'\n",
1289
+ " 'photo of bird' 'photo of food' 'photo of train' 'photo of sports'\n",
1290
+ " 'photo of vehicle' 'photo of baseball']\n",
1291
+ "tensor([ 5., 35., 11., 38., 20., 20., 33., 17., 19., 10., 7., 17., 37., 31.,\n",
1292
+ " 39., 2.])\n",
1293
+ "torch.Size([16, 256, 1664])\n",
1294
+ "torch.Size([16, 41])\n",
1295
+ "['photo of surfer' 'photo of food' 'photo of umbrella' 'photo of tennis'\n",
1296
+ " 'photo of bird' 'photo of train' 'photo of group of people'\n",
1297
+ " 'photo of group of people' 'photo of clocktower' 'photo of sports'\n",
1298
+ " 'photo of cat' 'photo of vehicle' 'photo of giraffe' 'photo of bedroom'\n",
1299
+ " 'photo of food' 'photo of baseball']\n",
1300
+ "tensor([33., 17., 38., 35., 7., 37., 20., 20., 11., 31., 10., 39., 19., 5.,\n",
1301
+ " 17., 2.])\n",
1302
+ "torch.Size([16, 256, 1664])\n",
1303
+ "torch.Size([16, 41])\n",
1304
+ "['photo of food' 'photo of clocktower' 'photo of bedroom'\n",
1305
+ " 'photo of baseball' 'photo of tennis' 'photo of giraffe'\n",
1306
+ " 'photo of vehicle' 'photo of group of people' 'photo of group of people'\n",
1307
+ " 'photo of cat' 'photo of food' 'photo of umbrella' 'photo of sports'\n",
1308
+ " 'photo of train' 'photo of bird' 'photo of surfer']\n",
1309
+ "tensor([17., 11., 5., 2., 35., 19., 39., 20., 20., 10., 17., 38., 31., 37.,\n",
1310
+ " 7., 33.])\n",
1311
+ "torch.Size([16, 256, 1664])\n",
1312
+ "torch.Size([16, 41])\n",
1313
+ "['photo of giraffe' 'photo of food' 'photo of baseball'\n",
1314
+ " 'photo of clocktower' 'photo of cat' 'photo of vehicle'\n",
1315
+ " 'photo of bedroom' 'photo of sports' 'photo of surfer'\n",
1316
+ " 'photo of group of people' 'photo of tennis' 'photo of food'\n",
1317
+ " 'photo of umbrella' 'photo of bird' 'photo of group of people'\n",
1318
+ " 'photo of train']\n",
1319
+ "tensor([19., 17., 2., 11., 10., 39., 5., 31., 33., 20., 35., 17., 38., 7.,\n",
1320
+ " 20., 37.])\n",
1321
+ "torch.Size([16, 256, 1664])\n",
1322
+ "torch.Size([16, 41])\n",
1323
+ "['photo of group of people' 'photo of baseball' 'photo of group of people'\n",
1324
+ " 'photo of bird' 'photo of train' 'photo of food' 'photo of vehicle'\n",
1325
+ " 'photo of cat' 'photo of sports' 'photo of giraffe' 'photo of surfer'\n",
1326
+ " 'photo of umbrella' 'photo of food' 'photo of tennis'\n",
1327
+ " 'photo of clocktower' 'photo of bedroom']\n",
1328
+ "tensor([20., 2., 20., 7., 37., 17., 39., 10., 31., 19., 33., 38., 17., 35.,\n",
1329
+ " 11., 5.])\n",
1330
+ "torch.Size([16, 256, 1664])\n",
1331
+ "torch.Size([16, 41])\n",
1332
+ "['photo of clocktower' 'photo of group of people' 'photo of bedroom'\n",
1333
+ " 'photo of giraffe' 'photo of surfer' 'photo of vehicle' 'photo of cat'\n",
1334
+ " 'photo of tennis' 'photo of food' 'photo of group of people'\n",
1335
+ " 'photo of train' 'photo of bird' 'photo of sports' 'photo of baseball'\n",
1336
+ " 'photo of umbrella' 'photo of food']\n",
1337
+ "tensor([11., 20., 5., 19., 33., 39., 10., 35., 17., 20., 37., 7., 31., 2.,\n",
1338
+ " 38., 17.])\n"
1339
+ ]
1340
+ },
1341
+ {
1342
+ "name": "stderr",
1343
+ "output_type": "stream",
1344
+ "text": [
1345
+ " 0%| | 0/146 [00:34<?, ?it/s]"
1346
+ ]
1347
+ },
1348
+ {
1349
+ "name": "stdout",
1350
+ "output_type": "stream",
1351
+ "text": [
1352
+ "torch.Size([16, 256, 1664])\n",
1353
+ "torch.Size([16, 41])\n",
1354
+ "['photo of vehicle' 'photo of surfer' 'photo of tennis'\n",
1355
+ " 'photo of group of people' 'photo of food' 'photo of group of people'\n",
1356
+ " 'photo of sports' 'photo of food' 'photo of giraffe' 'photo of baseball'\n",
1357
+ " 'photo of umbrella' 'photo of cat' 'photo of bedroom'\n",
1358
+ " 'photo of clocktower' 'photo of train' 'photo of bird']\n",
1359
+ "tensor([39., 33., 35., 20., 17., 20., 31., 17., 19., 2., 38., 10., 5., 11.,\n",
1360
+ " 37., 7.])\n",
1361
+ "torch.Size([16, 256, 1664])\n",
1362
+ "torch.Size([16, 41])\n",
1363
+ "['photo of cat' 'photo of baseball' 'photo of vehicle' 'photo of sports'\n",
1364
+ " 'photo of bird' 'photo of surfer' 'photo of food' 'photo of food'\n",
1365
+ " 'photo of clocktower' 'photo of umbrella' 'photo of group of people'\n",
1366
+ " 'photo of bedroom' 'photo of train' 'photo of tennis' 'photo of giraffe'\n",
1367
+ " 'photo of group of people']\n",
1368
+ "tensor([10., 2., 39., 31., 7., 33., 17., 17., 11., 38., 20., 5., 37., 35.,\n",
1369
+ " 19., 20.])\n"
1370
+ ]
1371
+ },
1372
+ {
1373
+ "name": "stderr",
1374
+ "output_type": "stream",
1375
+ "text": [
1376
+ "\n"
1377
+ ]
1378
+ },
1379
+ {
1380
+ "ename": "KeyboardInterrupt",
1381
+ "evalue": "",
1382
+ "output_type": "error",
1383
+ "traceback": [
1384
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1385
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
1386
+ "Cell \u001b[0;32mIn[28], line 90\u001b[0m\n\u001b[1;32m 88\u001b[0m voxel_list \u001b[38;5;241m=\u001b[39m [voxel_iters[\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msubj0\u001b[39m\u001b[38;5;132;01m{\u001b[39;00ms\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m_iter\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mtrain_i\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mdetach()\u001b[38;5;241m.\u001b[39mto(device) \u001b[38;5;28;01mfor\u001b[39;00m s \u001b[38;5;129;01min\u001b[39;00m subj_list]\n\u001b[1;32m 89\u001b[0m image \u001b[38;5;241m=\u001b[39m image_iters[train_i]\u001b[38;5;241m.\u001b[39mdetach()\n\u001b[0;32m---> 90\u001b[0m image \u001b[38;5;241m=\u001b[39m \u001b[43mimage\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdevice\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 92\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m use_image_aug: \n\u001b[1;32m 93\u001b[0m image \u001b[38;5;241m=\u001b[39m img_augment(image)\n",
1387
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
1388
+ ]
1389
+ }
1390
+ ],
1391
+ "source": [
1392
+ "print(f\"{model_name} starting with epoch {epoch} / {num_epochs}\")\n",
1393
+ "progress_bar = tqdm(range(epoch,num_epochs), ncols=1200, disable=(local_rank!=0))\n",
1394
+ "test_image, test_voxel = None, None\n",
1395
+ "mse = nn.MSELoss()\n",
1396
+ "l1 = nn.L1Loss()\n",
1397
+ "soft_loss_temps = utils.cosine_anneal(0.004, 0.0075, num_epochs - int(mixup_pct * num_epochs))\n",
1398
+ "\n",
1399
+ "for epoch in progress_bar:\n",
1400
+ " model.train()\n",
1401
+ "\n",
1402
+ " fwd_percent_correct = 0.\n",
1403
+ " bwd_percent_correct = 0.\n",
1404
+ " test_fwd_percent_correct = 0.\n",
1405
+ " test_bwd_percent_correct = 0.\n",
1406
+ " \n",
1407
+ " recon_cossim = 0.\n",
1408
+ " test_recon_cossim = 0.\n",
1409
+ " recon_mse = 0.\n",
1410
+ " test_recon_mse = 0.\n",
1411
+ "\n",
1412
+ " loss_clip_total = 0.\n",
1413
+ " loss_blurry_total = 0.\n",
1414
+ " loss_blurry_cont_total = 0.\n",
1415
+ " test_loss_clip_total = 0.\n",
1416
+ " \n",
1417
+ " loss_prior_total = 0.\n",
1418
+ " test_loss_prior_total = 0.\n",
1419
+ " \n",
1420
+ " loss_RR_total = 0.\n",
1421
+ " test_loss_RR_total = 0.\n",
1422
+ "\n",
1423
+ " blurry_pixcorr = 0.\n",
1424
+ " test_blurry_pixcorr = 0. # needs >.456 to beat low-level subj01 results in mindeye v1\n",
1425
+ "\n",
1426
+ " class_precisions_1 = 0\n",
1427
+ " test_class_precisions_1 = 0\n",
1428
+ "\n",
1429
+ " class_precisions_5 = 0\n",
1430
+ " test_class_precisions_5 = 0\n",
1431
+ "\n",
1432
+ " class_precisions_10 = 0\n",
1433
+ " test_class_precisions_10 = 0\n",
1434
+ "\n",
1435
+ " # pre-load all batches for this epoch (it's MUCH faster to pre-load in bulk than to separate loading per batch)\n",
1436
+ " voxel_iters = {} # empty dict because diff subjects have differing # of voxels\n",
1437
+ " image_iters = torch.zeros(num_iterations_per_epoch, batch_size*len(subj_list), 3, 224, 224).float()\n",
1438
+ " annot_iters = {}\n",
1439
+ " perm_iters, betas_iters, select_iters = {}, {}, {}\n",
1440
+ " images_indexes = {}\n",
1441
+ " for s, train_dl in enumerate(train_dls):\n",
1442
+ " with torch.cuda.amp.autocast(dtype=data_type):\n",
1443
+ " iter = -1\n",
1444
+ " for behav0, past_behav0, future_behav0, old_behav0 in train_dl: \n",
1445
+ " # Load images to cpu from hdf5 (requires sorted indexing)\n",
1446
+ " image_idx = behav0[:,0,0].cpu().long().numpy()\n",
1447
+ "\n",
1448
+ " image0, image_sorted_idx = np.unique(image_idx, return_index=True) \n",
1449
+ " if len(image0) != len(image_idx): # hdf5 cant handle duplicate indexing\n",
1450
+ " continue\n",
1451
+ " iter += 1\n",
1452
+ " image0 = torch.tensor(images[image0], dtype=data_type)\n",
1453
+ " image_iters[iter,s*batch_size:s*batch_size+batch_size] = image0\n",
1454
+ " images_indexes[f\"subj0{s}_iter{iter}\"] = image_sorted_idx\n",
1455
+ " \n",
1456
+ " # Load voxels for current batch, matching above indexing\n",
1457
+ " voxel_idx = behav0[:,0,5].cpu().long().numpy()\n",
1458
+ " voxel_sorted_idx = voxel_idx[image_sorted_idx]\n",
1459
+ " voxel0 = voxels[f'subj0{subj_list[s]}'][voxel_sorted_idx]\n",
1460
+ " voxel0 = torch.Tensor(voxel0).unsqueeze(1)\n",
1461
+ "\n",
1462
+ " if epoch < int(mixup_pct * num_epochs):\n",
1463
+ " voxel0, perm, betas, select = utils.mixco(voxel0)\n",
1464
+ " perm_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = perm\n",
1465
+ " betas_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = betas\n",
1466
+ " select_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = select\n",
1467
+ "\n",
1468
+ " voxel_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = voxel0\n",
1469
+ "\n",
1470
+ " if iter >= num_iterations_per_epoch-1:\n",
1471
+ " break\n",
1472
+ "\n",
1473
+ " # you now have voxel_iters and image_iters with num_iterations_per_epoch batches each\n",
1474
+ " for train_i in range(num_iterations_per_epoch):\n",
1475
+ " with torch.cuda.amp.autocast(dtype=data_type):\n",
1476
+ " optimizer.zero_grad()\n",
1477
+ " loss=0.\n",
1478
+ "\n",
1479
+ " voxel_list = [voxel_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1480
+ " image = image_iters[train_i].detach()\n",
1481
+ " image = image.to(device)\n",
1482
+ "\n",
1483
+ " if use_image_aug: \n",
1484
+ " image = img_augment(image)\n",
1485
+ "\n",
1486
+ " clip_target = clip_img_embedder(image)\n",
1487
+ " assert not torch.any(torch.isnan(clip_target))\n",
1488
+ "\n",
1489
+ " if epoch < int(mixup_pct * num_epochs):\n",
1490
+ " perm_list = [perm_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1491
+ " perm = torch.cat(perm_list, dim=0)\n",
1492
+ " betas_list = [betas_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1493
+ " betas = torch.cat(betas_list, dim=0)\n",
1494
+ " select_list = [select_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1495
+ " select = torch.cat(select_list, dim=0)\n",
1496
+ "\n",
1497
+ " voxel_ridge_list = [model.ridge(voxel_list[si],si) for si,s in enumerate(subj_list)]\n",
1498
+ " voxel_ridge = torch.cat(voxel_ridge_list, dim=0)\n",
1499
+ "\n",
1500
+ " backbone, clip_voxels, blurry_image_enc_ = model.backbone(voxel_ridge)\n",
1501
+ "\n",
1502
+ " if clip_scale>0:\n",
1503
+ " clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)\n",
1504
+ " clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)\n",
1505
+ "\n",
1506
+ " # if use_prior:\n",
1507
+ " # loss_prior, prior_out = model.diffusion_prior(text_embed=backbone, image_embed=clip_target)\n",
1508
+ " # loss_prior_total += loss_prior.item()\n",
1509
+ " # loss_prior *= prior_scale\n",
1510
+ " # loss += loss_prior\n",
1511
+ "\n",
1512
+ " # recon_cossim += nn.functional.cosine_similarity(prior_out, clip_target).mean().item()\n",
1513
+ " # recon_mse += mse(prior_out, clip_target).item()\n",
1514
+ " print(backbone.shape)\n",
1515
+ " logits = model.RRClassifier(backbone.flatten(1))\n",
1516
+ " print(logits.shape)\n",
1517
+ " print(semantic_cluster[images_indexes[f\"subj0{s}_iter{train_i}\"]])\n",
1518
+ " print(torch.Tensor([semantic_cluster_dict[i] for i in semantic_cluster[images_indexes[f\"subj0{s}_iter{train_i}\"]]]))\n",
1519
+ " #print(logits.shape, torch.argmax(semantic_cluster_onehot[images_indexes[f\"subj0{s}_iter{train_i}\"]], dim=1).shape)\n",
1520
+ " #print(logits, torch.argmax(semantic_cluster_onehot[images_indexes[f\"subj0{s}_iter{train_i}\"]], dim=1))\n",
1521
+ " loss_RR = nn.functional.cross_entropy(logits, torch.argmax(semantic_cluster_onehot[images_indexes[f\"subj0{s}_iter{train_i}\"]], dim=1).to(logits.device))\n",
1522
+ " #print(\"backbone.shape\",backbone.shape, \"clip_voxels.shape\",clip_voxels.shape, \"blurry_image_enc_[0].shape\",blurry_image_enc_[0].shape, \"blurry_image_enc_[1].shape\",blurry_image_enc_[1].shape)\n",
1523
+ " #something \n",
1524
+ "\n",
1525
+ " loss_RR_total += loss_RR.item()\n",
1526
+ " loss += loss_RR\n",
1527
+ "\n",
1528
+ " if (torch.rand(1) < 0.03).item():\n",
1529
+ " print(\"loss_RR\", loss_RR.item())\n",
1530
+ "\n",
1531
+ " if clip_scale>0:\n",
1532
+ " if epoch < int(mixup_pct * num_epochs): \n",
1533
+ " loss_clip = utils.mixco_nce(\n",
1534
+ " clip_voxels_norm,\n",
1535
+ " clip_target_norm,\n",
1536
+ " temp=.006,\n",
1537
+ " perm=perm, betas=betas, select=select)\n",
1538
+ " else:\n",
1539
+ " epoch_temp = soft_loss_temps[epoch-int(mixup_pct*num_epochs)]\n",
1540
+ " loss_clip = utils.soft_clip_loss(\n",
1541
+ " clip_voxels_norm,\n",
1542
+ " clip_target_norm,\n",
1543
+ " temp=epoch_temp)\n",
1544
+ "\n",
1545
+ " loss_clip_total += loss_clip.item()\n",
1546
+ " loss_clip *= clip_scale\n",
1547
+ " # loss += loss_clip\n",
1548
+ "\n",
1549
+ " if blurry_recon: \n",
1550
+ " image_enc_pred, transformer_feats = blurry_image_enc_\n",
1551
+ "\n",
1552
+ " image_enc = autoenc.encode(2*image-1).latent_dist.mode() * 0.18215\n",
1553
+ " loss_blurry = l1(image_enc_pred, image_enc)\n",
1554
+ " loss_blurry_total += loss_blurry.item()\n",
1555
+ "\n",
1556
+ " if epoch < int(mixup_pct * num_epochs):\n",
1557
+ " image_enc_shuf = image_enc[perm]\n",
1558
+ " betas_shape = [-1] + [1]*(len(image_enc.shape)-1)\n",
1559
+ " image_enc[select] = image_enc[select] * betas[select].reshape(*betas_shape) + \\\n",
1560
+ " image_enc_shuf[select] * (1 - betas[select]).reshape(*betas_shape)\n",
1561
+ "\n",
1562
+ " image_norm = (image - mean)/std\n",
1563
+ " image_aug = (blur_augs(image) - mean)/std\n",
1564
+ " _, cnx_embeds = cnx(image_norm)\n",
1565
+ " _, cnx_aug_embeds = cnx(image_aug)\n",
1566
+ "\n",
1567
+ " cont_loss = utils.soft_cont_loss(\n",
1568
+ " nn.functional.normalize(transformer_feats.reshape(-1, transformer_feats.shape[-1]), dim=-1),\n",
1569
+ " nn.functional.normalize(cnx_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),\n",
1570
+ " nn.functional.normalize(cnx_aug_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),\n",
1571
+ " temp=0.2)\n",
1572
+ " loss_blurry_cont_total += cont_loss.item()\n",
1573
+ "\n",
1574
+ " # loss += (loss_blurry + 0.1*cont_loss) * blur_scale #/.18215\n",
1575
+ "\n",
1576
+ " if clip_scale>0:\n",
1577
+ " # forward and backward top 1 accuracy \n",
1578
+ " labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device) \n",
1579
+ " fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()\n",
1580
+ " bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()\n",
1581
+ "\n",
1582
+ " if blurry_recon:\n",
1583
+ " with torch.no_grad():\n",
1584
+ " # only doing pixcorr eval on a subset of the samples per batch because its costly & slow to compute autoenc.decode()\n",
1585
+ " random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)\n",
1586
+ " blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample/ 2 + 0.5).clamp(0,1)\n",
1587
+ " pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)\n",
1588
+ " blurry_pixcorr += pixcorr.item()\n",
1589
+ "\n",
1590
+ " class_precisions_1 += classPrecision(logits, torch.argmax(semantic_cluster_onehot[images_indexes[f\"subj0{s}_iter{train_i}\"]], dim=1).to(logits.device))\n",
1591
+ " class_precisions_5 += classPrecision(logits, torch.argmax(semantic_cluster_onehot[images_indexes[f\"subj0{s}_iter{train_i}\"]], dim=1).to(logits.device), 5)\n",
1592
+ " class_precisions_10 += classPrecision(logits, torch.argmax(semantic_cluster_onehot[images_indexes[f\"subj0{s}_iter{train_i}\"]], dim=1).to(logits.device), 10)\n",
1593
+ "\n",
1594
+ " utils.check_loss(loss)\n",
1595
+ " accelerator.backward(loss)\n",
1596
+ " optimizer.step()\n",
1597
+ "\n",
1598
+ " losses.append(loss.item())\n",
1599
+ " lrs.append(optimizer.param_groups[0]['lr'])\n",
1600
+ "\n",
1601
+ " if lr_scheduler_type is not None:\n",
1602
+ " lr_scheduler.step()\n",
1603
+ "\n",
1604
+ " model.eval()\n",
1605
+ " if local_rank==0:\n",
1606
+ " with torch.no_grad(), torch.cuda.amp.autocast(dtype=data_type): \n",
1607
+ " for test_i, (behav, past_behav, future_behav, old_behav) in enumerate(test_dl): \n",
1608
+ " # all test samples should be loaded per batch such that test_i should never exceed 0\n",
1609
+ " assert len(behav) == num_test\n",
1610
+ "\n",
1611
+ " ## Average same-image repeats ##\n",
1612
+ " if test_image is None:\n",
1613
+ " voxel = voxels[f'subj0{subj}'][behav[:,0,5].cpu().long()].unsqueeze(1)\n",
1614
+ " \n",
1615
+ " image = behav[:,0,0].cpu().long()\n",
1616
+ "\n",
1617
+ " unique_image, sort_indices = torch.unique(image, return_inverse=True)\n",
1618
+ " for im in unique_image:\n",
1619
+ " locs = torch.where(im == image)[0]\n",
1620
+ " if len(locs)==1:\n",
1621
+ " locs = locs.repeat(3)\n",
1622
+ " elif len(locs)==2:\n",
1623
+ " locs = locs.repeat(2)[:3]\n",
1624
+ " assert len(locs)==3\n",
1625
+ " if test_image is None:\n",
1626
+ " test_image = torch.Tensor(images[im][None])\n",
1627
+ " test_voxel = voxel[locs][None]\n",
1628
+ " else:\n",
1629
+ " test_image = torch.vstack((test_image, torch.Tensor(images[im][None])))\n",
1630
+ " test_voxel = torch.vstack((test_voxel, voxel[locs][None]))\n",
1631
+ "\n",
1632
+ " loss=0.\n",
1633
+ " \n",
1634
+ " test_indices = torch.arange(len(test_voxel))[:300]\n",
1635
+ " voxel = test_voxel[test_indices].to(device)\n",
1636
+ " image = test_image[test_indices].to(device)\n",
1637
+ " assert len(image) == 300\n",
1638
+ "\n",
1639
+ " clip_target = clip_img_embedder(image.float())\n",
1640
+ "\n",
1641
+ " for rep in range(3):\n",
1642
+ " voxel_ridge = model.ridge(voxel[:,rep],0) # 0th index of subj_list\n",
1643
+ " backbone0, clip_voxels0, blurry_image_enc_ = model.backbone(voxel_ridge)\n",
1644
+ "\n",
1645
+ " logits0 = model.RRClassifier(backbone0.flatten(1))\n",
1646
+ "\n",
1647
+ " if rep==0:\n",
1648
+ " clip_voxels = clip_voxels0\n",
1649
+ " backbone = backbone0\n",
1650
+ " logits = logits0\n",
1651
+ " else:\n",
1652
+ " clip_voxels += clip_voxels0\n",
1653
+ " backbone += backbone0\n",
1654
+ " logits += logits0\n",
1655
+ " clip_voxels /= 3\n",
1656
+ " backbone /= 3\n",
1657
+ " logits /= 3\n",
1658
+ "\n",
1659
+ " print(logits.shape, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).shape)\n",
1660
+ " RR_loss = nn.functional.cross_entropy(logits, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).to(logits.device))\n",
1661
+ " test_loss_RR_total += RR_loss.item()\n",
1662
+ " loss += RR_loss\n",
1663
+ "\n",
1664
+ " if clip_scale>0:\n",
1665
+ " clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)\n",
1666
+ " clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)\n",
1667
+ " \n",
1668
+ " # for some evals, only doing a subset of the samples per batch because of computational cost\n",
1669
+ " random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)\n",
1670
+ " \n",
1671
+ " # if use_prior:\n",
1672
+ " # loss_prior, contaminated_prior_out = model.diffusion_prior(text_embed=backbone[random_samps], image_embed=clip_target[random_samps])\n",
1673
+ " # test_loss_prior_total += loss_prior.item()\n",
1674
+ " # loss_prior *= prior_scale\n",
1675
+ " # loss += loss_prior\n",
1676
+ " \n",
1677
+ " if clip_scale>0:\n",
1678
+ " loss_clip = utils.soft_clip_loss(\n",
1679
+ " clip_voxels_norm,\n",
1680
+ " clip_target_norm,\n",
1681
+ " temp=.006)\n",
1682
+ "\n",
1683
+ " test_loss_clip_total += loss_clip.item()\n",
1684
+ " loss_clip = loss_clip * clip_scale\n",
1685
+ " loss += loss_clip\n",
1686
+ "\n",
1687
+ " if blurry_recon:\n",
1688
+ " image_enc_pred, _ = blurry_image_enc_\n",
1689
+ " blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample / 2 + 0.5).clamp(0,1)\n",
1690
+ " pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)\n",
1691
+ " test_blurry_pixcorr += pixcorr.item()\n",
1692
+ "\n",
1693
+ " if clip_scale>0:\n",
1694
+ " # forward and backward top 1 accuracy \n",
1695
+ " labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device) \n",
1696
+ " test_fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()\n",
1697
+ " test_bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()\n",
1698
+ "\n",
1699
+ " test_class_precisions_1 += classPrecision(logits, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).to(logits.device))\n",
1700
+ " test_class_precisions_5 += classPrecision(logits, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).to(logits.device), 5)\n",
1701
+ " test_class_precisions_10 += classPrecision(logits, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).to(logits.device), 10)\n",
1702
+ "\n",
1703
+ " \n",
1704
+ " utils.check_loss(loss) \n",
1705
+ " test_losses.append(loss.item())\n",
1706
+ "\n",
1707
+ " assert (test_i+1) == 1\n",
1708
+ " logs = {\"train/loss\": np.mean(losses[-(train_i+1):]),\n",
1709
+ " \"test/loss\": np.mean(test_losses[-(test_i+1):]),\n",
1710
+ " \"train/lr\": lrs[-1],\n",
1711
+ " \"train/num_steps\": len(losses),\n",
1712
+ " \"test/num_steps\": len(test_losses),\n",
1713
+ " \"train/fwd_pct_correct\": fwd_percent_correct / (train_i + 1),\n",
1714
+ " \"train/bwd_pct_correct\": bwd_percent_correct / (train_i + 1),\n",
1715
+ " \"test/test_fwd_pct_correct\": test_fwd_percent_correct / (test_i + 1),\n",
1716
+ " \"test/test_bwd_pct_correct\": test_bwd_percent_correct / (test_i + 1),\n",
1717
+ " \"train/loss_clip_total\": loss_clip_total / (train_i + 1),\n",
1718
+ " \"train/loss_blurry_total\": loss_blurry_total / (train_i + 1),\n",
1719
+ " \"train/loss_blurry_cont_total\": loss_blurry_cont_total / (train_i + 1),\n",
1720
+ " \"test/loss_clip_total\": test_loss_clip_total / (test_i + 1),\n",
1721
+ " \"train/blurry_pixcorr\": blurry_pixcorr / (train_i + 1),\n",
1722
+ " \"test/blurry_pixcorr\": test_blurry_pixcorr / (test_i + 1),\n",
1723
+ " \"train/recon_cossim\": recon_cossim / (train_i + 1),\n",
1724
+ " \"test/recon_cossim\": test_recon_cossim / (test_i + 1),\n",
1725
+ " \"train/recon_mse\": recon_mse / (train_i + 1),\n",
1726
+ " \"test/recon_mse\": test_recon_mse / (test_i + 1),\n",
1727
+ " \"train/loss_prior\": loss_prior_total / (train_i + 1),\n",
1728
+ " \"test/loss_prior\": test_loss_prior_total / (test_i + 1),\n",
1729
+ " \"train/loss_RR\": loss_RR_total / (train_i + 1),\n",
1730
+ " \"test/loss_RR\": test_loss_RR_total / (test_i + 1),\n",
1731
+ " \"train/class_precisions_1\": class_precisions_1 / (train_i + 1),\n",
1732
+ " \"test/class_precisions_1\": test_class_precisions_1 / (test_i + 1),\n",
1733
+ " \"train/class_precisions_5\": class_precisions_5 / (train_i + 1),\n",
1734
+ " \"test/class_precisions_5\": test_class_precisions_5 / (test_i + 1),\n",
1735
+ " \"train/class_precisions_10\": class_precisions_10 / (train_i + 1),\n",
1736
+ " \"test/class_precisions_10\": test_class_precisions_10 / (test_i + 1),\n",
1737
+ " }\n",
1738
+ "\n",
1739
+ " # if finished training, save jpg recons if they exist\n",
1740
+ " if (epoch == num_epochs-1) or (epoch % ckpt_interval == 0):\n",
1741
+ " if blurry_recon: \n",
1742
+ " image_enc = autoenc.encode(2*image[:4]-1).latent_dist.mode() * 0.18215\n",
1743
+ " # transform blurry recon latents to images and plot it\n",
1744
+ " fig, axes = plt.subplots(1, 8, figsize=(10, 4))\n",
1745
+ " jj=-1\n",
1746
+ " for j in [0,1,2,3]:\n",
1747
+ " jj+=1\n",
1748
+ " axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))\n",
1749
+ " axes[jj].axis('off')\n",
1750
+ " jj+=1\n",
1751
+ " axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc_pred[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))\n",
1752
+ " axes[jj].axis('off')\n",
1753
+ "\n",
1754
+ " if wandb_log:\n",
1755
+ " logs[f\"test/blur_recons\"] = wandb.Image(fig, caption=f\"epoch{epoch:03d}\")\n",
1756
+ " plt.close()\n",
1757
+ " else:\n",
1758
+ " plt.show()\n",
1759
+ "\n",
1760
+ " progress_bar.set_postfix(**logs)\n",
1761
+ "\n",
1762
+ " if wandb_log: wandb.log(logs)\n",
1763
+ " \n",
1764
+ " # Save model checkpoint and reconstruct\n",
1765
+ " if (ckpt_saving) and (epoch % ckpt_interval == 0):\n",
1766
+ " save_ckpt(f'last')\n",
1767
+ "\n",
1768
+ " # wait for other GPUs to catch up if needed\n",
1769
+ " accelerator.wait_for_everyone()\n",
1770
+ " torch.cuda.empty_cache()\n",
1771
+ "\n",
1772
+ "print(\"\\n===Finished!===\\n\")\n",
1773
+ "if ckpt_saving:\n",
1774
+ " save_ckpt(f'last')"
1775
+ ]
1776
+ },
1777
+ {
1778
+ "cell_type": "code",
1779
+ "execution_count": 27,
1780
+ "id": "4211dd56-6a12-493e-8ccf-9b5229195cbd",
1781
+ "metadata": {},
1782
+ "outputs": [
1783
+ {
1784
+ "data": {
1785
+ "text/plain": [
1786
+ "{'photo of a person': 0,\n",
1787
+ " 'photo of airplane': 1,\n",
1788
+ " 'photo of baseball': 2,\n",
1789
+ " 'photo of bathroom': 3,\n",
1790
+ " 'photo of bear': 4,\n",
1791
+ " 'photo of bedroom': 5,\n",
1792
+ " 'photo of bike': 6,\n",
1793
+ " 'photo of bird': 7,\n",
1794
+ " 'photo of boat': 8,\n",
1795
+ " 'photo of bus': 9,\n",
1796
+ " 'photo of cat': 10,\n",
1797
+ " 'photo of clocktower': 11,\n",
1798
+ " 'photo of computer': 12,\n",
1799
+ " 'photo of cow': 13,\n",
1800
+ " 'photo of dog': 14,\n",
1801
+ " 'photo of elephant': 15,\n",
1802
+ " 'photo of flower': 16,\n",
1803
+ " 'photo of food': 17,\n",
1804
+ " 'photo of fruits': 18,\n",
1805
+ " 'photo of giraffe': 19,\n",
1806
+ " 'photo of group of people': 20,\n",
1807
+ " 'photo of horse': 21,\n",
1808
+ " 'photo of hydrant': 22,\n",
1809
+ " 'photo of living room': 23,\n",
1810
+ " 'photo of person eating': 24,\n",
1811
+ " 'photo of pizza': 25,\n",
1812
+ " 'photo of sheep': 26,\n",
1813
+ " 'photo of skate': 27,\n",
1814
+ " 'photo of ski': 28,\n",
1815
+ " 'photo of sky': 29,\n",
1816
+ " 'photo of soccer': 30,\n",
1817
+ " 'photo of sports': 31,\n",
1818
+ " 'photo of stop sign': 32,\n",
1819
+ " 'photo of surfer': 33,\n",
1820
+ " 'photo of sweets': 34,\n",
1821
+ " 'photo of tennis': 35,\n",
1822
+ " 'photo of toy': 36,\n",
1823
+ " 'photo of train': 37,\n",
1824
+ " 'photo of umbrella': 38,\n",
1825
+ " 'photo of vehicle': 39,\n",
1826
+ " 'photo of zebra': 40}"
1827
+ ]
1828
+ },
1829
+ "execution_count": 27,
1830
+ "metadata": {},
1831
+ "output_type": "execute_result"
1832
+ }
1833
+ ],
1834
+ "source": [
1835
+ "semantic_cluster_dict"
1836
+ ]
1837
+ },
1838
+ {
1839
+ "cell_type": "code",
1840
+ "execution_count": null,
1841
+ "id": "a7e81ae3-171f-40ad-a3e8-24bee4472325",
1842
+ "metadata": {
1843
+ "tags": []
1844
+ },
1845
+ "outputs": [],
1846
+ "source": [
1847
+ "plt.plot(losses)\n",
1848
+ "plt.show()\n",
1849
+ "plt.plot(test_losses)\n",
1850
+ "plt.show()"
1851
+ ]
1852
+ },
1853
+ {
1854
+ "cell_type": "code",
1855
+ "execution_count": null,
1856
+ "id": "45d5bc17-0914-43a5-bb4e-d98f0ba238f0",
1857
+ "metadata": {},
1858
+ "outputs": [],
1859
+ "source": [
1860
+ "import wandb\n",
1861
+ "wandb.login()"
1862
+ ]
1863
+ }
1864
+ ],
1865
+ "metadata": {
1866
+ "kernelspec": {
1867
+ "display_name": "Python 3 (ipykernel)",
1868
+ "language": "python",
1869
+ "name": "python3"
1870
+ },
1871
+ "language_info": {
1872
+ "codemirror_mode": {
1873
+ "name": "ipython",
1874
+ "version": 3
1875
+ },
1876
+ "file_extension": ".py",
1877
+ "mimetype": "text/x-python",
1878
+ "name": "python",
1879
+ "nbconvert_exporter": "python",
1880
+ "pygments_lexer": "ipython3",
1881
+ "version": "3.11.9"
1882
+ },
1883
+ "toc": {
1884
+ "base_numbering": 1,
1885
+ "nav_menu": {},
1886
+ "number_sections": true,
1887
+ "sideBar": true,
1888
+ "skip_h1_title": false,
1889
+ "title_cell": "Table of Contents",
1890
+ "title_sidebar": "Contents",
1891
+ "toc_cell": false,
1892
+ "toc_position": {
1893
+ "height": "calc(100% - 180px)",
1894
+ "left": "10px",
1895
+ "top": "150px",
1896
+ "width": "165px"
1897
+ },
1898
+ "toc_section_display": true,
1899
+ "toc_window_display": true
1900
+ },
1901
+ "toc-autonumbering": true,
1902
+ "vscode": {
1903
+ "interpreter": {
1904
+ "hash": "62aae01ef0cf7b6af841ab1c8ce59175c4332e693ab3d00bc32ceffb78a35376"
1905
+ }
1906
+ }
1907
+ },
1908
+ "nbformat": 4,
1909
+ "nbformat_minor": 5
1910
+ }
MindEyeV2/src/TrainCluster.ipynb ADDED
@@ -0,0 +1,1785 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "b0f0f4f3",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Import packages & functions"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": 1,
14
+ "id": "5bad764b-45c1-45ce-a716-8d055e09821a",
15
+ "metadata": {
16
+ "tags": []
17
+ },
18
+ "outputs": [],
19
+ "source": [
20
+ "import os\n",
21
+ "import sys\n",
22
+ "import json\n",
23
+ "import argparse\n",
24
+ "import numpy as np\n",
25
+ "import math\n",
26
+ "from einops import rearrange\n",
27
+ "import time\n",
28
+ "import random\n",
29
+ "import string\n",
30
+ "import h5py\n",
31
+ "from tqdm import tqdm\n",
32
+ "import webdataset as wds\n",
33
+ "\n",
34
+ "import matplotlib.pyplot as plt\n",
35
+ "import torch\n",
36
+ "import torch.nn as nn\n",
37
+ "from torchvision import transforms\n",
38
+ "from accelerate import Accelerator\n",
39
+ "\n",
40
+ "# SDXL unCLIP requires code from https://github.com/Stability-AI/generative-models/tree/main\n",
41
+ "sys.path.append('generative_models/')\n",
42
+ "import sgm\n",
43
+ "from generative_models.sgm.modules.encoders.modules import FrozenOpenCLIPImageEmbedder # bigG embedder\n",
44
+ "\n",
45
+ "# tf32 data type is faster than standard float32\n",
46
+ "torch.backends.cuda.matmul.allow_tf32 = True\n",
47
+ "\n",
48
+ "# custom functions #\n",
49
+ "import utils"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 2,
55
+ "id": "cc5d2e32-6027-4a19-bef4-5ca068db35bb",
56
+ "metadata": {
57
+ "tags": []
58
+ },
59
+ "outputs": [
60
+ {
61
+ "name": "stdout",
62
+ "output_type": "stream",
63
+ "text": [
64
+ "LOCAL RANK 0\n"
65
+ ]
66
+ }
67
+ ],
68
+ "source": [
69
+ "### Multi-GPU config ###\n",
70
+ "local_rank = os.getenv('RANK')\n",
71
+ "if local_rank is None: \n",
72
+ " local_rank = 0\n",
73
+ "else:\n",
74
+ " local_rank = int(local_rank)\n",
75
+ "print(\"LOCAL RANK \", local_rank) \n",
76
+ "\n",
77
+ "data_type = torch.float16 # change depending on your mixed_precision\n",
78
+ "num_devices = torch.cuda.device_count()\n",
79
+ "if num_devices==0: num_devices = 1\n",
80
+ "\n",
81
+ "# First use \"accelerate config\" in terminal and setup using deepspeed stage 2 with CPU offloading!\n",
82
+ "accelerator = Accelerator(split_batches=False, mixed_precision=\"fp16\")\n",
83
+ "if utils.is_interactive(): # set batch size here if using interactive notebook instead of submitting job\n",
84
+ " global_batch_size = batch_size = 8\n",
85
+ "else:\n",
86
+ " global_batch_size = os.environ[\"GLOBAL_BATCH_SIZE\"]\n",
87
+ " batch_size = int(os.environ[\"GLOBAL_BATCH_SIZE\"]) // num_devices"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": 3,
93
+ "id": "b767ab6f-d4a9-47a5-b3bf-f56bf6760c0c",
94
+ "metadata": {
95
+ "tags": []
96
+ },
97
+ "outputs": [
98
+ {
99
+ "name": "stdout",
100
+ "output_type": "stream",
101
+ "text": [
102
+ "PID of this process = 1132958\n",
103
+ "device: cuda\n",
104
+ "Distributed environment: DistributedType.NO\n",
105
+ "Num processes: 1\n",
106
+ "Process index: 0\n",
107
+ "Local process index: 0\n",
108
+ "Device: cuda\n",
109
+ "\n",
110
+ "Mixed precision type: fp16\n",
111
+ "\n",
112
+ "distributed = False num_devices = 1 local rank = 0 world size = 1 data_type = torch.float16\n"
113
+ ]
114
+ }
115
+ ],
116
+ "source": [
117
+ "print(\"PID of this process =\",os.getpid())\n",
118
+ "device = accelerator.device\n",
119
+ "print(\"device:\",device)\n",
120
+ "world_size = accelerator.state.num_processes\n",
121
+ "distributed = not accelerator.state.distributed_type == 'NO'\n",
122
+ "num_devices = torch.cuda.device_count()\n",
123
+ "if num_devices==0 or not distributed: num_devices = 1\n",
124
+ "num_workers = num_devices\n",
125
+ "print(accelerator.state)\n",
126
+ "\n",
127
+ "print(\"distributed =\",distributed, \"num_devices =\", num_devices, \"local rank =\", local_rank, \"world size =\", world_size, \"data_type =\", data_type)\n",
128
+ "print = accelerator.print # only print if local_rank=0"
129
+ ]
130
+ },
131
+ {
132
+ "cell_type": "markdown",
133
+ "id": "9018b82b-c054-4463-9527-4b0c2a75bda6",
134
+ "metadata": {
135
+ "tags": []
136
+ },
137
+ "source": [
138
+ "# Configurations"
139
+ ]
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "execution_count": 4,
144
+ "id": "2b61fec7-72a0-4b67-86da-1375f1d9fbd3",
145
+ "metadata": {
146
+ "tags": []
147
+ },
148
+ "outputs": [
149
+ {
150
+ "name": "stdout",
151
+ "output_type": "stream",
152
+ "text": [
153
+ "model_name: testing2\n",
154
+ "--data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=testing2 --no-multi_subject --subj=1 --batch_size=8 --num_sessions=40 --hidden_dim=1024 --clip_scale=1. --no-blurry_recon --blur_scale=.5 --use_prior --prior_scale=30 --n_blocks=4 --max_lr=3e-5 --mixup_pct=.33 --num_epochs=150 --no-use_image_aug --ckpt_interval=999 --no-ckpt_saving --wandb_log\n"
155
+ ]
156
+ }
157
+ ],
158
+ "source": [
159
+ "# if running this interactively, can specify jupyter_args here for argparser to use\n",
160
+ "if utils.is_interactive():\n",
161
+ " model_name = \"testing2\"\n",
162
+ " print(\"model_name:\", model_name)\n",
163
+ " \n",
164
+ " # global_batch_size and batch_size should already be defined in the 2nd cell block\n",
165
+ " jupyter_args = f\"--data_path=/weka/proj-medarc/shared/mindeyev2_dataset \\\n",
166
+ " --cache_dir=/weka/proj-medarc/shared/cache \\\n",
167
+ " --model_name={model_name} \\\n",
168
+ " --no-multi_subject --subj=1 --batch_size={batch_size} --num_sessions=40 \\\n",
169
+ " --hidden_dim=1024 --clip_scale=1. \\\n",
170
+ " --no-blurry_recon --blur_scale=.5 \\\n",
171
+ " --use_prior --prior_scale=30 \\\n",
172
+ " --n_blocks=4 --max_lr=3e-5 --mixup_pct=.33 --num_epochs=150 --no-use_image_aug \\\n",
173
+ " --ckpt_interval=999 --no-ckpt_saving --wandb_log\"\n",
174
+ " # --multisubject_ckpt=../train_logs/multisubject_subj01_1024_24bs_nolow\n",
175
+ "\n",
176
+ " print(jupyter_args)\n",
177
+ " jupyter_args = jupyter_args.split()\n",
178
+ " \n",
179
+ " from IPython.display import clear_output # function to clear print outputs in cell\n",
180
+ " %load_ext autoreload \n",
181
+ " # this allows you to change functions in models.py or utils.py and have this notebook automatically update with your revisions\n",
182
+ " %autoreload 2 "
183
+ ]
184
+ },
185
+ {
186
+ "cell_type": "code",
187
+ "execution_count": 5,
188
+ "id": "2028bdf0-2f41-46d9-b6e7-86b870dbf16c",
189
+ "metadata": {
190
+ "tags": []
191
+ },
192
+ "outputs": [
193
+ {
194
+ "name": "stdout",
195
+ "output_type": "stream",
196
+ "text": [
197
+ "subj_list [1] num_sessions 40\n"
198
+ ]
199
+ }
200
+ ],
201
+ "source": [
202
+ "parser = argparse.ArgumentParser(description=\"Model Training Configuration\")\n",
203
+ "parser.add_argument(\n",
204
+ " \"--model_name\", type=str, default=\"testing2\",\n",
205
+ " help=\"name of model, used for ckpt saving and wandb logging (if enabled)\",\n",
206
+ ")\n",
207
+ "parser.add_argument(\n",
208
+ " \"--data_path\", type=str, default=os.getcwd(),\n",
209
+ " help=\"Path to where NSD data is stored / where to download it to\",\n",
210
+ ")\n",
211
+ "parser.add_argument(\n",
212
+ " \"--cache_dir\", type=str, default=os.getcwd(),\n",
213
+ " help=\"Path to where misc. files downloaded from huggingface are stored. Defaults to current src directory.\",\n",
214
+ ")\n",
215
+ "parser.add_argument(\n",
216
+ " \"--subj\",type=int, default=1, choices=[1,2,3,4,5,6,7,8],\n",
217
+ " help=\"Validate on which subject?\",\n",
218
+ ")\n",
219
+ "parser.add_argument(\n",
220
+ " \"--multisubject_ckpt\", type=str, default=None,\n",
221
+ " help=\"Path to pre-trained multisubject model to finetune a single subject from. multisubject must be False.\",\n",
222
+ ")\n",
223
+ "parser.add_argument(\n",
224
+ " \"--num_sessions\", type=int, default=1,\n",
225
+ " help=\"Number of training sessions to include\",\n",
226
+ ")\n",
227
+ "parser.add_argument(\n",
228
+ " \"--use_prior\",action=argparse.BooleanOptionalAction,default=True,\n",
229
+ " help=\"whether to train diffusion prior (True) or just rely on retrieval part of the pipeline (False)\",\n",
230
+ ")\n",
231
+ "parser.add_argument(\n",
232
+ " \"--batch_size\", type=int, default=16,\n",
233
+ " help=\"Batch size can be increased by 10x if only training retreival submodule and not diffusion prior\",\n",
234
+ ")\n",
235
+ "parser.add_argument(\n",
236
+ " \"--wandb_log\",action=argparse.BooleanOptionalAction,default=False,\n",
237
+ " help=\"whether to log to wandb\",\n",
238
+ ")\n",
239
+ "parser.add_argument(\n",
240
+ " \"--wandb_project\",type=str,default=\"stability\",\n",
241
+ " help=\"wandb project name\",\n",
242
+ ")\n",
243
+ "parser.add_argument(\n",
244
+ " \"--mixup_pct\",type=float,default=.33,\n",
245
+ " help=\"proportion of way through training when to switch from BiMixCo to SoftCLIP\",\n",
246
+ ")\n",
247
+ "parser.add_argument(\n",
248
+ " \"--blurry_recon\",action=argparse.BooleanOptionalAction,default=True,\n",
249
+ " help=\"whether to output blurry reconstructions\",\n",
250
+ ")\n",
251
+ "parser.add_argument(\n",
252
+ " \"--blur_scale\",type=float,default=.5,\n",
253
+ " help=\"multiply loss from blurry recons by this number\",\n",
254
+ ")\n",
255
+ "parser.add_argument(\n",
256
+ " \"--clip_scale\",type=float,default=1.,\n",
257
+ " help=\"multiply contrastive loss by this number\",\n",
258
+ ")\n",
259
+ "parser.add_argument(\n",
260
+ " \"--prior_scale\",type=float,default=30,\n",
261
+ " help=\"multiply diffusion prior loss by this\",\n",
262
+ ")\n",
263
+ "parser.add_argument(\n",
264
+ " \"--use_image_aug\",action=argparse.BooleanOptionalAction,default=False,\n",
265
+ " help=\"whether to use image augmentation\",\n",
266
+ ")\n",
267
+ "parser.add_argument(\n",
268
+ " \"--num_epochs\",type=int,default=150,\n",
269
+ " help=\"number of epochs of training\",\n",
270
+ ")\n",
271
+ "parser.add_argument(\n",
272
+ " \"--multi_subject\",action=argparse.BooleanOptionalAction,default=False,\n",
273
+ ")\n",
274
+ "parser.add_argument(\n",
275
+ " \"--new_test\",action=argparse.BooleanOptionalAction,default=True,\n",
276
+ ")\n",
277
+ "parser.add_argument(\n",
278
+ " \"--n_blocks\",type=int,default=4,\n",
279
+ ")\n",
280
+ "parser.add_argument(\n",
281
+ " \"--hidden_dim\",type=int,default=1024,\n",
282
+ ")\n",
283
+ "parser.add_argument(\n",
284
+ " \"--lr_scheduler_type\",type=str,default='cycle',choices=['cycle','linear'],\n",
285
+ ")\n",
286
+ "parser.add_argument(\n",
287
+ " \"--ckpt_saving\",action=argparse.BooleanOptionalAction,default=True,\n",
288
+ ")\n",
289
+ "parser.add_argument(\n",
290
+ " \"--ckpt_interval\",type=int,default=5,\n",
291
+ " help=\"save backup ckpt and reconstruct every x epochs\",\n",
292
+ ")\n",
293
+ "parser.add_argument(\n",
294
+ " \"--seed\",type=int,default=42,\n",
295
+ ")\n",
296
+ "parser.add_argument(\n",
297
+ " \"--max_lr\",type=float,default=3e-5,\n",
298
+ ")\n",
299
+ "\n",
300
+ "if utils.is_interactive():\n",
301
+ " args = parser.parse_args(jupyter_args)\n",
302
+ "else:\n",
303
+ " args = parser.parse_args()\n",
304
+ "\n",
305
+ "# create global variables without the args prefix\n",
306
+ "for attribute_name in vars(args).keys():\n",
307
+ " globals()[attribute_name] = getattr(args, attribute_name)\n",
308
+ " \n",
309
+ "# seed all random functions\n",
310
+ "utils.seed_everything(seed)\n",
311
+ "\n",
312
+ "outdir = os.path.abspath(f'../train_logs/{model_name}')\n",
313
+ "if not os.path.exists(outdir) and ckpt_saving:\n",
314
+ " os.makedirs(outdir,exist_ok=True)\n",
315
+ " \n",
316
+ "if use_image_aug or blurry_recon:\n",
317
+ " import kornia\n",
318
+ " from kornia.augmentation.container import AugmentationSequential\n",
319
+ "if use_image_aug:\n",
320
+ " img_augment = AugmentationSequential(\n",
321
+ " kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1, p=0.3),\n",
322
+ " same_on_batch=False,\n",
323
+ " data_keys=[\"input\"],\n",
324
+ " )\n",
325
+ " \n",
326
+ "if multi_subject:\n",
327
+ " subj_list = np.arange(1,9)\n",
328
+ " subj_list = subj_list[subj_list != subj]\n",
329
+ "else:\n",
330
+ " subj_list = [subj]\n",
331
+ "\n",
332
+ "print(\"subj_list\", subj_list, \"num_sessions\", num_sessions)"
333
+ ]
334
+ },
335
+ {
336
+ "cell_type": "code",
337
+ "execution_count": 6,
338
+ "id": "2fb18bf3-27f5-470c-be05-002215d391b9",
339
+ "metadata": {},
340
+ "outputs": [
341
+ {
342
+ "data": {
343
+ "text/plain": [
344
+ "3e-05"
345
+ ]
346
+ },
347
+ "execution_count": 6,
348
+ "metadata": {},
349
+ "output_type": "execute_result"
350
+ }
351
+ ],
352
+ "source": [
353
+ "max_lr"
354
+ ]
355
+ },
356
+ {
357
+ "cell_type": "markdown",
358
+ "id": "42d13c25-1369-4c49-81d4-83d713586096",
359
+ "metadata": {
360
+ "tags": []
361
+ },
362
+ "source": [
363
+ "# Prep data, models, and dataloaders"
364
+ ]
365
+ },
366
+ {
367
+ "cell_type": "markdown",
368
+ "id": "1c023f24-5233-4a15-a2f5-78487b3a8546",
369
+ "metadata": {},
370
+ "source": [
371
+ "### Creating wds dataloader, preload betas and all 73k possible images"
372
+ ]
373
+ },
374
+ {
375
+ "cell_type": "code",
376
+ "execution_count": 7,
377
+ "id": "aefe7c27-ab39-4b2c-90f4-480f4087b7ab",
378
+ "metadata": {
379
+ "tags": []
380
+ },
381
+ "outputs": [
382
+ {
383
+ "name": "stdout",
384
+ "output_type": "stream",
385
+ "text": [
386
+ "dividing batch size by subj_list, which will then be concatenated across subj during training...\n",
387
+ "batch_size = 8 num_iterations_per_epoch = 3750 num_samples_per_epoch = 30000\n"
388
+ ]
389
+ }
390
+ ],
391
+ "source": [
392
+ "def my_split_by_node(urls): return urls\n",
393
+ "num_voxels_list = []\n",
394
+ "\n",
395
+ "if multi_subject:\n",
396
+ " nsessions_allsubj=np.array([40, 40, 32, 30, 40, 32, 40, 30])\n",
397
+ " num_samples_per_epoch = (750*40) // num_devices \n",
398
+ "else:\n",
399
+ " num_samples_per_epoch = (750*num_sessions) // num_devices \n",
400
+ "\n",
401
+ "print(\"dividing batch size by subj_list, which will then be concatenated across subj during training...\") \n",
402
+ "batch_size = batch_size // len(subj_list)\n",
403
+ "\n",
404
+ "num_iterations_per_epoch = num_samples_per_epoch // (batch_size*len(subj_list))\n",
405
+ "\n",
406
+ "print(\"batch_size =\", batch_size, \"num_iterations_per_epoch =\",num_iterations_per_epoch, \"num_samples_per_epoch =\",num_samples_per_epoch)"
407
+ ]
408
+ },
409
+ {
410
+ "cell_type": "code",
411
+ "execution_count": 8,
412
+ "id": "81084834-035f-4465-ad59-59e6b806a2f5",
413
+ "metadata": {
414
+ "tags": []
415
+ },
416
+ "outputs": [
417
+ {
418
+ "name": "stdout",
419
+ "output_type": "stream",
420
+ "text": [
421
+ "Training with 40 sessions\n",
422
+ "/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/train/{0..39}.tar\n",
423
+ "num_voxels for subj01: 15724\n",
424
+ "Loaded all subj train dls and betas!\n",
425
+ "\n",
426
+ "/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/new_test/0.tar\n",
427
+ "Loaded test dl for subj1!\n",
428
+ "\n"
429
+ ]
430
+ }
431
+ ],
432
+ "source": [
433
+ "train_data = {}\n",
434
+ "train_dl = {}\n",
435
+ "num_voxels = {}\n",
436
+ "voxels = {}\n",
437
+ "for s in subj_list:\n",
438
+ " print(f\"Training with {num_sessions} sessions\")\n",
439
+ " if multi_subject:\n",
440
+ " train_url = f\"{data_path}/wds/subj0{s}/train/\" + \"{0..\" + f\"{nsessions_allsubj[s-1]-1}\" + \"}.tar\"\n",
441
+ " else:\n",
442
+ " train_url = f\"{data_path}/wds/subj0{s}/train/\" + \"{0..\" + f\"{num_sessions-1}\" + \"}.tar\"\n",
443
+ " print(train_url)\n",
444
+ " \n",
445
+ " train_data[f'subj0{s}'] = wds.WebDataset(train_url,resampled=True,nodesplitter=my_split_by_node)\\\n",
446
+ " .shuffle(750, initial=1500, rng=random.Random(42))\\\n",
447
+ " .decode(\"torch\")\\\n",
448
+ " .rename(behav=\"behav.npy\", past_behav=\"past_behav.npy\", future_behav=\"future_behav.npy\", olds_behav=\"olds_behav.npy\")\\\n",
449
+ " .to_tuple(*[\"behav\", \"past_behav\", \"future_behav\", \"olds_behav\"])\n",
450
+ " train_dl[f'subj0{s}'] = torch.utils.data.DataLoader(train_data[f'subj0{s}'], batch_size=batch_size, shuffle=False, drop_last=False, pin_memory=True)\n",
451
+ "\n",
452
+ " f = h5py.File(f'{data_path}/betas_all_subj0{s}_fp32_renorm.hdf5', 'r')\n",
453
+ " betas = f['betas'][:]\n",
454
+ " betas = torch.Tensor(betas).to(\"cpu\").to(data_type)\n",
455
+ " num_voxels_list.append(betas[0].shape[-1])\n",
456
+ " num_voxels[f'subj0{s}'] = betas[0].shape[-1]\n",
457
+ " voxels[f'subj0{s}'] = betas\n",
458
+ " print(f\"num_voxels for subj0{s}: {num_voxels[f'subj0{s}']}\")\n",
459
+ "\n",
460
+ "print(\"Loaded all subj train dls and betas!\\n\")\n",
461
+ "\n",
462
+ "# Validate only on one subject\n",
463
+ "if multi_subject: \n",
464
+ " subj = subj_list[0] # cant validate on the actual held out person so picking first in subj_list\n",
465
+ "if not new_test: # using old test set from before full dataset released (used in original MindEye paper)\n",
466
+ " if subj==3:\n",
467
+ " num_test=2113\n",
468
+ " elif subj==4:\n",
469
+ " num_test=1985\n",
470
+ " elif subj==6:\n",
471
+ " num_test=2113\n",
472
+ " elif subj==8:\n",
473
+ " num_test=1985\n",
474
+ " else:\n",
475
+ " num_test=2770\n",
476
+ " test_url = f\"{data_path}/wds/subj0{subj}/test/\" + \"0.tar\"\n",
477
+ "elif new_test: # using larger test set from after full dataset released\n",
478
+ " if subj==3:\n",
479
+ " num_test=2371\n",
480
+ " elif subj==4:\n",
481
+ " num_test=2188\n",
482
+ " elif subj==6:\n",
483
+ " num_test=2371\n",
484
+ " elif subj==8:\n",
485
+ " num_test=2188\n",
486
+ " else:\n",
487
+ " num_test=3000\n",
488
+ " test_url = f\"{data_path}/wds/subj0{subj}/new_test/\" + \"0.tar\"\n",
489
+ "print(test_url)\n",
490
+ "test_data = wds.WebDataset(test_url,resampled=False,nodesplitter=my_split_by_node)\\\n",
491
+ " .shuffle(750, initial=1500, rng=random.Random(42))\\\n",
492
+ " .decode(\"torch\")\\\n",
493
+ " .rename(behav=\"behav.npy\", past_behav=\"past_behav.npy\", future_behav=\"future_behav.npy\", olds_behav=\"olds_behav.npy\")\\\n",
494
+ " .to_tuple(*[\"behav\", \"past_behav\", \"future_behav\", \"olds_behav\"])\n",
495
+ "test_dl = torch.utils.data.DataLoader(test_data, batch_size=num_test, shuffle=False, drop_last=True, pin_memory=True)\n",
496
+ "print(f\"Loaded test dl for subj{subj}!\\n\")"
497
+ ]
498
+ },
499
+ {
500
+ "cell_type": "code",
501
+ "execution_count": 9,
502
+ "id": "c13b4b84-094c-4b5b-bace-26c155aa6181",
503
+ "metadata": {
504
+ "tags": []
505
+ },
506
+ "outputs": [
507
+ {
508
+ "name": "stdout",
509
+ "output_type": "stream",
510
+ "text": [
511
+ "Loaded all 73k possible NSD images to cpu! (73000, 3, 224, 224)\n"
512
+ ]
513
+ }
514
+ ],
515
+ "source": [
516
+ "# Load 73k NSD images\n",
517
+ "f = h5py.File(f'{data_path}/coco_images_224_float16.hdf5', 'r')\n",
518
+ "images = f['images']\n",
519
+ "print(\"Loaded all 73k possible NSD images to cpu!\", images.shape)"
520
+ ]
521
+ },
522
+ {
523
+ "cell_type": "markdown",
524
+ "id": "10ec4517-dbdf-4ece-98f6-4714d5de4e15",
525
+ "metadata": {},
526
+ "source": [
527
+ "## Load models"
528
+ ]
529
+ },
530
+ {
531
+ "cell_type": "markdown",
532
+ "id": "48d6160e-1ee8-4da7-a755-9dbb452a6fa5",
533
+ "metadata": {},
534
+ "source": [
535
+ "### CLIP image embeddings model"
536
+ ]
537
+ },
538
+ {
539
+ "cell_type": "code",
540
+ "execution_count": 10,
541
+ "id": "b0420dc0-199e-4c1a-857d-b1747058b467",
542
+ "metadata": {
543
+ "tags": []
544
+ },
545
+ "outputs": [],
546
+ "source": [
547
+ "clip_img_embedder = FrozenOpenCLIPImageEmbedder(\n",
548
+ " arch=\"ViT-bigG-14\",\n",
549
+ " version=\"laion2b_s39b_b160k\",\n",
550
+ " output_tokens=True,\n",
551
+ " only_tokens=True,\n",
552
+ ")\n",
553
+ "clip_img_embedder.to(device)\n",
554
+ "\n",
555
+ "clip_seq_dim = 256\n",
556
+ "clip_emb_dim = 1664"
557
+ ]
558
+ },
559
+ {
560
+ "cell_type": "markdown",
561
+ "id": "5b79bd38-6990-4504-8d45-4a68d57d8885",
562
+ "metadata": {},
563
+ "source": [
564
+ "### SD VAE"
565
+ ]
566
+ },
567
+ {
568
+ "cell_type": "code",
569
+ "execution_count": 11,
570
+ "id": "01baff79-8114-482b-b115-6f05aa8ad691",
571
+ "metadata": {
572
+ "tags": []
573
+ },
574
+ "outputs": [],
575
+ "source": [
576
+ "if blurry_recon:\n",
577
+ " from diffusers import AutoencoderKL \n",
578
+ " autoenc = AutoencoderKL(\n",
579
+ " down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D'],\n",
580
+ " up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D'],\n",
581
+ " block_out_channels=[128, 256, 512, 512],\n",
582
+ " layers_per_block=2,\n",
583
+ " sample_size=256,\n",
584
+ " )\n",
585
+ " ckpt = torch.load(f'{cache_dir}/sd_image_var_autoenc.pth')\n",
586
+ " autoenc.load_state_dict(ckpt)\n",
587
+ " \n",
588
+ " autoenc.eval()\n",
589
+ " autoenc.requires_grad_(False)\n",
590
+ " autoenc.to(device)\n",
591
+ " utils.count_params(autoenc)\n",
592
+ " \n",
593
+ " from autoencoder.convnext import ConvnextXL\n",
594
+ " cnx = ConvnextXL(f'{cache_dir}/convnext_xlarge_alpha0.75_fullckpt.pth')\n",
595
+ " cnx.requires_grad_(False)\n",
596
+ " cnx.eval()\n",
597
+ " cnx.to(device)\n",
598
+ " \n",
599
+ " mean = torch.tensor([0.485, 0.456, 0.406]).to(device).reshape(1,3,1,1)\n",
600
+ " std = torch.tensor([0.228, 0.224, 0.225]).to(device).reshape(1,3,1,1)\n",
601
+ " \n",
602
+ " blur_augs = AugmentationSequential(\n",
603
+ " kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1, p=0.8),\n",
604
+ " kornia.augmentation.RandomGrayscale(p=0.1),\n",
605
+ " kornia.augmentation.RandomSolarize(p=0.1),\n",
606
+ " kornia.augmentation.RandomResizedCrop((224,224), scale=(.9,.9), ratio=(1,1), p=1.0),\n",
607
+ " data_keys=[\"input\"],\n",
608
+ " )"
609
+ ]
610
+ },
611
+ {
612
+ "cell_type": "markdown",
613
+ "id": "260e5e4a-f697-4b2c-88fc-01f6a54886c0",
614
+ "metadata": {},
615
+ "source": [
616
+ "### MindEye modules"
617
+ ]
618
+ },
619
+ {
620
+ "cell_type": "code",
621
+ "execution_count": 12,
622
+ "id": "c44c271b-173f-472e-b059-a2eda0f4c4c5",
623
+ "metadata": {
624
+ "tags": []
625
+ },
626
+ "outputs": [
627
+ {
628
+ "data": {
629
+ "text/plain": [
630
+ "MindEyeModule()"
631
+ ]
632
+ },
633
+ "execution_count": 12,
634
+ "metadata": {},
635
+ "output_type": "execute_result"
636
+ }
637
+ ],
638
+ "source": [
639
+ "class MindEyeModule(nn.Module):\n",
640
+ " def __init__(self):\n",
641
+ " super(MindEyeModule, self).__init__()\n",
642
+ " def forward(self, x):\n",
643
+ " return x\n",
644
+ " \n",
645
+ "model = MindEyeModule()\n",
646
+ "model"
647
+ ]
648
+ },
649
+ {
650
+ "cell_type": "code",
651
+ "execution_count": 13,
652
+ "id": "038a5d61-4769-40b9-a004-f4e7b5b38bb0",
653
+ "metadata": {
654
+ "tags": []
655
+ },
656
+ "outputs": [
657
+ {
658
+ "name": "stdout",
659
+ "output_type": "stream",
660
+ "text": [
661
+ "param counts:\n",
662
+ "16,102,400 total\n",
663
+ "16,102,400 trainable\n",
664
+ "param counts:\n",
665
+ "16,102,400 total\n",
666
+ "16,102,400 trainable\n",
667
+ "torch.Size([2, 1, 15724]) torch.Size([2, 1, 1024])\n"
668
+ ]
669
+ }
670
+ ],
671
+ "source": [
672
+ "class RidgeRegression(torch.nn.Module):\n",
673
+ " # make sure to add weight_decay when initializing optimizer to enable regularization\n",
674
+ " def __init__(self, input_sizes, out_features): \n",
675
+ " super(RidgeRegression, self).__init__()\n",
676
+ " self.out_features = out_features\n",
677
+ " self.linears = torch.nn.ModuleList([\n",
678
+ " torch.nn.Linear(input_size, out_features) for input_size in input_sizes\n",
679
+ " ])\n",
680
+ " def forward(self, x, subj_idx):\n",
681
+ " out = self.linears[subj_idx](x[:,0]).unsqueeze(1)\n",
682
+ " return out\n",
683
+ " \n",
684
+ "class IndividRidgeRegression(torch.nn.Module):\n",
685
+ " def __init__(self, input_size, out_features):\n",
686
+ " super(IndividRidgeRegression, self).__init__()\n",
687
+ " self.out_features = out_features\n",
688
+ " self.linear = torch.nn.Linear(input_size, out_features)\n",
689
+ " def forward(self, x):\n",
690
+ " out = self.linear(x)\n",
691
+ " return out\n",
692
+ " \n",
693
+ "model.ridge = RidgeRegression(num_voxels_list, out_features=hidden_dim)\n",
694
+ "utils.count_params(model.ridge)\n",
695
+ "utils.count_params(model)\n",
696
+ "\n",
697
+ "# test on subject 1 with fake data\n",
698
+ "b = torch.randn((2,1,num_voxels_list[0]))\n",
699
+ "print(b.shape, model.ridge(b,0).shape)"
700
+ ]
701
+ },
702
+ {
703
+ "cell_type": "code",
704
+ "execution_count": 14,
705
+ "id": "7b8de65a-6d3b-4248-bea9-9b6f4d562321",
706
+ "metadata": {
707
+ "tags": []
708
+ },
709
+ "outputs": [
710
+ {
711
+ "name": "stdout",
712
+ "output_type": "stream",
713
+ "text": [
714
+ "param counts:\n",
715
+ "453,360,280 total\n",
716
+ "453,360,280 trainable\n",
717
+ "param counts:\n",
718
+ "469,462,680 total\n",
719
+ "469,462,680 trainable\n",
720
+ "b.shape torch.Size([2, 1, 1024])\n",
721
+ "torch.Size([2, 256, 1664]) torch.Size([2, 256, 1664]) torch.Size([1]) torch.Size([1])\n"
722
+ ]
723
+ }
724
+ ],
725
+ "source": [
726
+ "from models import BrainNetwork\n",
727
+ "model.backbone = BrainNetwork(h=hidden_dim, in_dim=hidden_dim, seq_len=1, n_blocks=n_blocks,\n",
728
+ " clip_size=clip_emb_dim, out_dim=clip_emb_dim*clip_seq_dim, \n",
729
+ " blurry_recon=blurry_recon, clip_scale=clip_scale)\n",
730
+ "utils.count_params(model.backbone)\n",
731
+ "utils.count_params(model)\n",
732
+ "\n",
733
+ "# test that the model works on some fake data\n",
734
+ "b = torch.randn((2,1,hidden_dim))\n",
735
+ "print(\"b.shape\",b.shape)\n",
736
+ "\n",
737
+ "backbone_, clip_, blur_ = model.backbone(b)\n",
738
+ "print(backbone_.shape, clip_.shape, blur_[0].shape, blur_[1].shape)"
739
+ ]
740
+ },
741
+ {
742
+ "cell_type": "markdown",
743
+ "id": "e63b26a9-3a36-4638-be3c-dbf28705dd76",
744
+ "metadata": {},
745
+ "source": [
746
+ "### Load semantic clusters"
747
+ ]
748
+ },
749
+ {
750
+ "cell_type": "code",
751
+ "execution_count": 15,
752
+ "id": "2950add9-3828-4d55-bbf7-0d9f3519de5c",
753
+ "metadata": {},
754
+ "outputs": [
755
+ {
756
+ "name": "stdout",
757
+ "output_type": "stream",
758
+ "text": [
759
+ "semantic_cluster_onehot.shape torch.Size([73024, 41])\n",
760
+ "num_seman_clusters 41\n"
761
+ ]
762
+ }
763
+ ],
764
+ "source": [
765
+ "path_semantic_names = \"/weka/proj-medarc/shared/mindeyev2_dataset/semantic_cluster_names.npy\"\n",
766
+ "path_semantic_cluster = \"/weka/proj-medarc/shared/mindeyev2_dataset/COCO_73k_semantic_cluster.npy\"\n",
767
+ "semantic_cluster_names = np.load(path_semantic_names)\n",
768
+ "semantic_cluster = np.load(path_semantic_cluster)\n",
769
+ "possible_semantic_clusters = np.unique(semantic_cluster)\n",
770
+ "\n",
771
+ "# one-hot encode semantic clusters\n",
772
+ "# move possible_semantic_clusters to numbers and create a dictionary\n",
773
+ "semantic_cluster_dict = {cluster: i for i, cluster in enumerate(possible_semantic_clusters)}\n",
774
+ "semantic_cluster_onehot = torch.zeros((len(semantic_cluster), len(possible_semantic_clusters)))\n",
775
+ "for i, cluster in enumerate(semantic_cluster):\n",
776
+ " semantic_cluster_onehot[i, semantic_cluster_dict[cluster]] = 1\n",
777
+ "\n",
778
+ "\n",
779
+ "print(\"semantic_cluster_onehot.shape\", semantic_cluster_onehot.shape)\n",
780
+ "\n",
781
+ "num_seman_clusters = len(np.unique(semantic_cluster))\n",
782
+ "print(\"num_seman_clusters\", num_seman_clusters)"
783
+ ]
784
+ },
785
+ {
786
+ "cell_type": "markdown",
787
+ "id": "b397c0d7-52a3-4153-823b-c27d2eb3eeba",
788
+ "metadata": {},
789
+ "source": [
790
+ "### Adding the ridge regression to the class"
791
+ ]
792
+ },
793
+ {
794
+ "cell_type": "code",
795
+ "execution_count": 16,
796
+ "id": "69965344-9346-4592-9cc5-e537e31d5fce",
797
+ "metadata": {
798
+ "tags": []
799
+ },
800
+ "outputs": [
801
+ {
802
+ "name": "stdout",
803
+ "output_type": "stream",
804
+ "text": [
805
+ "param counts:\n",
806
+ "17,465,385 total\n",
807
+ "17,465,385 trainable\n",
808
+ "param counts:\n",
809
+ "486,928,065 total\n",
810
+ "486,928,065 trainable\n"
811
+ ]
812
+ },
813
+ {
814
+ "data": {
815
+ "text/plain": [
816
+ "486928065"
817
+ ]
818
+ },
819
+ "execution_count": 16,
820
+ "metadata": {},
821
+ "output_type": "execute_result"
822
+ }
823
+ ],
824
+ "source": [
825
+ "# if use_prior:\n",
826
+ "# from models import *\n",
827
+ "\n",
828
+ "# # setup diffusion prior network\n",
829
+ "# out_dim = clip_emb_dim\n",
830
+ "# depth = 6\n",
831
+ "# dim_head = 52\n",
832
+ "# heads = clip_emb_dim//52 # heads * dim_head = clip_emb_dim\n",
833
+ "# timesteps = 100\n",
834
+ "\n",
835
+ "# prior_network = PriorNetwork(\n",
836
+ "# dim=out_dim,\n",
837
+ "# depth=depth,\n",
838
+ "# dim_head=dim_head,\n",
839
+ "# heads=heads,\n",
840
+ "# causal=False,\n",
841
+ "# num_tokens = clip_seq_dim,\n",
842
+ "# learned_query_mode=\"pos_emb\"\n",
843
+ "# )\n",
844
+ "\n",
845
+ "# model.diffusion_prior = BrainDiffusionPrior(\n",
846
+ "# net=prior_network,\n",
847
+ "# image_embed_dim=out_dim,\n",
848
+ "# condition_on_text_encodings=False,\n",
849
+ "# timesteps=timesteps,\n",
850
+ "# cond_drop_prob=0.2,\n",
851
+ "# image_embed_scale=None,\n",
852
+ "# )\n",
853
+ " \n",
854
+ "# utils.count_params(model.diffusion_prior)\n",
855
+ "# utils.count_params(model)\n",
856
+ "\n",
857
+ "model.RRClassifier = IndividRidgeRegression(clip_emb_dim*clip_seq_dim, out_features=num_seman_clusters)\n",
858
+ "utils.count_params(model.RRClassifier)\n",
859
+ "utils.count_params(model)"
860
+ ]
861
+ },
862
+ {
863
+ "cell_type": "markdown",
864
+ "id": "ec25271a-2209-400c-8026-df3b8ddc1eef",
865
+ "metadata": {},
866
+ "source": [
867
+ "### Setup optimizer / lr / ckpt saving"
868
+ ]
869
+ },
870
+ {
871
+ "cell_type": "code",
872
+ "execution_count": 17,
873
+ "id": "e14d0482-dc42-43b9-9ce1-953c32f2c9c1",
874
+ "metadata": {
875
+ "tags": []
876
+ },
877
+ "outputs": [
878
+ {
879
+ "name": "stdout",
880
+ "output_type": "stream",
881
+ "text": [
882
+ "total_steps 562500\n",
883
+ "\n",
884
+ "Done with model preparations!\n",
885
+ "param counts:\n",
886
+ "486,928,065 total\n",
887
+ "486,928,065 trainable\n"
888
+ ]
889
+ }
890
+ ],
891
+ "source": [
892
+ "no_decay = ['bias', 'LayerNorm.bias', 'LayerNorm.weight']\n",
893
+ "\n",
894
+ "opt_grouped_parameters = [\n",
895
+ " {'params': [p for n, p in model.ridge.named_parameters()], 'weight_decay': 1e-2},\n",
896
+ " {'params': [p for n, p in model.backbone.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},\n",
897
+ " {'params': [p for n, p in model.backbone.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0},\n",
898
+ "]\n",
899
+ "# if use_prior:\n",
900
+ "# opt_grouped_parameters.extend([\n",
901
+ "# {'params': [p for n, p in model.diffusion_prior.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},\n",
902
+ "# {'params': [p for n, p in model.diffusion_prior.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0}\n",
903
+ "# ])\n",
904
+ "opt_grouped_parameters.extend([\n",
905
+ " {'params': [p for n, p in model.RRClassifier.named_parameters()], 'weight_decay': 1e-2},\n",
906
+ "])\n",
907
+ "\n",
908
+ "optimizer = torch.optim.AdamW(opt_grouped_parameters, lr=max_lr)\n",
909
+ "\n",
910
+ "if lr_scheduler_type == 'linear':\n",
911
+ " lr_scheduler = torch.optim.lr_scheduler.LinearLR(\n",
912
+ " optimizer,\n",
913
+ " total_iters=int(np.floor(num_epochs*num_iterations_per_epoch)),\n",
914
+ " last_epoch=-1\n",
915
+ " )\n",
916
+ "elif lr_scheduler_type == 'cycle':\n",
917
+ " total_steps=int(np.floor(num_epochs*num_iterations_per_epoch))\n",
918
+ " print(\"total_steps\", total_steps)\n",
919
+ " lr_scheduler = torch.optim.lr_scheduler.OneCycleLR(\n",
920
+ " optimizer, \n",
921
+ " max_lr=max_lr,\n",
922
+ " total_steps=total_steps,\n",
923
+ " final_div_factor=1000,\n",
924
+ " last_epoch=-1, pct_start=2/num_epochs\n",
925
+ " )\n",
926
+ " \n",
927
+ "def save_ckpt(tag):\n",
928
+ " ckpt_path = outdir+f'/{tag}.pth'\n",
929
+ " if accelerator.is_main_process:\n",
930
+ " unwrapped_model = accelerator.unwrap_model(model)\n",
931
+ " torch.save({\n",
932
+ " 'epoch': epoch,\n",
933
+ " 'model_state_dict': unwrapped_model.state_dict(),\n",
934
+ " 'optimizer_state_dict': optimizer.state_dict(),\n",
935
+ " 'lr_scheduler': lr_scheduler.state_dict(),\n",
936
+ " 'train_losses': losses,\n",
937
+ " 'test_losses': test_losses,\n",
938
+ " 'lrs': lrs,\n",
939
+ " }, ckpt_path)\n",
940
+ " print(f\"\\n---saved {outdir}/{tag} ckpt!---\\n\")\n",
941
+ "\n",
942
+ "def load_ckpt(tag,load_lr=True,load_optimizer=True,load_epoch=True,strict=True,outdir=outdir,multisubj_loading=False): \n",
943
+ " print(f\"\\n---loading {outdir}/{tag}.pth ckpt---\\n\")\n",
944
+ " checkpoint = torch.load(outdir+'/last.pth', map_location='cpu')\n",
945
+ " state_dict = checkpoint['model_state_dict']\n",
946
+ " if multisubj_loading: # remove incompatible ridge layer that will otherwise error\n",
947
+ " state_dict.pop('ridge.linears.0.weight',None)\n",
948
+ " model.load_state_dict(state_dict, strict=strict)\n",
949
+ " if load_epoch:\n",
950
+ " globals()[\"epoch\"] = checkpoint['epoch']\n",
951
+ " print(\"Epoch\",epoch)\n",
952
+ " if load_optimizer:\n",
953
+ " optimizer.load_state_dict(checkpoint['optimizer_state_dict'])\n",
954
+ " if load_lr:\n",
955
+ " lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])\n",
956
+ " del checkpoint\n",
957
+ "\n",
958
+ "print(\"\\nDone with model preparations!\")\n",
959
+ "num_params = utils.count_params(model)"
960
+ ]
961
+ },
962
+ {
963
+ "cell_type": "markdown",
964
+ "id": "983f458b-35b8-49f2-b6db-80296cece730",
965
+ "metadata": {},
966
+ "source": [
967
+ "# Weights and Biases"
968
+ ]
969
+ },
970
+ {
971
+ "cell_type": "code",
972
+ "execution_count": 18,
973
+ "id": "0a25a662-daa8-4de9-9233-8364800fcb6b",
974
+ "metadata": {
975
+ "tags": []
976
+ },
977
+ "outputs": [
978
+ {
979
+ "name": "stdout",
980
+ "output_type": "stream",
981
+ "text": [
982
+ "wandb mindeye_semantic_cluster run testing2\n",
983
+ "wandb_config:\n",
984
+ " {'model_name': 'testing2', 'global_batch_size': 8, 'batch_size': 8, 'num_epochs': 150, 'num_sessions': 40, 'num_params': 486928065, 'clip_scale': 1.0, 'prior_scale': 30.0, 'blur_scale': 0.5, 'use_image_aug': False, 'max_lr': 3e-05, 'mixup_pct': 0.33, 'num_samples_per_epoch': 30000, 'num_test': 3000, 'ckpt_interval': 999, 'ckpt_saving': False, 'seed': 42, 'distributed': False, 'num_devices': 1, 'world_size': 1, 'train_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/train/{0..39}.tar', 'test_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/new_test/0.tar'}\n",
985
+ "wandb_id: testing2\n"
986
+ ]
987
+ },
988
+ {
989
+ "name": "stderr",
990
+ "output_type": "stream",
991
+ "text": [
992
+ "\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mckadirt\u001b[0m. Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n"
993
+ ]
994
+ },
995
+ {
996
+ "data": {
997
+ "text/html": [
998
+ "wandb version 0.17.2 is available! To upgrade, please run:\n",
999
+ " $ pip install wandb --upgrade"
1000
+ ],
1001
+ "text/plain": [
1002
+ "<IPython.core.display.HTML object>"
1003
+ ]
1004
+ },
1005
+ "metadata": {},
1006
+ "output_type": "display_data"
1007
+ },
1008
+ {
1009
+ "data": {
1010
+ "text/html": [
1011
+ "Tracking run with wandb version 0.17.1"
1012
+ ],
1013
+ "text/plain": [
1014
+ "<IPython.core.display.HTML object>"
1015
+ ]
1016
+ },
1017
+ "metadata": {},
1018
+ "output_type": "display_data"
1019
+ },
1020
+ {
1021
+ "data": {
1022
+ "text/html": [
1023
+ "Run data is saved locally in <code>/weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_133545-testing2</code>"
1024
+ ],
1025
+ "text/plain": [
1026
+ "<IPython.core.display.HTML object>"
1027
+ ]
1028
+ },
1029
+ "metadata": {},
1030
+ "output_type": "display_data"
1031
+ },
1032
+ {
1033
+ "data": {
1034
+ "text/html": [
1035
+ "Resuming run <strong><a href='https://stability.wandb.io/ckadirt/mindeye_semantic_cluster/runs/testing2' target=\"_blank\">testing2</a></strong> to <a href='https://stability.wandb.io/ckadirt/mindeye_semantic_cluster' target=\"_blank\">Weights & Biases</a> (<a href='https://wandb.me/run' target=\"_blank\">docs</a>)<br/>"
1036
+ ],
1037
+ "text/plain": [
1038
+ "<IPython.core.display.HTML object>"
1039
+ ]
1040
+ },
1041
+ "metadata": {},
1042
+ "output_type": "display_data"
1043
+ },
1044
+ {
1045
+ "data": {
1046
+ "text/html": [
1047
+ " View project at <a href='https://stability.wandb.io/ckadirt/mindeye_semantic_cluster' target=\"_blank\">https://stability.wandb.io/ckadirt/mindeye_semantic_cluster</a>"
1048
+ ],
1049
+ "text/plain": [
1050
+ "<IPython.core.display.HTML object>"
1051
+ ]
1052
+ },
1053
+ "metadata": {},
1054
+ "output_type": "display_data"
1055
+ },
1056
+ {
1057
+ "data": {
1058
+ "text/html": [
1059
+ " View run at <a href='https://stability.wandb.io/ckadirt/mindeye_semantic_cluster/runs/testing2' target=\"_blank\">https://stability.wandb.io/ckadirt/mindeye_semantic_cluster/runs/testing2</a>"
1060
+ ],
1061
+ "text/plain": [
1062
+ "<IPython.core.display.HTML object>"
1063
+ ]
1064
+ },
1065
+ "metadata": {},
1066
+ "output_type": "display_data"
1067
+ }
1068
+ ],
1069
+ "source": [
1070
+ "if local_rank==0 and wandb_log: # only use main process for wandb logging\n",
1071
+ " import wandb\n",
1072
+ " wandb_project = 'mindeye_semantic_cluster'\n",
1073
+ " print(f\"wandb {wandb_project} run {model_name}\")\n",
1074
+ " # need to configure wandb beforehand in terminal with \"wandb init\"!\n",
1075
+ " wandb_config = {\n",
1076
+ " \"model_name\": model_name,\n",
1077
+ " \"global_batch_size\": global_batch_size,\n",
1078
+ " \"batch_size\": batch_size,\n",
1079
+ " \"num_epochs\": num_epochs,\n",
1080
+ " \"num_sessions\": num_sessions,\n",
1081
+ " \"num_params\": num_params,\n",
1082
+ " \"clip_scale\": clip_scale,\n",
1083
+ " \"prior_scale\": prior_scale,\n",
1084
+ " \"blur_scale\": blur_scale,\n",
1085
+ " \"use_image_aug\": use_image_aug,\n",
1086
+ " \"max_lr\": max_lr,\n",
1087
+ " \"mixup_pct\": mixup_pct,\n",
1088
+ " \"num_samples_per_epoch\": num_samples_per_epoch,\n",
1089
+ " \"num_test\": num_test,\n",
1090
+ " \"ckpt_interval\": ckpt_interval,\n",
1091
+ " \"ckpt_saving\": ckpt_saving,\n",
1092
+ " \"seed\": seed,\n",
1093
+ " \"distributed\": distributed,\n",
1094
+ " \"num_devices\": num_devices,\n",
1095
+ " \"world_size\": world_size,\n",
1096
+ " \"train_url\": train_url,\n",
1097
+ " \"test_url\": test_url,\n",
1098
+ " }\n",
1099
+ " print(\"wandb_config:\\n\",wandb_config)\n",
1100
+ " print(\"wandb_id:\",model_name)\n",
1101
+ " wandb.login(host='https://stability.wandb.io')\n",
1102
+ " wandb.init(\n",
1103
+ " id=model_name,\n",
1104
+ " project=wandb_project,\n",
1105
+ " name=model_name,\n",
1106
+ " config=wandb_config,\n",
1107
+ " resume=\"allow\",\n",
1108
+ " )\n",
1109
+ "else:\n",
1110
+ " wandb_log = False"
1111
+ ]
1112
+ },
1113
+ {
1114
+ "cell_type": "markdown",
1115
+ "id": "d5690151-2131-4918-b750-e869cbd1a8a8",
1116
+ "metadata": {},
1117
+ "source": [
1118
+ "# Main"
1119
+ ]
1120
+ },
1121
+ {
1122
+ "cell_type": "code",
1123
+ "execution_count": 19,
1124
+ "id": "12de6387-6e18-4e4b-b5ce-a847d625330a",
1125
+ "metadata": {
1126
+ "tags": []
1127
+ },
1128
+ "outputs": [],
1129
+ "source": [
1130
+ "epoch = 0\n",
1131
+ "losses, test_losses, lrs = [], [], []\n",
1132
+ "best_test_loss = 1e9\n",
1133
+ "torch.cuda.empty_cache()"
1134
+ ]
1135
+ },
1136
+ {
1137
+ "cell_type": "code",
1138
+ "execution_count": 20,
1139
+ "id": "607a7c7b-fe5e-41a4-80bf-d2814b3a57cc",
1140
+ "metadata": {
1141
+ "tags": []
1142
+ },
1143
+ "outputs": [],
1144
+ "source": [
1145
+ "# load multisubject stage1 ckpt if set\n",
1146
+ "if multisubject_ckpt is not None:\n",
1147
+ " load_ckpt(\"last\",outdir=multisubject_ckpt,load_lr=False,load_optimizer=False,load_epoch=False,strict=False,multisubj_loading=True)"
1148
+ ]
1149
+ },
1150
+ {
1151
+ "cell_type": "code",
1152
+ "execution_count": 21,
1153
+ "id": "99f09f76-4481-4133-b09a-a22b10dbc0c4",
1154
+ "metadata": {
1155
+ "tags": []
1156
+ },
1157
+ "outputs": [],
1158
+ "source": [
1159
+ "train_dls = [train_dl[f'subj0{s}'] for s in subj_list]\n",
1160
+ "\n",
1161
+ "model, optimizer, *train_dls, lr_scheduler, semantic_cluster_onehot = accelerator.prepare(model, optimizer, *train_dls, lr_scheduler, semantic_cluster_onehot)\n",
1162
+ "# leaving out test_dl since we will only have local_rank 0 device do evals"
1163
+ ]
1164
+ },
1165
+ {
1166
+ "cell_type": "code",
1167
+ "execution_count": 22,
1168
+ "id": "e16fa583-064c-4cfa-9f47-08d08f53f504",
1169
+ "metadata": {},
1170
+ "outputs": [
1171
+ {
1172
+ "name": "stdout",
1173
+ "output_type": "stream",
1174
+ "text": [
1175
+ "3750\n"
1176
+ ]
1177
+ }
1178
+ ],
1179
+ "source": [
1180
+ "print(num_iterations_per_epoch)"
1181
+ ]
1182
+ },
1183
+ {
1184
+ "cell_type": "code",
1185
+ "execution_count": 23,
1186
+ "id": "60be0d5f-3e94-4612-9373-61b53d836393",
1187
+ "metadata": {
1188
+ "tags": []
1189
+ },
1190
+ "outputs": [
1191
+ {
1192
+ "name": "stdout",
1193
+ "output_type": "stream",
1194
+ "text": [
1195
+ "testing2 starting with epoch 0 / 150\n"
1196
+ ]
1197
+ },
1198
+ {
1199
+ "name": "stderr",
1200
+ "output_type": "stream",
1201
+ "text": [
1202
+ " 0%| | 0/150 [00:00<?, ?it/s]"
1203
+ ]
1204
+ },
1205
+ {
1206
+ "name": "stdout",
1207
+ "output_type": "stream",
1208
+ "text": [
1209
+ "torch.Size([300, 41]) torch.Size([300])\n"
1210
+ ]
1211
+ },
1212
+ {
1213
+ "name": "stderr",
1214
+ "output_type": "stream",
1215
+ "text": [
1216
+ " 1%|████▏ | 1/150 [06:36<16:25:13, 396.74s/it, test/blurry_pixcorr=0, test/loss=13, test/loss_RR=10.7, test/loss_clip_total=2.26, test/loss_prior=0, test/num_steps=1, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.37, test/test_fwd_pct_correct=0.703, train/blurry_pixcorr=0, train/bwd_pct_correct=0.402, train/fwd_pct_correct=0.445, train/loss=3.54, train/loss_RR=2.21, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=1.33, train/loss_prior=0, train/lr=1.56e-5, train/num_steps=3750, train/recon_cossim=0, train/recon_mse=0]"
1217
+ ]
1218
+ },
1219
+ {
1220
+ "name": "stdout",
1221
+ "output_type": "stream",
1222
+ "text": [
1223
+ "torch.Size([300, 41]) torch.Size([300])\n"
1224
+ ]
1225
+ },
1226
+ {
1227
+ "name": "stderr",
1228
+ "output_type": "stream",
1229
+ "text": [
1230
+ " 1%|████████▎ | 2/150 [13:23<16:32:38, 402.42s/it, test/blurry_pixcorr=0, test/loss=42.5, test/loss_RR=41.1, test/loss_clip_total=1.37, test/loss_prior=0, test/num_steps=2, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.613, test/test_fwd_pct_correct=0.827, train/blurry_pixcorr=0, train/bwd_pct_correct=0.717, train/fwd_pct_correct=0.708, train/loss=3.95, train/loss_RR=3.5, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=0.448, train/loss_prior=0, train/lr=3e-5, train/num_steps=7500, train/recon_cossim=0, train/recon_mse=0]"
1231
+ ]
1232
+ },
1233
+ {
1234
+ "name": "stdout",
1235
+ "output_type": "stream",
1236
+ "text": [
1237
+ "torch.Size([300, 41]) torch.Size([300])\n"
1238
+ ]
1239
+ },
1240
+ {
1241
+ "name": "stderr",
1242
+ "output_type": "stream",
1243
+ "text": [
1244
+ " 2%|████████████▌ | 3/150 [19:12<15:26:12, 378.04s/it, test/blurry_pixcorr=0, test/loss=76.7, test/loss_RR=75.5, test/loss_clip_total=1.18, test/loss_prior=0, test/num_steps=3, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.72, test/test_fwd_pct_correct=0.89, train/blurry_pixcorr=0, train/bwd_pct_correct=0.746, train/fwd_pct_correct=0.725, train/loss=4.13, train/loss_RR=3.75, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=0.376, train/loss_prior=0, train/lr=3e-5, train/num_steps=11250, train/recon_cossim=0, train/recon_mse=0]"
1245
+ ]
1246
+ },
1247
+ {
1248
+ "name": "stdout",
1249
+ "output_type": "stream",
1250
+ "text": [
1251
+ "torch.Size([300, 41]) torch.Size([300])\n"
1252
+ ]
1253
+ },
1254
+ {
1255
+ "name": "stderr",
1256
+ "output_type": "stream",
1257
+ "text": [
1258
+ " 3%|████████████████▋ | 4/150 [23:52<13:46:10, 339.53s/it, test/blurry_pixcorr=0, test/loss=58.4, test/loss_RR=57.2, test/loss_clip_total=1.18, test/loss_prior=0, test/num_steps=4, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.817, test/test_fwd_pct_correct=0.913, train/blurry_pixcorr=0, train/bwd_pct_correct=0.758, train/fwd_pct_correct=0.73, train/loss=3.77, train/loss_RR=3.44, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=0.335, train/loss_prior=0, train/lr=3e-5, train/num_steps=15000, train/recon_cossim=0, train/recon_mse=0]"
1259
+ ]
1260
+ },
1261
+ {
1262
+ "name": "stdout",
1263
+ "output_type": "stream",
1264
+ "text": [
1265
+ "torch.Size([300, 41]) torch.Size([300])\n"
1266
+ ]
1267
+ },
1268
+ {
1269
+ "name": "stderr",
1270
+ "output_type": "stream",
1271
+ "text": [
1272
+ " 3%|████████████████████▉ | 5/150 [28:32<12:48:34, 318.03s/it, test/blurry_pixcorr=0, test/loss=58.6, test/loss_RR=57.5, test/loss_clip_total=1.12, test/loss_prior=0, test/num_steps=5, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.797, test/test_fwd_pct_correct=0.903, train/blurry_pixcorr=0, train/bwd_pct_correct=0.763, train/fwd_pct_correct=0.733, train/loss=3.73, train/loss_RR=3.41, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=0.32, train/loss_prior=0, train/lr=3e-5, train/num_steps=18750, train/recon_cossim=0, train/recon_mse=0]"
1273
+ ]
1274
+ },
1275
+ {
1276
+ "name": "stdout",
1277
+ "output_type": "stream",
1278
+ "text": [
1279
+ "torch.Size([300, 41]) torch.Size([300])\n"
1280
+ ]
1281
+ },
1282
+ {
1283
+ "name": "stderr",
1284
+ "output_type": "stream",
1285
+ "text": [
1286
+ " 4%|████████████████████████▉ | 6/150 [33:12<12:12:10, 305.07s/it, test/blurry_pixcorr=0, test/loss=44.9, test/loss_RR=43.7, test/loss_clip_total=1.14, test/loss_prior=0, test/num_steps=6, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.833, test/test_fwd_pct_correct=0.897, train/blurry_pixcorr=0, train/bwd_pct_correct=0.773, train/fwd_pct_correct=0.735, train/loss=3.67, train/loss_RR=3.37, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=0.302, train/loss_prior=0, train/lr=2.99e-5, train/num_steps=22500, train/recon_cossim=0, train/recon_mse=0]"
1287
+ ]
1288
+ },
1289
+ {
1290
+ "name": "stdout",
1291
+ "output_type": "stream",
1292
+ "text": [
1293
+ "torch.Size([300, 41]) torch.Size([300])\n"
1294
+ ]
1295
+ },
1296
+ {
1297
+ "name": "stderr",
1298
+ "output_type": "stream",
1299
+ "text": [
1300
+ " 5%|█████████████████████████████ | 7/150 [37:52<11:47:39, 296.92s/it, test/blurry_pixcorr=0, test/loss=65.1, test/loss_RR=64.1, test/loss_clip_total=0.981, test/loss_prior=0, test/num_steps=7, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.867, test/test_fwd_pct_correct=0.93, train/blurry_pixcorr=0, train/bwd_pct_correct=0.774, train/fwd_pct_correct=0.738, train/loss=3.68, train/loss_RR=3.38, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=0.294, train/loss_prior=0, train/lr=2.99e-5, train/num_steps=26250, train/recon_cossim=0, train/recon_mse=0]"
1301
+ ]
1302
+ },
1303
+ {
1304
+ "name": "stdout",
1305
+ "output_type": "stream",
1306
+ "text": [
1307
+ "torch.Size([300, 41]) torch.Size([300])\n"
1308
+ ]
1309
+ },
1310
+ {
1311
+ "name": "stderr",
1312
+ "output_type": "stream",
1313
+ "text": [
1314
+ " 5%|█████████████████████████████████▍ | 8/150 [42:32<11:29:38, 291.40s/it, test/blurry_pixcorr=0, test/loss=102, test/loss_RR=101, test/loss_clip_total=1.01, test/loss_prior=0, test/num_steps=8, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.823, test/test_fwd_pct_correct=0.927, train/blurry_pixcorr=0, train/bwd_pct_correct=0.771, train/fwd_pct_correct=0.735, train/loss=3.6, train/loss_RR=3.31, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=0.291, train/loss_prior=0, train/lr=2.99e-5, train/num_steps=3e+4, train/recon_cossim=0, train/recon_mse=0]"
1315
+ ]
1316
+ },
1317
+ {
1318
+ "name": "stdout",
1319
+ "output_type": "stream",
1320
+ "text": [
1321
+ "torch.Size([300, 41]) torch.Size([300])\n"
1322
+ ]
1323
+ },
1324
+ {
1325
+ "name": "stderr",
1326
+ "output_type": "stream",
1327
+ "text": [
1328
+ " 6%|█████████████████████████████████████▌ | 9/150 [47:13<11:17:18, 288.22s/it, test/blurry_pixcorr=0, test/loss=40.6, test/loss_RR=39.5, test/loss_clip_total=1.03, test/loss_prior=0, test/num_steps=9, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.85, test/test_fwd_pct_correct=0.92, train/blurry_pixcorr=0, train/bwd_pct_correct=0.777, train/fwd_pct_correct=0.739, train/loss=3.63, train/loss_RR=3.34, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=0.282, train/loss_prior=0, train/lr=2.98e-5, train/num_steps=33750, train/recon_cossim=0, train/recon_mse=0]"
1329
+ ]
1330
+ },
1331
+ {
1332
+ "name": "stdout",
1333
+ "output_type": "stream",
1334
+ "text": [
1335
+ "torch.Size([300, 41]) torch.Size([300])\n"
1336
+ ]
1337
+ },
1338
+ {
1339
+ "name": "stderr",
1340
+ "output_type": "stream",
1341
+ "text": [
1342
+ " 7%|█████████████████████████████████████████▎ | 10/150 [1:21:00<18:54:10, 486.07s/it, test/blurry_pixcorr=0, test/loss=106, test/loss_RR=105, test/loss_clip_total=0.948, test/loss_prior=0, test/num_steps=10, test/recon_cossim=0, test/recon_mse=0, test/test_bwd_pct_correct=0.897, test/test_fwd_pct_correct=0.923, train/blurry_pixcorr=0, train/bwd_pct_correct=0.773, train/fwd_pct_correct=0.733, train/loss=3.61, train/loss_RR=3.33, train/loss_blurry_cont_total=0, train/loss_blurry_total=0, train/loss_clip_total=0.284, train/loss_prior=0, train/lr=2.98e-5, train/num_steps=37500, train/recon_cossim=0, train/recon_mse=0]\n"
1343
+ ]
1344
+ },
1345
+ {
1346
+ "ename": "KeyboardInterrupt",
1347
+ "evalue": "",
1348
+ "output_type": "error",
1349
+ "traceback": [
1350
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1351
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
1352
+ "Cell \u001b[0;32mIn[23], line 188\u001b[0m\n\u001b[1;32m 185\u001b[0m accelerator\u001b[38;5;241m.\u001b[39mbackward(loss)\n\u001b[1;32m 186\u001b[0m optimizer\u001b[38;5;241m.\u001b[39mstep()\n\u001b[0;32m--> 188\u001b[0m losses\u001b[38;5;241m.\u001b[39mappend(\u001b[43mloss\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mitem\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 189\u001b[0m lrs\u001b[38;5;241m.\u001b[39mappend(optimizer\u001b[38;5;241m.\u001b[39mparam_groups[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlr\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m 191\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m lr_scheduler_type \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
1353
+ "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
1354
+ ]
1355
+ }
1356
+ ],
1357
+ "source": [
1358
+ "print(f\"{model_name} starting with epoch {epoch} / {num_epochs}\")\n",
1359
+ "progress_bar = tqdm(range(epoch,num_epochs), ncols=1200, disable=(local_rank!=0))\n",
1360
+ "test_image, test_voxel = None, None\n",
1361
+ "mse = nn.MSELoss()\n",
1362
+ "l1 = nn.L1Loss()\n",
1363
+ "soft_loss_temps = utils.cosine_anneal(0.004, 0.0075, num_epochs - int(mixup_pct * num_epochs))\n",
1364
+ "\n",
1365
+ "for epoch in progress_bar:\n",
1366
+ " model.train()\n",
1367
+ "\n",
1368
+ " fwd_percent_correct = 0.\n",
1369
+ " bwd_percent_correct = 0.\n",
1370
+ " test_fwd_percent_correct = 0.\n",
1371
+ " test_bwd_percent_correct = 0.\n",
1372
+ " \n",
1373
+ " recon_cossim = 0.\n",
1374
+ " test_recon_cossim = 0.\n",
1375
+ " recon_mse = 0.\n",
1376
+ " test_recon_mse = 0.\n",
1377
+ "\n",
1378
+ " loss_clip_total = 0.\n",
1379
+ " loss_blurry_total = 0.\n",
1380
+ " loss_blurry_cont_total = 0.\n",
1381
+ " test_loss_clip_total = 0.\n",
1382
+ " \n",
1383
+ " loss_prior_total = 0.\n",
1384
+ " test_loss_prior_total = 0.\n",
1385
+ " \n",
1386
+ " loss_RR_total = 0.\n",
1387
+ " test_loss_RR_total = 0.\n",
1388
+ "\n",
1389
+ " blurry_pixcorr = 0.\n",
1390
+ " test_blurry_pixcorr = 0. # needs >.456 to beat low-level subj01 results in mindeye v1\n",
1391
+ "\n",
1392
+ " # pre-load all batches for this epoch (it's MUCH faster to pre-load in bulk than to separate loading per batch)\n",
1393
+ " voxel_iters = {} # empty dict because diff subjects have differing # of voxels\n",
1394
+ " image_iters = torch.zeros(num_iterations_per_epoch, batch_size*len(subj_list), 3, 224, 224).float()\n",
1395
+ " annot_iters = {}\n",
1396
+ " perm_iters, betas_iters, select_iters = {}, {}, {}\n",
1397
+ " images_indexes = {}\n",
1398
+ " for s, train_dl in enumerate(train_dls):\n",
1399
+ " with torch.cuda.amp.autocast(dtype=data_type):\n",
1400
+ " iter = -1\n",
1401
+ " for behav0, past_behav0, future_behav0, old_behav0 in train_dl: \n",
1402
+ " # Load images to cpu from hdf5 (requires sorted indexing)\n",
1403
+ " image_idx = behav0[:,0,0].cpu().long().numpy()\n",
1404
+ "\n",
1405
+ " image0, image_sorted_idx = np.unique(image_idx, return_index=True) \n",
1406
+ " if len(image0) != len(image_idx): # hdf5 cant handle duplicate indexing\n",
1407
+ " continue\n",
1408
+ " iter += 1\n",
1409
+ " image0 = torch.tensor(images[image0], dtype=data_type)\n",
1410
+ " image_iters[iter,s*batch_size:s*batch_size+batch_size] = image0\n",
1411
+ " images_indexes[f\"subj0{s}_iter{iter}\"] = image_sorted_idx\n",
1412
+ " \n",
1413
+ " # Load voxels for current batch, matching above indexing\n",
1414
+ " voxel_idx = behav0[:,0,5].cpu().long().numpy()\n",
1415
+ " voxel_sorted_idx = voxel_idx[image_sorted_idx]\n",
1416
+ " voxel0 = voxels[f'subj0{subj_list[s]}'][voxel_sorted_idx]\n",
1417
+ " voxel0 = torch.Tensor(voxel0).unsqueeze(1)\n",
1418
+ "\n",
1419
+ " if epoch < int(mixup_pct * num_epochs):\n",
1420
+ " voxel0, perm, betas, select = utils.mixco(voxel0)\n",
1421
+ " perm_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = perm\n",
1422
+ " betas_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = betas\n",
1423
+ " select_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = select\n",
1424
+ "\n",
1425
+ " voxel_iters[f\"subj0{subj_list[s]}_iter{iter}\"] = voxel0\n",
1426
+ "\n",
1427
+ " if iter >= num_iterations_per_epoch-1:\n",
1428
+ " break\n",
1429
+ "\n",
1430
+ " # you now have voxel_iters and image_iters with num_iterations_per_epoch batches each\n",
1431
+ " for train_i in range(num_iterations_per_epoch):\n",
1432
+ " with torch.cuda.amp.autocast(dtype=data_type):\n",
1433
+ " optimizer.zero_grad()\n",
1434
+ " loss=0.\n",
1435
+ "\n",
1436
+ " voxel_list = [voxel_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1437
+ " image = image_iters[train_i].detach()\n",
1438
+ " image = image.to(device)\n",
1439
+ "\n",
1440
+ " if use_image_aug: \n",
1441
+ " image = img_augment(image)\n",
1442
+ "\n",
1443
+ " clip_target = clip_img_embedder(image)\n",
1444
+ " assert not torch.any(torch.isnan(clip_target))\n",
1445
+ "\n",
1446
+ " if epoch < int(mixup_pct * num_epochs):\n",
1447
+ " perm_list = [perm_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1448
+ " perm = torch.cat(perm_list, dim=0)\n",
1449
+ " betas_list = [betas_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1450
+ " betas = torch.cat(betas_list, dim=0)\n",
1451
+ " select_list = [select_iters[f\"subj0{s}_iter{train_i}\"].detach().to(device) for s in subj_list]\n",
1452
+ " select = torch.cat(select_list, dim=0)\n",
1453
+ "\n",
1454
+ " voxel_ridge_list = [model.ridge(voxel_list[si],si) for si,s in enumerate(subj_list)]\n",
1455
+ " voxel_ridge = torch.cat(voxel_ridge_list, dim=0)\n",
1456
+ "\n",
1457
+ " backbone, clip_voxels, blurry_image_enc_ = model.backbone(voxel_ridge)\n",
1458
+ "\n",
1459
+ " if clip_scale>0:\n",
1460
+ " clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)\n",
1461
+ " clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)\n",
1462
+ "\n",
1463
+ " # if use_prior:\n",
1464
+ " # loss_prior, prior_out = model.diffusion_prior(text_embed=backbone, image_embed=clip_target)\n",
1465
+ " # loss_prior_total += loss_prior.item()\n",
1466
+ " # loss_prior *= prior_scale\n",
1467
+ " # loss += loss_prior\n",
1468
+ "\n",
1469
+ " # recon_cossim += nn.functional.cosine_similarity(prior_out, clip_target).mean().item()\n",
1470
+ " # recon_mse += mse(prior_out, clip_target).item()\n",
1471
+ "\n",
1472
+ " logits = model.RRClassifier(backbone.flatten(1))\n",
1473
+ " #print(logits.shape, torch.argmax(semantic_cluster_onehot[images_indexes[f\"subj0{s}_iter{train_i}\"]], dim=1).shape)\n",
1474
+ " #print(logits, torch.argmax(semantic_cluster_onehot[images_indexes[f\"subj0{s}_iter{train_i}\"]], dim=1))\n",
1475
+ " loss_RR = nn.functional.cross_entropy(logits, torch.argmax(semantic_cluster_onehot[images_indexes[f\"subj0{s}_iter{train_i}\"]], dim=1).to(logits.device))\n",
1476
+ " #print(\"backbone.shape\",backbone.shape, \"clip_voxels.shape\",clip_voxels.shape, \"blurry_image_enc_[0].shape\",blurry_image_enc_[0].shape, \"blurry_image_enc_[1].shape\",blurry_image_enc_[1].shape)\n",
1477
+ " #something \n",
1478
+ "\n",
1479
+ " loss_RR_total += loss_RR.item()\n",
1480
+ " loss += loss_RR\n",
1481
+ "\n",
1482
+ " if clip_scale>0:\n",
1483
+ " if epoch < int(mixup_pct * num_epochs): \n",
1484
+ " loss_clip = utils.mixco_nce(\n",
1485
+ " clip_voxels_norm,\n",
1486
+ " clip_target_norm,\n",
1487
+ " temp=.006,\n",
1488
+ " perm=perm, betas=betas, select=select)\n",
1489
+ " else:\n",
1490
+ " epoch_temp = soft_loss_temps[epoch-int(mixup_pct*num_epochs)]\n",
1491
+ " loss_clip = utils.soft_clip_loss(\n",
1492
+ " clip_voxels_norm,\n",
1493
+ " clip_target_norm,\n",
1494
+ " temp=epoch_temp)\n",
1495
+ "\n",
1496
+ " loss_clip_total += loss_clip.item()\n",
1497
+ " loss_clip *= clip_scale\n",
1498
+ " loss += loss_clip\n",
1499
+ "\n",
1500
+ " if blurry_recon: \n",
1501
+ " image_enc_pred, transformer_feats = blurry_image_enc_\n",
1502
+ "\n",
1503
+ " image_enc = autoenc.encode(2*image-1).latent_dist.mode() * 0.18215\n",
1504
+ " loss_blurry = l1(image_enc_pred, image_enc)\n",
1505
+ " loss_blurry_total += loss_blurry.item()\n",
1506
+ "\n",
1507
+ " if epoch < int(mixup_pct * num_epochs):\n",
1508
+ " image_enc_shuf = image_enc[perm]\n",
1509
+ " betas_shape = [-1] + [1]*(len(image_enc.shape)-1)\n",
1510
+ " image_enc[select] = image_enc[select] * betas[select].reshape(*betas_shape) + \\\n",
1511
+ " image_enc_shuf[select] * (1 - betas[select]).reshape(*betas_shape)\n",
1512
+ "\n",
1513
+ " image_norm = (image - mean)/std\n",
1514
+ " image_aug = (blur_augs(image) - mean)/std\n",
1515
+ " _, cnx_embeds = cnx(image_norm)\n",
1516
+ " _, cnx_aug_embeds = cnx(image_aug)\n",
1517
+ "\n",
1518
+ " cont_loss = utils.soft_cont_loss(\n",
1519
+ " nn.functional.normalize(transformer_feats.reshape(-1, transformer_feats.shape[-1]), dim=-1),\n",
1520
+ " nn.functional.normalize(cnx_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),\n",
1521
+ " nn.functional.normalize(cnx_aug_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),\n",
1522
+ " temp=0.2)\n",
1523
+ " loss_blurry_cont_total += cont_loss.item()\n",
1524
+ "\n",
1525
+ " loss += (loss_blurry + 0.1*cont_loss) * blur_scale #/.18215\n",
1526
+ "\n",
1527
+ " if clip_scale>0:\n",
1528
+ " # forward and backward top 1 accuracy \n",
1529
+ " labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device) \n",
1530
+ " fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()\n",
1531
+ " bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()\n",
1532
+ "\n",
1533
+ " if blurry_recon:\n",
1534
+ " with torch.no_grad():\n",
1535
+ " # only doing pixcorr eval on a subset of the samples per batch because its costly & slow to compute autoenc.decode()\n",
1536
+ " random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)\n",
1537
+ " blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample/ 2 + 0.5).clamp(0,1)\n",
1538
+ " pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)\n",
1539
+ " blurry_pixcorr += pixcorr.item()\n",
1540
+ "\n",
1541
+ " utils.check_loss(loss)\n",
1542
+ " accelerator.backward(loss)\n",
1543
+ " optimizer.step()\n",
1544
+ "\n",
1545
+ " losses.append(loss.item())\n",
1546
+ " lrs.append(optimizer.param_groups[0]['lr'])\n",
1547
+ "\n",
1548
+ " if lr_scheduler_type is not None:\n",
1549
+ " lr_scheduler.step()\n",
1550
+ "\n",
1551
+ " model.eval()\n",
1552
+ " if local_rank==0:\n",
1553
+ " with torch.no_grad(), torch.cuda.amp.autocast(dtype=data_type): \n",
1554
+ " for test_i, (behav, past_behav, future_behav, old_behav) in enumerate(test_dl): \n",
1555
+ " # all test samples should be loaded per batch such that test_i should never exceed 0\n",
1556
+ " assert len(behav) == num_test\n",
1557
+ "\n",
1558
+ " ## Average same-image repeats ##\n",
1559
+ " if test_image is None:\n",
1560
+ " voxel = voxels[f'subj0{subj}'][behav[:,0,5].cpu().long()].unsqueeze(1)\n",
1561
+ " \n",
1562
+ " image = behav[:,0,0].cpu().long()\n",
1563
+ "\n",
1564
+ " unique_image, sort_indices = torch.unique(image, return_inverse=True)\n",
1565
+ " for im in unique_image:\n",
1566
+ " locs = torch.where(im == image)[0]\n",
1567
+ " if len(locs)==1:\n",
1568
+ " locs = locs.repeat(3)\n",
1569
+ " elif len(locs)==2:\n",
1570
+ " locs = locs.repeat(2)[:3]\n",
1571
+ " assert len(locs)==3\n",
1572
+ " if test_image is None:\n",
1573
+ " test_image = torch.Tensor(images[im][None])\n",
1574
+ " test_voxel = voxel[locs][None]\n",
1575
+ " else:\n",
1576
+ " test_image = torch.vstack((test_image, torch.Tensor(images[im][None])))\n",
1577
+ " test_voxel = torch.vstack((test_voxel, voxel[locs][None]))\n",
1578
+ "\n",
1579
+ " loss=0.\n",
1580
+ " \n",
1581
+ " test_indices = torch.arange(len(test_voxel))[:300]\n",
1582
+ " voxel = test_voxel[test_indices].to(device)\n",
1583
+ " image = test_image[test_indices].to(device)\n",
1584
+ " assert len(image) == 300\n",
1585
+ "\n",
1586
+ " clip_target = clip_img_embedder(image.float())\n",
1587
+ "\n",
1588
+ " for rep in range(3):\n",
1589
+ " voxel_ridge = model.ridge(voxel[:,rep],0) # 0th index of subj_list\n",
1590
+ " backbone0, clip_voxels0, blurry_image_enc_ = model.backbone(voxel_ridge)\n",
1591
+ "\n",
1592
+ " logits0 = model.RRClassifier(backbone0.flatten(1))\n",
1593
+ "\n",
1594
+ " if rep==0:\n",
1595
+ " clip_voxels = clip_voxels0\n",
1596
+ " backbone = backbone0\n",
1597
+ " logits = logits0\n",
1598
+ " else:\n",
1599
+ " clip_voxels += clip_voxels0\n",
1600
+ " backbone += backbone0\n",
1601
+ " logits += logits0\n",
1602
+ " clip_voxels /= 3\n",
1603
+ " backbone /= 3\n",
1604
+ " logits /= 3\n",
1605
+ "\n",
1606
+ " print(logits.shape, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).shape)\n",
1607
+ " RR_loss = nn.functional.cross_entropy(logits, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).to(logits.device))\n",
1608
+ " test_loss_RR_total += RR_loss.item()\n",
1609
+ " loss += RR_loss\n",
1610
+ "\n",
1611
+ " if clip_scale>0:\n",
1612
+ " clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)\n",
1613
+ " clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)\n",
1614
+ " \n",
1615
+ " # for some evals, only doing a subset of the samples per batch because of computational cost\n",
1616
+ " random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)\n",
1617
+ " \n",
1618
+ " # if use_prior:\n",
1619
+ " # loss_prior, contaminated_prior_out = model.diffusion_prior(text_embed=backbone[random_samps], image_embed=clip_target[random_samps])\n",
1620
+ " # test_loss_prior_total += loss_prior.item()\n",
1621
+ " # loss_prior *= prior_scale\n",
1622
+ " # loss += loss_prior\n",
1623
+ " \n",
1624
+ " if clip_scale>0:\n",
1625
+ " loss_clip = utils.soft_clip_loss(\n",
1626
+ " clip_voxels_norm,\n",
1627
+ " clip_target_norm,\n",
1628
+ " temp=.006)\n",
1629
+ "\n",
1630
+ " test_loss_clip_total += loss_clip.item()\n",
1631
+ " loss_clip = loss_clip * clip_scale\n",
1632
+ " loss += loss_clip\n",
1633
+ "\n",
1634
+ " if blurry_recon:\n",
1635
+ " image_enc_pred, _ = blurry_image_enc_\n",
1636
+ " blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample / 2 + 0.5).clamp(0,1)\n",
1637
+ " pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)\n",
1638
+ " test_blurry_pixcorr += pixcorr.item()\n",
1639
+ "\n",
1640
+ " if clip_scale>0:\n",
1641
+ " # forward and backward top 1 accuracy \n",
1642
+ " labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device) \n",
1643
+ " test_fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()\n",
1644
+ " test_bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()\n",
1645
+ " \n",
1646
+ " utils.check_loss(loss) \n",
1647
+ " test_losses.append(loss.item())\n",
1648
+ "\n",
1649
+ " assert (test_i+1) == 1\n",
1650
+ " logs = {\"train/loss\": np.mean(losses[-(train_i+1):]),\n",
1651
+ " \"test/loss\": np.mean(test_losses[-(test_i+1):]),\n",
1652
+ " \"train/lr\": lrs[-1],\n",
1653
+ " \"train/num_steps\": len(losses),\n",
1654
+ " \"test/num_steps\": len(test_losses),\n",
1655
+ " \"train/fwd_pct_correct\": fwd_percent_correct / (train_i + 1),\n",
1656
+ " \"train/bwd_pct_correct\": bwd_percent_correct / (train_i + 1),\n",
1657
+ " \"test/test_fwd_pct_correct\": test_fwd_percent_correct / (test_i + 1),\n",
1658
+ " \"test/test_bwd_pct_correct\": test_bwd_percent_correct / (test_i + 1),\n",
1659
+ " \"train/loss_clip_total\": loss_clip_total / (train_i + 1),\n",
1660
+ " \"train/loss_blurry_total\": loss_blurry_total / (train_i + 1),\n",
1661
+ " \"train/loss_blurry_cont_total\": loss_blurry_cont_total / (train_i + 1),\n",
1662
+ " \"test/loss_clip_total\": test_loss_clip_total / (test_i + 1),\n",
1663
+ " \"train/blurry_pixcorr\": blurry_pixcorr / (train_i + 1),\n",
1664
+ " \"test/blurry_pixcorr\": test_blurry_pixcorr / (test_i + 1),\n",
1665
+ " \"train/recon_cossim\": recon_cossim / (train_i + 1),\n",
1666
+ " \"test/recon_cossim\": test_recon_cossim / (test_i + 1),\n",
1667
+ " \"train/recon_mse\": recon_mse / (train_i + 1),\n",
1668
+ " \"test/recon_mse\": test_recon_mse / (test_i + 1),\n",
1669
+ " \"train/loss_prior\": loss_prior_total / (train_i + 1),\n",
1670
+ " \"test/loss_prior\": test_loss_prior_total / (test_i + 1),\n",
1671
+ " \"train/loss_RR\": loss_RR_total / (train_i + 1),\n",
1672
+ " \"test/loss_RR\": test_loss_RR_total / (test_i + 1),\n",
1673
+ " }\n",
1674
+ "\n",
1675
+ " # if finished training, save jpg recons if they exist\n",
1676
+ " if (epoch == num_epochs-1) or (epoch % ckpt_interval == 0):\n",
1677
+ " if blurry_recon: \n",
1678
+ " image_enc = autoenc.encode(2*image[:4]-1).latent_dist.mode() * 0.18215\n",
1679
+ " # transform blurry recon latents to images and plot it\n",
1680
+ " fig, axes = plt.subplots(1, 8, figsize=(10, 4))\n",
1681
+ " jj=-1\n",
1682
+ " for j in [0,1,2,3]:\n",
1683
+ " jj+=1\n",
1684
+ " axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))\n",
1685
+ " axes[jj].axis('off')\n",
1686
+ " jj+=1\n",
1687
+ " axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc_pred[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))\n",
1688
+ " axes[jj].axis('off')\n",
1689
+ "\n",
1690
+ " if wandb_log:\n",
1691
+ " logs[f\"test/blur_recons\"] = wandb.Image(fig, caption=f\"epoch{epoch:03d}\")\n",
1692
+ " plt.close()\n",
1693
+ " else:\n",
1694
+ " plt.show()\n",
1695
+ "\n",
1696
+ " progress_bar.set_postfix(**logs)\n",
1697
+ "\n",
1698
+ " if wandb_log: wandb.log(logs)\n",
1699
+ " \n",
1700
+ " # Save model checkpoint and reconstruct\n",
1701
+ " if (ckpt_saving) and (epoch % ckpt_interval == 0):\n",
1702
+ " save_ckpt(f'last')\n",
1703
+ "\n",
1704
+ " # wait for other GPUs to catch up if needed\n",
1705
+ " accelerator.wait_for_everyone()\n",
1706
+ " torch.cuda.empty_cache()\n",
1707
+ "\n",
1708
+ "print(\"\\n===Finished!===\\n\")\n",
1709
+ "if ckpt_saving:\n",
1710
+ " save_ckpt(f'last')"
1711
+ ]
1712
+ },
1713
+ {
1714
+ "cell_type": "code",
1715
+ "execution_count": null,
1716
+ "id": "a7e81ae3-171f-40ad-a3e8-24bee4472325",
1717
+ "metadata": {
1718
+ "tags": []
1719
+ },
1720
+ "outputs": [],
1721
+ "source": [
1722
+ "plt.plot(losses)\n",
1723
+ "plt.show()\n",
1724
+ "plt.plot(test_losses)\n",
1725
+ "plt.show()"
1726
+ ]
1727
+ },
1728
+ {
1729
+ "cell_type": "code",
1730
+ "execution_count": null,
1731
+ "id": "45d5bc17-0914-43a5-bb4e-d98f0ba238f0",
1732
+ "metadata": {},
1733
+ "outputs": [],
1734
+ "source": [
1735
+ "import wandb\n",
1736
+ "wandb.login()"
1737
+ ]
1738
+ }
1739
+ ],
1740
+ "metadata": {
1741
+ "kernelspec": {
1742
+ "display_name": "Python 3 (ipykernel)",
1743
+ "language": "python",
1744
+ "name": "python3"
1745
+ },
1746
+ "language_info": {
1747
+ "codemirror_mode": {
1748
+ "name": "ipython",
1749
+ "version": 3
1750
+ },
1751
+ "file_extension": ".py",
1752
+ "mimetype": "text/x-python",
1753
+ "name": "python",
1754
+ "nbconvert_exporter": "python",
1755
+ "pygments_lexer": "ipython3",
1756
+ "version": "3.11.9"
1757
+ },
1758
+ "toc": {
1759
+ "base_numbering": 1,
1760
+ "nav_menu": {},
1761
+ "number_sections": true,
1762
+ "sideBar": true,
1763
+ "skip_h1_title": false,
1764
+ "title_cell": "Table of Contents",
1765
+ "title_sidebar": "Contents",
1766
+ "toc_cell": false,
1767
+ "toc_position": {
1768
+ "height": "calc(100% - 180px)",
1769
+ "left": "10px",
1770
+ "top": "150px",
1771
+ "width": "165px"
1772
+ },
1773
+ "toc_section_display": true,
1774
+ "toc_window_display": true
1775
+ },
1776
+ "toc-autonumbering": true,
1777
+ "vscode": {
1778
+ "interpreter": {
1779
+ "hash": "62aae01ef0cf7b6af841ab1c8ce59175c4332e693ab3d00bc32ceffb78a35376"
1780
+ }
1781
+ }
1782
+ },
1783
+ "nbformat": 4,
1784
+ "nbformat_minor": 5
1785
+ }
MindEyeV2/src/TrainCluster.py ADDED
@@ -0,0 +1,1078 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # # Import packages & functions
5
+
6
+ # In[1]:
7
+
8
+
9
+ import os
10
+ import sys
11
+ import json
12
+ import argparse
13
+ import numpy as np
14
+ import math
15
+ from einops import rearrange
16
+ import time
17
+ import random
18
+ import string
19
+ import h5py
20
+ from tqdm import tqdm
21
+ import webdataset as wds
22
+
23
+ import matplotlib.pyplot as plt
24
+ import torch
25
+ import torch.nn as nn
26
+ from torchvision import transforms
27
+ from accelerate import Accelerator
28
+
29
+ # SDXL unCLIP requires code from https://github.com/Stability-AI/generative-models/tree/main
30
+ sys.path.append('generative_models/')
31
+ import sgm
32
+ from generative_models.sgm.modules.encoders.modules import FrozenOpenCLIPImageEmbedder # bigG embedder
33
+
34
+ # tf32 data type is faster than standard float32
35
+ torch.backends.cuda.matmul.allow_tf32 = True
36
+
37
+ # custom functions #
38
+ import utils
39
+
40
+
41
+ # In[2]:
42
+
43
+
44
+ ### Multi-GPU config ###
45
+ local_rank = os.getenv('RANK')
46
+ if local_rank is None:
47
+ local_rank = 0
48
+ else:
49
+ local_rank = int(local_rank)
50
+ print("LOCAL RANK ", local_rank)
51
+
52
+ data_type = torch.float16 # change depending on your mixed_precision
53
+ num_devices = torch.cuda.device_count()
54
+ if num_devices==0: num_devices = 1
55
+
56
+ # First use "accelerate config" in terminal and setup using deepspeed stage 2 with CPU offloading!
57
+ accelerator = Accelerator(split_batches=False, mixed_precision="fp16")
58
+ if utils.is_interactive(): # set batch size here if using interactive notebook instead of submitting job
59
+ global_batch_size = batch_size = 8
60
+ else:
61
+ global_batch_size = os.environ["GLOBAL_BATCH_SIZE"]
62
+ batch_size = int(os.environ["GLOBAL_BATCH_SIZE"]) // num_devices
63
+
64
+
65
+ # In[3]:
66
+
67
+
68
+ print("PID of this process =",os.getpid())
69
+ device = accelerator.device
70
+ print("device:",device)
71
+ world_size = accelerator.state.num_processes
72
+ distributed = not accelerator.state.distributed_type == 'NO'
73
+ num_devices = torch.cuda.device_count()
74
+ if num_devices==0 or not distributed: num_devices = 1
75
+ num_workers = num_devices
76
+ print(accelerator.state)
77
+
78
+ print("distributed =",distributed, "num_devices =", num_devices, "local rank =", local_rank, "world size =", world_size, "data_type =", data_type)
79
+ print = accelerator.print # only print if local_rank=0
80
+
81
+
82
+ # # Configurations
83
+
84
+ # In[4]:
85
+
86
+
87
+ # if running this interactively, can specify jupyter_args here for argparser to use
88
+ if utils.is_interactive():
89
+ model_name = "testing2"
90
+ print("model_name:", model_name)
91
+
92
+ # global_batch_size and batch_size should already be defined in the 2nd cell block
93
+ jupyter_args = f"--data_path=/weka/proj-medarc/shared/mindeyev2_dataset \
94
+ --cache_dir=/weka/proj-medarc/shared/cache \
95
+ --model_name={model_name} \
96
+ --no-multi_subject --subj=1 --batch_size={batch_size} --num_sessions=40 \
97
+ --hidden_dim=1024 --clip_scale=1. \
98
+ --no-blurry_recon --blur_scale=.5 \
99
+ --use_prior --prior_scale=30 \
100
+ --n_blocks=4 --max_lr=3e-5 --mixup_pct=.33 --num_epochs=150 --no-use_image_aug \
101
+ --ckpt_interval=999 --no-ckpt_saving --wandb_log"
102
+ # --multisubject_ckpt=../train_logs/multisubject_subj01_1024_24bs_nolow
103
+
104
+ print(jupyter_args)
105
+ jupyter_args = jupyter_args.split()
106
+
107
+ from IPython.display import clear_output # function to clear print outputs in cell
108
+ get_ipython().run_line_magic('load_ext', 'autoreload')
109
+ # this allows you to change functions in models.py or utils.py and have this notebook automatically update with your revisions
110
+ get_ipython().run_line_magic('autoreload', '2')
111
+
112
+
113
+ # In[5]:
114
+
115
+
116
+ parser = argparse.ArgumentParser(description="Model Training Configuration")
117
+ parser.add_argument(
118
+ "--model_name", type=str, default="testing2",
119
+ help="name of model, used for ckpt saving and wandb logging (if enabled)",
120
+ )
121
+ parser.add_argument(
122
+ "--data_path", type=str, default=os.getcwd(),
123
+ help="Path to where NSD data is stored / where to download it to",
124
+ )
125
+ parser.add_argument(
126
+ "--cache_dir", type=str, default=os.getcwd(),
127
+ help="Path to where misc. files downloaded from huggingface are stored. Defaults to current src directory.",
128
+ )
129
+ parser.add_argument(
130
+ "--subj",type=int, default=1, choices=[1,2,3,4,5,6,7,8],
131
+ help="Validate on which subject?",
132
+ )
133
+ parser.add_argument(
134
+ "--multisubject_ckpt", type=str, default=None,
135
+ help="Path to pre-trained multisubject model to finetune a single subject from. multisubject must be False.",
136
+ )
137
+ parser.add_argument(
138
+ "--num_sessions", type=int, default=1,
139
+ help="Number of training sessions to include",
140
+ )
141
+ parser.add_argument(
142
+ "--use_prior",action=argparse.BooleanOptionalAction,default=True,
143
+ help="whether to train diffusion prior (True) or just rely on retrieval part of the pipeline (False)",
144
+ )
145
+ parser.add_argument(
146
+ "--batch_size", type=int, default=16,
147
+ help="Batch size can be increased by 10x if only training retreival submodule and not diffusion prior",
148
+ )
149
+ parser.add_argument(
150
+ "--wandb_log",action=argparse.BooleanOptionalAction,default=False,
151
+ help="whether to log to wandb",
152
+ )
153
+ parser.add_argument(
154
+ "--wandb_project",type=str,default="stability",
155
+ help="wandb project name",
156
+ )
157
+ parser.add_argument(
158
+ "--mixup_pct",type=float,default=.33,
159
+ help="proportion of way through training when to switch from BiMixCo to SoftCLIP",
160
+ )
161
+ parser.add_argument(
162
+ "--blurry_recon",action=argparse.BooleanOptionalAction,default=True,
163
+ help="whether to output blurry reconstructions",
164
+ )
165
+ parser.add_argument(
166
+ "--blur_scale",type=float,default=.5,
167
+ help="multiply loss from blurry recons by this number",
168
+ )
169
+ parser.add_argument(
170
+ "--clip_scale",type=float,default=1.,
171
+ help="multiply contrastive loss by this number",
172
+ )
173
+ parser.add_argument(
174
+ "--prior_scale",type=float,default=30,
175
+ help="multiply diffusion prior loss by this",
176
+ )
177
+ parser.add_argument(
178
+ "--use_image_aug",action=argparse.BooleanOptionalAction,default=False,
179
+ help="whether to use image augmentation",
180
+ )
181
+ parser.add_argument(
182
+ "--num_epochs",type=int,default=150,
183
+ help="number of epochs of training",
184
+ )
185
+ parser.add_argument(
186
+ "--multi_subject",action=argparse.BooleanOptionalAction,default=False,
187
+ )
188
+ parser.add_argument(
189
+ "--new_test",action=argparse.BooleanOptionalAction,default=True,
190
+ )
191
+ parser.add_argument(
192
+ "--n_blocks",type=int,default=4,
193
+ )
194
+ parser.add_argument(
195
+ "--hidden_dim",type=int,default=1024,
196
+ )
197
+ parser.add_argument(
198
+ "--lr_scheduler_type",type=str,default='cycle',choices=['cycle','linear'],
199
+ )
200
+ parser.add_argument(
201
+ "--ckpt_saving",action=argparse.BooleanOptionalAction,default=True,
202
+ )
203
+ parser.add_argument(
204
+ "--ckpt_interval",type=int,default=5,
205
+ help="save backup ckpt and reconstruct every x epochs",
206
+ )
207
+ parser.add_argument(
208
+ "--seed",type=int,default=42,
209
+ )
210
+ parser.add_argument(
211
+ "--max_lr",type=float,default=3e-5,
212
+ )
213
+
214
+ if utils.is_interactive():
215
+ args = parser.parse_args(jupyter_args)
216
+ else:
217
+ args = parser.parse_args()
218
+
219
+ # create global variables without the args prefix
220
+ for attribute_name in vars(args).keys():
221
+ globals()[attribute_name] = getattr(args, attribute_name)
222
+
223
+ # seed all random functions
224
+ utils.seed_everything(seed)
225
+
226
+ outdir = os.path.abspath(f'../train_logs/{model_name}')
227
+ if not os.path.exists(outdir) and ckpt_saving:
228
+ os.makedirs(outdir,exist_ok=True)
229
+
230
+ if use_image_aug or blurry_recon:
231
+ import kornia
232
+ from kornia.augmentation.container import AugmentationSequential
233
+ if use_image_aug:
234
+ img_augment = AugmentationSequential(
235
+ kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1, p=0.3),
236
+ same_on_batch=False,
237
+ data_keys=["input"],
238
+ )
239
+
240
+ if multi_subject:
241
+ subj_list = np.arange(1,9)
242
+ subj_list = subj_list[subj_list != subj]
243
+ else:
244
+ subj_list = [subj]
245
+
246
+ print("subj_list", subj_list, "num_sessions", num_sessions)
247
+
248
+
249
+ # In[6]:
250
+
251
+
252
+ max_lr
253
+
254
+
255
+ # # Prep data, models, and dataloaders
256
+
257
+ # ### Creating wds dataloader, preload betas and all 73k possible images
258
+
259
+ # In[7]:
260
+
261
+
262
+ def my_split_by_node(urls): return urls
263
+ num_voxels_list = []
264
+
265
+ if multi_subject:
266
+ nsessions_allsubj=np.array([40, 40, 32, 30, 40, 32, 40, 30])
267
+ num_samples_per_epoch = (750*40) // num_devices
268
+ else:
269
+ num_samples_per_epoch = (750*num_sessions) // num_devices
270
+
271
+ print("dividing batch size by subj_list, which will then be concatenated across subj during training...")
272
+ batch_size = batch_size // len(subj_list)
273
+
274
+ num_iterations_per_epoch = num_samples_per_epoch // (batch_size*len(subj_list))
275
+
276
+ print("batch_size =", batch_size, "num_iterations_per_epoch =",num_iterations_per_epoch, "num_samples_per_epoch =",num_samples_per_epoch)
277
+
278
+
279
+ # In[8]:
280
+
281
+
282
+ train_data = {}
283
+ train_dl = {}
284
+ num_voxels = {}
285
+ voxels = {}
286
+ for s in subj_list:
287
+ print(f"Training with {num_sessions} sessions")
288
+ if multi_subject:
289
+ train_url = f"{data_path}/wds/subj0{s}/train/" + "{0.." + f"{nsessions_allsubj[s-1]-1}" + "}.tar"
290
+ else:
291
+ train_url = f"{data_path}/wds/subj0{s}/train/" + "{0.." + f"{num_sessions-1}" + "}.tar"
292
+ print(train_url)
293
+
294
+ train_data[f'subj0{s}'] = wds.WebDataset(train_url,resampled=True,nodesplitter=my_split_by_node)\
295
+ .shuffle(750, initial=1500, rng=random.Random(42))\
296
+ .decode("torch")\
297
+ .rename(behav="behav.npy", past_behav="past_behav.npy", future_behav="future_behav.npy", olds_behav="olds_behav.npy")\
298
+ .to_tuple(*["behav", "past_behav", "future_behav", "olds_behav"])
299
+ train_dl[f'subj0{s}'] = torch.utils.data.DataLoader(train_data[f'subj0{s}'], batch_size=batch_size, shuffle=False, drop_last=False, pin_memory=True)
300
+
301
+ f = h5py.File(f'{data_path}/betas_all_subj0{s}_fp32_renorm.hdf5', 'r')
302
+ betas = f['betas'][:]
303
+ betas = torch.Tensor(betas).to("cpu").to(data_type)
304
+ num_voxels_list.append(betas[0].shape[-1])
305
+ num_voxels[f'subj0{s}'] = betas[0].shape[-1]
306
+ voxels[f'subj0{s}'] = betas
307
+ print(f"num_voxels for subj0{s}: {num_voxels[f'subj0{s}']}")
308
+
309
+ print("Loaded all subj train dls and betas!\n")
310
+
311
+ # Validate only on one subject
312
+ if multi_subject:
313
+ subj = subj_list[0] # cant validate on the actual held out person so picking first in subj_list
314
+ if not new_test: # using old test set from before full dataset released (used in original MindEye paper)
315
+ if subj==3:
316
+ num_test=2113
317
+ elif subj==4:
318
+ num_test=1985
319
+ elif subj==6:
320
+ num_test=2113
321
+ elif subj==8:
322
+ num_test=1985
323
+ else:
324
+ num_test=2770
325
+ test_url = f"{data_path}/wds/subj0{subj}/test/" + "0.tar"
326
+ elif new_test: # using larger test set from after full dataset released
327
+ if subj==3:
328
+ num_test=2371
329
+ elif subj==4:
330
+ num_test=2188
331
+ elif subj==6:
332
+ num_test=2371
333
+ elif subj==8:
334
+ num_test=2188
335
+ else:
336
+ num_test=3000
337
+ test_url = f"{data_path}/wds/subj0{subj}/new_test/" + "0.tar"
338
+ print(test_url)
339
+ test_data = wds.WebDataset(test_url,resampled=False,nodesplitter=my_split_by_node)\
340
+ .shuffle(750, initial=1500, rng=random.Random(42))\
341
+ .decode("torch")\
342
+ .rename(behav="behav.npy", past_behav="past_behav.npy", future_behav="future_behav.npy", olds_behav="olds_behav.npy")\
343
+ .to_tuple(*["behav", "past_behav", "future_behav", "olds_behav"])
344
+ test_dl = torch.utils.data.DataLoader(test_data, batch_size=num_test, shuffle=False, drop_last=True, pin_memory=True)
345
+ print(f"Loaded test dl for subj{subj}!\n")
346
+
347
+
348
+ # In[9]:
349
+
350
+
351
+ # Load 73k NSD images
352
+ f = h5py.File(f'{data_path}/coco_images_224_float16.hdf5', 'r')
353
+ images = f['images']
354
+ print("Loaded all 73k possible NSD images to cpu!", images.shape)
355
+
356
+
357
+ # ## Load models
358
+
359
+ # ### CLIP image embeddings model
360
+
361
+ # In[10]:
362
+
363
+
364
+ clip_img_embedder = FrozenOpenCLIPImageEmbedder(
365
+ arch="ViT-bigG-14",
366
+ version="laion2b_s39b_b160k",
367
+ output_tokens=True,
368
+ only_tokens=True,
369
+ )
370
+ clip_img_embedder.to(device)
371
+
372
+ clip_seq_dim = 256
373
+ clip_emb_dim = 1664
374
+
375
+
376
+ # ### SD VAE
377
+
378
+ # In[11]:
379
+
380
+
381
+ if blurry_recon:
382
+ from diffusers import AutoencoderKL
383
+ autoenc = AutoencoderKL(
384
+ down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D'],
385
+ up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D'],
386
+ block_out_channels=[128, 256, 512, 512],
387
+ layers_per_block=2,
388
+ sample_size=256,
389
+ )
390
+ ckpt = torch.load(f'{cache_dir}/sd_image_var_autoenc.pth')
391
+ autoenc.load_state_dict(ckpt)
392
+
393
+ autoenc.eval()
394
+ autoenc.requires_grad_(False)
395
+ autoenc.to(device)
396
+ utils.count_params(autoenc)
397
+
398
+ from autoencoder.convnext import ConvnextXL
399
+ cnx = ConvnextXL(f'{cache_dir}/convnext_xlarge_alpha0.75_fullckpt.pth')
400
+ cnx.requires_grad_(False)
401
+ cnx.eval()
402
+ cnx.to(device)
403
+
404
+ mean = torch.tensor([0.485, 0.456, 0.406]).to(device).reshape(1,3,1,1)
405
+ std = torch.tensor([0.228, 0.224, 0.225]).to(device).reshape(1,3,1,1)
406
+
407
+ blur_augs = AugmentationSequential(
408
+ kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1, p=0.8),
409
+ kornia.augmentation.RandomGrayscale(p=0.1),
410
+ kornia.augmentation.RandomSolarize(p=0.1),
411
+ kornia.augmentation.RandomResizedCrop((224,224), scale=(.9,.9), ratio=(1,1), p=1.0),
412
+ data_keys=["input"],
413
+ )
414
+
415
+
416
+ # ### MindEye modules
417
+
418
+ # In[12]:
419
+
420
+
421
+ class MindEyeModule(nn.Module):
422
+ def __init__(self):
423
+ super(MindEyeModule, self).__init__()
424
+ def forward(self, x):
425
+ return x
426
+
427
+ model = MindEyeModule()
428
+ model
429
+
430
+
431
+ # In[13]:
432
+
433
+
434
+ class RidgeRegression(torch.nn.Module):
435
+ # make sure to add weight_decay when initializing optimizer to enable regularization
436
+ def __init__(self, input_sizes, out_features):
437
+ super(RidgeRegression, self).__init__()
438
+ self.out_features = out_features
439
+ self.linears = torch.nn.ModuleList([
440
+ torch.nn.Linear(input_size, out_features) for input_size in input_sizes
441
+ ])
442
+ def forward(self, x, subj_idx):
443
+ out = self.linears[subj_idx](x[:,0]).unsqueeze(1)
444
+ return out
445
+
446
+ class IndividRidgeRegression(torch.nn.Module):
447
+ def __init__(self, input_size, out_features):
448
+ super(IndividRidgeRegression, self).__init__()
449
+ self.out_features = out_features
450
+ self.linear = torch.nn.Linear(input_size, out_features)
451
+ def forward(self, x):
452
+ out = self.linear(x)
453
+ return out
454
+
455
+ model.ridge = RidgeRegression(num_voxels_list, out_features=hidden_dim)
456
+ utils.count_params(model.ridge)
457
+ utils.count_params(model)
458
+
459
+ # test on subject 1 with fake data
460
+ b = torch.randn((2,1,num_voxels_list[0]))
461
+ print(b.shape, model.ridge(b,0).shape)
462
+
463
+
464
+ # In[14]:
465
+
466
+
467
+ from models import BrainNetwork
468
+ model.backbone = BrainNetwork(h=hidden_dim, in_dim=hidden_dim, seq_len=1, n_blocks=n_blocks,
469
+ clip_size=clip_emb_dim, out_dim=clip_emb_dim*clip_seq_dim,
470
+ blurry_recon=blurry_recon, clip_scale=clip_scale)
471
+ utils.count_params(model.backbone)
472
+ utils.count_params(model)
473
+
474
+ # test that the model works on some fake data
475
+ b = torch.randn((2,1,hidden_dim))
476
+ print("b.shape",b.shape)
477
+
478
+ backbone_, clip_, blur_ = model.backbone(b)
479
+ print(backbone_.shape, clip_.shape, blur_[0].shape, blur_[1].shape)
480
+
481
+
482
+ # ### Load semantic clusters
483
+
484
+ # In[15]:
485
+
486
+
487
+ path_semantic_names = "/weka/proj-medarc/shared/mindeyev2_dataset/semantic_cluster_names.npy"
488
+ path_semantic_cluster = "/weka/proj-medarc/shared/mindeyev2_dataset/COCO_73k_semantic_cluster.npy"
489
+ semantic_cluster_names = np.load(path_semantic_names)
490
+ semantic_cluster = np.load(path_semantic_cluster)
491
+ possible_semantic_clusters = np.unique(semantic_cluster)
492
+
493
+ # one-hot encode semantic clusters
494
+ # move possible_semantic_clusters to numbers and create a dictionary
495
+ semantic_cluster_dict = {cluster: i for i, cluster in enumerate(possible_semantic_clusters)}
496
+ semantic_cluster_onehot = torch.zeros((len(semantic_cluster), len(possible_semantic_clusters)))
497
+ for i, cluster in enumerate(semantic_cluster):
498
+ semantic_cluster_onehot[i, semantic_cluster_dict[cluster]] = 1
499
+
500
+
501
+ print("semantic_cluster_onehot.shape", semantic_cluster_onehot.shape)
502
+
503
+ num_seman_clusters = len(np.unique(semantic_cluster))
504
+ print("num_seman_clusters", num_seman_clusters)
505
+
506
+
507
+ # ### Adding the ridge regression to the class
508
+
509
+ # In[16]:
510
+
511
+
512
+ # if use_prior:
513
+ # from models import *
514
+
515
+ # # setup diffusion prior network
516
+ # out_dim = clip_emb_dim
517
+ # depth = 6
518
+ # dim_head = 52
519
+ # heads = clip_emb_dim//52 # heads * dim_head = clip_emb_dim
520
+ # timesteps = 100
521
+
522
+ # prior_network = PriorNetwork(
523
+ # dim=out_dim,
524
+ # depth=depth,
525
+ # dim_head=dim_head,
526
+ # heads=heads,
527
+ # causal=False,
528
+ # num_tokens = clip_seq_dim,
529
+ # learned_query_mode="pos_emb"
530
+ # )
531
+
532
+ # model.diffusion_prior = BrainDiffusionPrior(
533
+ # net=prior_network,
534
+ # image_embed_dim=out_dim,
535
+ # condition_on_text_encodings=False,
536
+ # timesteps=timesteps,
537
+ # cond_drop_prob=0.2,
538
+ # image_embed_scale=None,
539
+ # )
540
+
541
+ # utils.count_params(model.diffusion_prior)
542
+ # utils.count_params(model)
543
+
544
+ model.RRClassifier = IndividRidgeRegression(clip_emb_dim*clip_seq_dim, out_features=num_seman_clusters)
545
+ utils.count_params(model.RRClassifier)
546
+ utils.count_params(model)
547
+
548
+
549
+ # ### Setup optimizer / lr / ckpt saving
550
+
551
+ # In[17]:
552
+
553
+
554
+ no_decay = ['bias', 'LayerNorm.bias', 'LayerNorm.weight']
555
+
556
+ opt_grouped_parameters = [
557
+ {'params': [p for n, p in model.ridge.named_parameters()], 'weight_decay': 1e-2},
558
+ {'params': [p for n, p in model.backbone.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},
559
+ {'params': [p for n, p in model.backbone.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0},
560
+ ]
561
+ # if use_prior:
562
+ # opt_grouped_parameters.extend([
563
+ # {'params': [p for n, p in model.diffusion_prior.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},
564
+ # {'params': [p for n, p in model.diffusion_prior.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0}
565
+ # ])
566
+ opt_grouped_parameters.extend([
567
+ {'params': [p for n, p in model.RRClassifier.named_parameters()], 'weight_decay': 1e-2},
568
+ ])
569
+
570
+ optimizer = torch.optim.AdamW(opt_grouped_parameters, lr=max_lr)
571
+
572
+ if lr_scheduler_type == 'linear':
573
+ lr_scheduler = torch.optim.lr_scheduler.LinearLR(
574
+ optimizer,
575
+ total_iters=int(np.floor(num_epochs*num_iterations_per_epoch)),
576
+ last_epoch=-1
577
+ )
578
+ elif lr_scheduler_type == 'cycle':
579
+ total_steps=int(np.floor(num_epochs*num_iterations_per_epoch))
580
+ print("total_steps", total_steps)
581
+ lr_scheduler = torch.optim.lr_scheduler.OneCycleLR(
582
+ optimizer,
583
+ max_lr=max_lr,
584
+ total_steps=total_steps,
585
+ final_div_factor=1000,
586
+ last_epoch=-1, pct_start=2/num_epochs
587
+ )
588
+
589
+ def save_ckpt(tag):
590
+ ckpt_path = outdir+f'/{tag}.pth'
591
+ if accelerator.is_main_process:
592
+ unwrapped_model = accelerator.unwrap_model(model)
593
+ torch.save({
594
+ 'epoch': epoch,
595
+ 'model_state_dict': unwrapped_model.state_dict(),
596
+ 'optimizer_state_dict': optimizer.state_dict(),
597
+ 'lr_scheduler': lr_scheduler.state_dict(),
598
+ 'train_losses': losses,
599
+ 'test_losses': test_losses,
600
+ 'lrs': lrs,
601
+ }, ckpt_path)
602
+ print(f"\n---saved {outdir}/{tag} ckpt!---\n")
603
+
604
+ def load_ckpt(tag,load_lr=True,load_optimizer=True,load_epoch=True,strict=True,outdir=outdir,multisubj_loading=False):
605
+ print(f"\n---loading {outdir}/{tag}.pth ckpt---\n")
606
+ checkpoint = torch.load(outdir+'/last.pth', map_location='cpu')
607
+ state_dict = checkpoint['model_state_dict']
608
+ if multisubj_loading: # remove incompatible ridge layer that will otherwise error
609
+ state_dict.pop('ridge.linears.0.weight',None)
610
+ model.load_state_dict(state_dict, strict=strict)
611
+ if load_epoch:
612
+ globals()["epoch"] = checkpoint['epoch']
613
+ print("Epoch",epoch)
614
+ if load_optimizer:
615
+ optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
616
+ if load_lr:
617
+ lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])
618
+ del checkpoint
619
+
620
+ print("\nDone with model preparations!")
621
+ num_params = utils.count_params(model)
622
+
623
+
624
+ # # Weights and Biases
625
+
626
+ # In[18]:
627
+
628
+
629
+ if local_rank==0 and wandb_log: # only use main process for wandb logging
630
+ import wandb
631
+ wandb_project = 'mindeye_semantic_cluster'
632
+ print(f"wandb {wandb_project} run {model_name}")
633
+ # need to configure wandb beforehand in terminal with "wandb init"!
634
+ wandb_config = {
635
+ "model_name": model_name,
636
+ "global_batch_size": global_batch_size,
637
+ "batch_size": batch_size,
638
+ "num_epochs": num_epochs,
639
+ "num_sessions": num_sessions,
640
+ "num_params": num_params,
641
+ "clip_scale": clip_scale,
642
+ "prior_scale": prior_scale,
643
+ "blur_scale": blur_scale,
644
+ "use_image_aug": use_image_aug,
645
+ "max_lr": max_lr,
646
+ "mixup_pct": mixup_pct,
647
+ "num_samples_per_epoch": num_samples_per_epoch,
648
+ "num_test": num_test,
649
+ "ckpt_interval": ckpt_interval,
650
+ "ckpt_saving": ckpt_saving,
651
+ "seed": seed,
652
+ "distributed": distributed,
653
+ "num_devices": num_devices,
654
+ "world_size": world_size,
655
+ "train_url": train_url,
656
+ "test_url": test_url,
657
+ }
658
+ print("wandb_config:\n",wandb_config)
659
+ print("wandb_id:",model_name)
660
+ wandb.login(host='https://stability.wandb.io')
661
+ wandb.init(
662
+ id=model_name,
663
+ project=wandb_project,
664
+ name=model_name,
665
+ config=wandb_config,
666
+ resume="allow",
667
+ )
668
+ else:
669
+ wandb_log = False
670
+
671
+
672
+ # # Main
673
+
674
+ # In[19]:
675
+
676
+
677
+ epoch = 0
678
+ losses, test_losses, lrs = [], [], []
679
+ best_test_loss = 1e9
680
+ torch.cuda.empty_cache()
681
+
682
+
683
+ # In[20]:
684
+
685
+
686
+ # load multisubject stage1 ckpt if set
687
+ if multisubject_ckpt is not None:
688
+ load_ckpt("last",outdir=multisubject_ckpt,load_lr=False,load_optimizer=False,load_epoch=False,strict=False,multisubj_loading=True)
689
+
690
+
691
+ # In[21]:
692
+
693
+
694
+ train_dls = [train_dl[f'subj0{s}'] for s in subj_list]
695
+
696
+ model, optimizer, *train_dls, lr_scheduler, semantic_cluster_onehot = accelerator.prepare(model, optimizer, *train_dls, lr_scheduler, semantic_cluster_onehot)
697
+ # leaving out test_dl since we will only have local_rank 0 device do evals
698
+
699
+
700
+ # In[22]:
701
+
702
+
703
+ print(num_iterations_per_epoch)
704
+
705
+
706
+ # In[ ]:
707
+
708
+
709
+ print(f"{model_name} starting with epoch {epoch} / {num_epochs}")
710
+ progress_bar = tqdm(range(epoch,num_epochs), ncols=1200, disable=(local_rank!=0))
711
+ test_image, test_voxel = None, None
712
+ mse = nn.MSELoss()
713
+ l1 = nn.L1Loss()
714
+ soft_loss_temps = utils.cosine_anneal(0.004, 0.0075, num_epochs - int(mixup_pct * num_epochs))
715
+
716
+ for epoch in progress_bar:
717
+ model.train()
718
+
719
+ fwd_percent_correct = 0.
720
+ bwd_percent_correct = 0.
721
+ test_fwd_percent_correct = 0.
722
+ test_bwd_percent_correct = 0.
723
+
724
+ recon_cossim = 0.
725
+ test_recon_cossim = 0.
726
+ recon_mse = 0.
727
+ test_recon_mse = 0.
728
+
729
+ loss_clip_total = 0.
730
+ loss_blurry_total = 0.
731
+ loss_blurry_cont_total = 0.
732
+ test_loss_clip_total = 0.
733
+
734
+ loss_prior_total = 0.
735
+ test_loss_prior_total = 0.
736
+
737
+ loss_RR_total = 0.
738
+ test_loss_RR_total = 0.
739
+
740
+ blurry_pixcorr = 0.
741
+ test_blurry_pixcorr = 0. # needs >.456 to beat low-level subj01 results in mindeye v1
742
+
743
+ # pre-load all batches for this epoch (it's MUCH faster to pre-load in bulk than to separate loading per batch)
744
+ voxel_iters = {} # empty dict because diff subjects have differing # of voxels
745
+ image_iters = torch.zeros(num_iterations_per_epoch, batch_size*len(subj_list), 3, 224, 224).float()
746
+ annot_iters = {}
747
+ perm_iters, betas_iters, select_iters = {}, {}, {}
748
+ images_indexes = {}
749
+ for s, train_dl in enumerate(train_dls):
750
+ with torch.cuda.amp.autocast(dtype=data_type):
751
+ iter = -1
752
+ for behav0, past_behav0, future_behav0, old_behav0 in train_dl:
753
+ # Load images to cpu from hdf5 (requires sorted indexing)
754
+ image_idx = behav0[:,0,0].cpu().long().numpy()
755
+
756
+ image0, image_sorted_idx = np.unique(image_idx, return_index=True)
757
+ if len(image0) != len(image_idx): # hdf5 cant handle duplicate indexing
758
+ continue
759
+ iter += 1
760
+ image0 = torch.tensor(images[image0], dtype=data_type)
761
+ image_iters[iter,s*batch_size:s*batch_size+batch_size] = image0
762
+ images_indexes[f"subj0{s}_iter{iter}"] = image_sorted_idx
763
+
764
+ # Load voxels for current batch, matching above indexing
765
+ voxel_idx = behav0[:,0,5].cpu().long().numpy()
766
+ voxel_sorted_idx = voxel_idx[image_sorted_idx]
767
+ voxel0 = voxels[f'subj0{subj_list[s]}'][voxel_sorted_idx]
768
+ voxel0 = torch.Tensor(voxel0).unsqueeze(1)
769
+
770
+ if epoch < int(mixup_pct * num_epochs):
771
+ voxel0, perm, betas, select = utils.mixco(voxel0)
772
+ perm_iters[f"subj0{subj_list[s]}_iter{iter}"] = perm
773
+ betas_iters[f"subj0{subj_list[s]}_iter{iter}"] = betas
774
+ select_iters[f"subj0{subj_list[s]}_iter{iter}"] = select
775
+
776
+ voxel_iters[f"subj0{subj_list[s]}_iter{iter}"] = voxel0
777
+
778
+ if iter >= num_iterations_per_epoch-1:
779
+ break
780
+
781
+ # you now have voxel_iters and image_iters with num_iterations_per_epoch batches each
782
+ for train_i in range(num_iterations_per_epoch):
783
+ with torch.cuda.amp.autocast(dtype=data_type):
784
+ optimizer.zero_grad()
785
+ loss=0.
786
+
787
+ voxel_list = [voxel_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
788
+ image = image_iters[train_i].detach()
789
+ image = image.to(device)
790
+
791
+ if use_image_aug:
792
+ image = img_augment(image)
793
+
794
+ clip_target = clip_img_embedder(image)
795
+ assert not torch.any(torch.isnan(clip_target))
796
+
797
+ if epoch < int(mixup_pct * num_epochs):
798
+ perm_list = [perm_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
799
+ perm = torch.cat(perm_list, dim=0)
800
+ betas_list = [betas_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
801
+ betas = torch.cat(betas_list, dim=0)
802
+ select_list = [select_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
803
+ select = torch.cat(select_list, dim=0)
804
+
805
+ voxel_ridge_list = [model.ridge(voxel_list[si],si) for si,s in enumerate(subj_list)]
806
+ voxel_ridge = torch.cat(voxel_ridge_list, dim=0)
807
+
808
+ backbone, clip_voxels, blurry_image_enc_ = model.backbone(voxel_ridge)
809
+
810
+ if clip_scale>0:
811
+ clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)
812
+ clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)
813
+
814
+ # if use_prior:
815
+ # loss_prior, prior_out = model.diffusion_prior(text_embed=backbone, image_embed=clip_target)
816
+ # loss_prior_total += loss_prior.item()
817
+ # loss_prior *= prior_scale
818
+ # loss += loss_prior
819
+
820
+ # recon_cossim += nn.functional.cosine_similarity(prior_out, clip_target).mean().item()
821
+ # recon_mse += mse(prior_out, clip_target).item()
822
+
823
+ logits = model.RRClassifier(backbone.flatten(1))
824
+ #print(logits.shape, torch.argmax(semantic_cluster_onehot[images_indexes[f"subj0{s}_iter{train_i}"]], dim=1).shape)
825
+ #print(logits, torch.argmax(semantic_cluster_onehot[images_indexes[f"subj0{s}_iter{train_i}"]], dim=1))
826
+ loss_RR = nn.functional.cross_entropy(logits, torch.argmax(semantic_cluster_onehot[images_indexes[f"subj0{s}_iter{train_i}"]], dim=1).to(logits.device))
827
+ #print("backbone.shape",backbone.shape, "clip_voxels.shape",clip_voxels.shape, "blurry_image_enc_[0].shape",blurry_image_enc_[0].shape, "blurry_image_enc_[1].shape",blurry_image_enc_[1].shape)
828
+ #something
829
+
830
+ loss_RR_total += loss_RR.item()
831
+ loss += loss_RR
832
+
833
+ if clip_scale>0:
834
+ if epoch < int(mixup_pct * num_epochs):
835
+ loss_clip = utils.mixco_nce(
836
+ clip_voxels_norm,
837
+ clip_target_norm,
838
+ temp=.006,
839
+ perm=perm, betas=betas, select=select)
840
+ else:
841
+ epoch_temp = soft_loss_temps[epoch-int(mixup_pct*num_epochs)]
842
+ loss_clip = utils.soft_clip_loss(
843
+ clip_voxels_norm,
844
+ clip_target_norm,
845
+ temp=epoch_temp)
846
+
847
+ loss_clip_total += loss_clip.item()
848
+ loss_clip *= clip_scale
849
+ loss += loss_clip
850
+
851
+ if blurry_recon:
852
+ image_enc_pred, transformer_feats = blurry_image_enc_
853
+
854
+ image_enc = autoenc.encode(2*image-1).latent_dist.mode() * 0.18215
855
+ loss_blurry = l1(image_enc_pred, image_enc)
856
+ loss_blurry_total += loss_blurry.item()
857
+
858
+ if epoch < int(mixup_pct * num_epochs):
859
+ image_enc_shuf = image_enc[perm]
860
+ betas_shape = [-1] + [1]*(len(image_enc.shape)-1)
861
+ image_enc[select] = image_enc[select] * betas[select].reshape(*betas_shape) + \
862
+ image_enc_shuf[select] * (1 - betas[select]).reshape(*betas_shape)
863
+
864
+ image_norm = (image - mean)/std
865
+ image_aug = (blur_augs(image) - mean)/std
866
+ _, cnx_embeds = cnx(image_norm)
867
+ _, cnx_aug_embeds = cnx(image_aug)
868
+
869
+ cont_loss = utils.soft_cont_loss(
870
+ nn.functional.normalize(transformer_feats.reshape(-1, transformer_feats.shape[-1]), dim=-1),
871
+ nn.functional.normalize(cnx_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),
872
+ nn.functional.normalize(cnx_aug_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),
873
+ temp=0.2)
874
+ loss_blurry_cont_total += cont_loss.item()
875
+
876
+ loss += (loss_blurry + 0.1*cont_loss) * blur_scale #/.18215
877
+
878
+ if clip_scale>0:
879
+ # forward and backward top 1 accuracy
880
+ labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device)
881
+ fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()
882
+ bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()
883
+
884
+ if blurry_recon:
885
+ with torch.no_grad():
886
+ # only doing pixcorr eval on a subset of the samples per batch because its costly & slow to compute autoenc.decode()
887
+ random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)
888
+ blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample/ 2 + 0.5).clamp(0,1)
889
+ pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)
890
+ blurry_pixcorr += pixcorr.item()
891
+
892
+ utils.check_loss(loss)
893
+ accelerator.backward(loss)
894
+ optimizer.step()
895
+
896
+ losses.append(loss.item())
897
+ lrs.append(optimizer.param_groups[0]['lr'])
898
+
899
+ if lr_scheduler_type is not None:
900
+ lr_scheduler.step()
901
+
902
+ model.eval()
903
+ if local_rank==0:
904
+ with torch.no_grad(), torch.cuda.amp.autocast(dtype=data_type):
905
+ for test_i, (behav, past_behav, future_behav, old_behav) in enumerate(test_dl):
906
+ # all test samples should be loaded per batch such that test_i should never exceed 0
907
+ assert len(behav) == num_test
908
+
909
+ ## Average same-image repeats ##
910
+ if test_image is None:
911
+ voxel = voxels[f'subj0{subj}'][behav[:,0,5].cpu().long()].unsqueeze(1)
912
+
913
+ image = behav[:,0,0].cpu().long()
914
+
915
+ unique_image, sort_indices = torch.unique(image, return_inverse=True)
916
+ for im in unique_image:
917
+ locs = torch.where(im == image)[0]
918
+ if len(locs)==1:
919
+ locs = locs.repeat(3)
920
+ elif len(locs)==2:
921
+ locs = locs.repeat(2)[:3]
922
+ assert len(locs)==3
923
+ if test_image is None:
924
+ test_image = torch.Tensor(images[im][None])
925
+ test_voxel = voxel[locs][None]
926
+ else:
927
+ test_image = torch.vstack((test_image, torch.Tensor(images[im][None])))
928
+ test_voxel = torch.vstack((test_voxel, voxel[locs][None]))
929
+
930
+ loss=0.
931
+
932
+ test_indices = torch.arange(len(test_voxel))[:300]
933
+ voxel = test_voxel[test_indices].to(device)
934
+ image = test_image[test_indices].to(device)
935
+ assert len(image) == 300
936
+
937
+ clip_target = clip_img_embedder(image.float())
938
+
939
+ for rep in range(3):
940
+ voxel_ridge = model.ridge(voxel[:,rep],0) # 0th index of subj_list
941
+ backbone0, clip_voxels0, blurry_image_enc_ = model.backbone(voxel_ridge)
942
+
943
+ logits0 = model.RRClassifier(backbone0.flatten(1))
944
+
945
+ if rep==0:
946
+ clip_voxels = clip_voxels0
947
+ backbone = backbone0
948
+ logits = logits0
949
+ else:
950
+ clip_voxels += clip_voxels0
951
+ backbone += backbone0
952
+ logits += logits0
953
+ clip_voxels /= 3
954
+ backbone /= 3
955
+ logits /= 3
956
+
957
+ print(logits.shape, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).shape)
958
+ RR_loss = nn.functional.cross_entropy(logits, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).to(logits.device))
959
+ test_loss_RR_total += RR_loss.item()
960
+ loss += RR_loss
961
+
962
+ if clip_scale>0:
963
+ clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)
964
+ clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)
965
+
966
+ # for some evals, only doing a subset of the samples per batch because of computational cost
967
+ random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)
968
+
969
+ # if use_prior:
970
+ # loss_prior, contaminated_prior_out = model.diffusion_prior(text_embed=backbone[random_samps], image_embed=clip_target[random_samps])
971
+ # test_loss_prior_total += loss_prior.item()
972
+ # loss_prior *= prior_scale
973
+ # loss += loss_prior
974
+
975
+ if clip_scale>0:
976
+ loss_clip = utils.soft_clip_loss(
977
+ clip_voxels_norm,
978
+ clip_target_norm,
979
+ temp=.006)
980
+
981
+ test_loss_clip_total += loss_clip.item()
982
+ loss_clip = loss_clip * clip_scale
983
+ loss += loss_clip
984
+
985
+ if blurry_recon:
986
+ image_enc_pred, _ = blurry_image_enc_
987
+ blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample / 2 + 0.5).clamp(0,1)
988
+ pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)
989
+ test_blurry_pixcorr += pixcorr.item()
990
+
991
+ if clip_scale>0:
992
+ # forward and backward top 1 accuracy
993
+ labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device)
994
+ test_fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()
995
+ test_bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()
996
+
997
+ utils.check_loss(loss)
998
+ test_losses.append(loss.item())
999
+
1000
+ assert (test_i+1) == 1
1001
+ logs = {"train/loss": np.mean(losses[-(train_i+1):]),
1002
+ "test/loss": np.mean(test_losses[-(test_i+1):]),
1003
+ "train/lr": lrs[-1],
1004
+ "train/num_steps": len(losses),
1005
+ "test/num_steps": len(test_losses),
1006
+ "train/fwd_pct_correct": fwd_percent_correct / (train_i + 1),
1007
+ "train/bwd_pct_correct": bwd_percent_correct / (train_i + 1),
1008
+ "test/test_fwd_pct_correct": test_fwd_percent_correct / (test_i + 1),
1009
+ "test/test_bwd_pct_correct": test_bwd_percent_correct / (test_i + 1),
1010
+ "train/loss_clip_total": loss_clip_total / (train_i + 1),
1011
+ "train/loss_blurry_total": loss_blurry_total / (train_i + 1),
1012
+ "train/loss_blurry_cont_total": loss_blurry_cont_total / (train_i + 1),
1013
+ "test/loss_clip_total": test_loss_clip_total / (test_i + 1),
1014
+ "train/blurry_pixcorr": blurry_pixcorr / (train_i + 1),
1015
+ "test/blurry_pixcorr": test_blurry_pixcorr / (test_i + 1),
1016
+ "train/recon_cossim": recon_cossim / (train_i + 1),
1017
+ "test/recon_cossim": test_recon_cossim / (test_i + 1),
1018
+ "train/recon_mse": recon_mse / (train_i + 1),
1019
+ "test/recon_mse": test_recon_mse / (test_i + 1),
1020
+ "train/loss_prior": loss_prior_total / (train_i + 1),
1021
+ "test/loss_prior": test_loss_prior_total / (test_i + 1),
1022
+ "train/loss_RR": loss_RR_total / (train_i + 1),
1023
+ "test/loss_RR": test_loss_RR_total / (test_i + 1),
1024
+ }
1025
+
1026
+ # if finished training, save jpg recons if they exist
1027
+ if (epoch == num_epochs-1) or (epoch % ckpt_interval == 0):
1028
+ if blurry_recon:
1029
+ image_enc = autoenc.encode(2*image[:4]-1).latent_dist.mode() * 0.18215
1030
+ # transform blurry recon latents to images and plot it
1031
+ fig, axes = plt.subplots(1, 8, figsize=(10, 4))
1032
+ jj=-1
1033
+ for j in [0,1,2,3]:
1034
+ jj+=1
1035
+ axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))
1036
+ axes[jj].axis('off')
1037
+ jj+=1
1038
+ axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc_pred[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))
1039
+ axes[jj].axis('off')
1040
+
1041
+ if wandb_log:
1042
+ logs[f"test/blur_recons"] = wandb.Image(fig, caption=f"epoch{epoch:03d}")
1043
+ plt.close()
1044
+ else:
1045
+ plt.show()
1046
+
1047
+ progress_bar.set_postfix(**logs)
1048
+
1049
+ if wandb_log: wandb.log(logs)
1050
+
1051
+ # Save model checkpoint and reconstruct
1052
+ if (ckpt_saving) and (epoch % ckpt_interval == 0):
1053
+ save_ckpt(f'last')
1054
+
1055
+ # wait for other GPUs to catch up if needed
1056
+ accelerator.wait_for_everyone()
1057
+ torch.cuda.empty_cache()
1058
+
1059
+ print("\n===Finished!===\n")
1060
+ if ckpt_saving:
1061
+ save_ckpt(f'last')
1062
+
1063
+
1064
+ # In[ ]:
1065
+
1066
+
1067
+ plt.plot(losses)
1068
+ plt.show()
1069
+ plt.plot(test_losses)
1070
+ plt.show()
1071
+
1072
+
1073
+ # In[ ]:
1074
+
1075
+
1076
+ import wandb
1077
+ wandb.login()
1078
+
MindEyeV2/src/accel.slurm ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --account=fmri
3
+ #SBATCH --qos=normal
4
+ #SBATCH --partition=p5
5
+ #SBATCH --job-name=eyeRR
6
+ #SBATCH --nodes=1
7
+ #SBATCH --gres=gpu:1
8
+ #SBATCH --time=48:00:00 # total run time limit (HH:MM:SS)
9
+ #SBATCH -e slurms/%j.err # first create a "slurms" folder in current directory to store logs
10
+ #SBATCH -o slurms/%j.out
11
+ #SBATCH --comment=medarc
12
+ #SBATCH --no-requeue
13
+ #SBATCH --exclusive
14
+
15
+ # Make sure you activate your fmri environment created from src/setup.sh
16
+ cd /weka/proj-fmri/ckadirt/MindEyeV2/src
17
+ source /admin/home-ckadirt/fmri/bin/activate
18
+
19
+ # The following line converts your jupyter notebook into a python script runnable with Slurm
20
+ jupyter nbconvert TrainCluster-Copy2.ipynb --to python
21
+
22
+ export NUM_GPUS=1 # Set to equal gres=gpu:#!
23
+ export BATCH_SIZE=21 # 21 for multisubject / 24 for singlesubject (orig. paper used 42 for multisubject / 24 for singlesubject)
24
+ export GLOBAL_BATCH_SIZE=$((BATCH_SIZE * NUM_GPUS))
25
+
26
+ # Make sure another job doesnt use same port, here using random number
27
+ export MASTER_PORT=$((RANDOM % (19000 - 11000 + 1) + 11000))
28
+ export HOSTNAMES=$(scontrol show hostnames "$SLURM_JOB_NODELIST")
29
+ export MASTER_ADDR=$(scontrol show hostnames "$SLURM_JOB_NODELIST" | head -n 1)
30
+ export COUNT_NODE=1 #$(scontrol show hostnames "$SLURM_JOB_NODELIST" | wc -l)
31
+ echo MASTER_ADDR=${MASTER_ADDR}
32
+ echo MASTER_PORT=${MASTER_PORT}
33
+ echo WORLD_SIZE=${COUNT_NODE}
34
+
35
+ # multisubject pretraining
36
+ model_name="rr-test-top"
37
+ echo model_name=${model_name}
38
+ # accelerate launch --num_processes=$(($NUM_GPUS * $COUNT_NODE)) --num_machines=$COUNT_NODE --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --mixed_precision=fp16 TrainCluster.py --data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=${model_name} --multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
39
+ python TrainCluster-Copy2.py --data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=${model_name} --no-multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-5 --mixup_pct=.33 --num_epochs=150 --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
40
+ # singlesubject finetuning
41
+ #model_name="finetuned_subj01_40sess"
42
+ #echo model_name=${model_name}
43
+ #accelerate launch --num_processes=$(($NUM_GPUS * $COUNT_NODE)) --num_machines=$COUNT_NODE --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --mixed_precision=fp16 Train.py --data_path=/weka/proj-fmri/shared/mindeyev2_dataset --cache_dir=/weka/proj-fmri/shared/cache --model_name=${model_name} --no-multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --use_prior --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log --multisubject_ckpt=../train_logs/multisubject_excludingsubj01_40sess
MindEyeV2/src/accelSM.slurm ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --account=fmri
3
+ #SBATCH --qos=normal
4
+ #SBATCH --partition=p5
5
+ #SBATCH --job-name=sm_p_msub_0.33
6
+ #SBATCH --nodes=1
7
+ #SBATCH --gres=gpu:1
8
+ #SBATCH --time=48:00:00 # total run time limit (HH:MM:SS)
9
+ #SBATCH -e slurms/%j.err # first create a "slurms" folder in current directory to store logs
10
+ #SBATCH -o slurms/%j.out
11
+ #SBATCH --comment=medarc
12
+ #SBATCH --no-requeue
13
+
14
+ # Make sure you activate your fmri environment created from src/setup.sh
15
+ cd /weka/proj-fmri/ckadirt/MindEyeV2/src
16
+ source /admin/home-ckadirt/fmri/bin/activate
17
+
18
+ # The following line converts your jupyter notebook into a python script runnable with Slurm
19
+ jupyter nbconvert train_semantic_cluster.ipynb --to python
20
+
21
+ export NUM_GPUS=1 # Set to equal gres=gpu:#!
22
+ export BATCH_SIZE=21 # 21 for multisubject / 24 for singlesubject (orig. paper used 42 for multisubject / 24 for singlesubject)
23
+ export GLOBAL_BATCH_SIZE=$((BATCH_SIZE * NUM_GPUS))
24
+
25
+ # Make sure another job doesnt use same port, here using random number
26
+ export MASTER_PORT=$((RANDOM % (19000 - 11000 + 1) + 11000))
27
+ export HOSTNAMES=$(scontrol show hostnames "$SLURM_JOB_NODELIST")
28
+ export MASTER_ADDR=$(scontrol show hostnames "$SLURM_JOB_NODELIST" | head -n 1)
29
+ export COUNT_NODE=1 #$(scontrol show hostnames "$SLURM_JOB_NODELIST" | wc -l)
30
+ echo MASTER_ADDR=${MASTER_ADDR}
31
+ echo MASTER_PORT=${MASTER_PORT}
32
+ echo WORLD_SIZE=${COUNT_NODE}
33
+
34
+ # multisubject pretraining
35
+ model_name="semantic_cluster_1.2_average_after_wd-2_prior_multi"
36
+ echo model_name=${model_name}
37
+ # accelerate launch --num_processes=$(($NUM_GPUS * $COUNT_NODE)) --num_machines=$COUNT_NODE --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --mixed_precision=fp16 TrainCluster.py --data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=${model_name} --multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
38
+ python Untitled1.py --data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=${model_name} --multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-5 --mixup_pct=.33 --num_epochs=150 --prior_scale=30 --clip_scale=1 --no-blurry_recon --use_prior --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
39
+ # singlesubject finetuning
40
+ #model_name="finetuned_subj01_40sess"
41
+ #echo model_name=${model_name}
42
+ #accelerate launch --num_processes=$(($NUM_GPUS * $COUNT_NODE)) --num_machines=$COUNT_NODE --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --mixed_precision=fp16 Train.py --data_path=/weka/proj-fmri/shared/mindeyev2_dataset --cache_dir=/weka/proj-fmri/shared/cache --model_name=${model_name} --no-multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --use_prior --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log --multisubject_ckpt=../train_logs/multisubject_excludingsubj01_40sess
MindEyeV2/src/accel_recon_imagery.slurm ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --account=fmri
3
+ #SBATCH --partition=p5
4
+ #SBATCH --job-name=me2_imagery
5
+ #SBATCH --ntasks-per-node=1
6
+ #SBATCH --nodes=1
7
+ #SBATCH --gres=gpu:1
8
+ #SBATCH --gpus-per-task=1 # Set to equal gres=gpu:#
9
+ #SBATCH --time=72:00:00 # Total run time limit (HH:MM:SS)
10
+ #SBATCH -e slurms/%j.err # Ensure "slurms" directory exists for logs
11
+ #SBATCH -o slurms/%j.out
12
+ #SBATCH --comment=medarc
13
+ #SBATCH --no-requeue
14
+ #SBATCH --qos=idle
15
+ #SBATCH --dependency=afterok:534007
16
+
17
+ source ~/.bashrc
18
+ source /admin/home-ckadirt/fmri/bin/activate
19
+ cd /weka/proj-fmri/ckadirt/MindEyeV2/src/
20
+
21
+
22
+ # Set up networking environment variables to avoid port conflicts
23
+ export MASTER_PORT=$((RANDOM % (19000 - 11000 + 1) + 11000))
24
+ export HOSTNAMES=$(scontrol show hostnames "$SLURM_JOB_NODELIST")
25
+ export MASTER_ADDR=$(echo "$HOSTNAMES" | head -n 1)
26
+ echo "MASTER_ADDR=${MASTER_ADDR}"
27
+ echo "MASTER_PORT=${MASTER_PORT}"
28
+
29
+ export MODULEPATH=/opt/amazon/modules/modulefiles:$MODULEPATH
30
+
31
+ jupyter nbconvert enhanced_recon_inference.ipynb --to python
32
+ jupyter nbconvert recon_inference.ipynb --to python
33
+
34
+ # jupyter nbconvert final_evaluations_mi_multi_icnn.ipynb --to python
35
+
36
+
37
+ for subj in 1; do
38
+ for num_sessions in 2 3 5 10 20 40; do
39
+ model_name="final_subj0${subj}_pretrained_${num_sessions}sess_24bs"
40
+ echo ${model_name}
41
+ echo "new_sessions"
42
+
43
+ for mode in "imagery" "vision"; do #
44
+
45
+ python recon_inference.py \
46
+ --data_path=/weka/proj-medarc/shared/mindeyev2_dataset \
47
+ --cache_dir=/weka/proj-medarc/shared/mindeyev2_dataset \
48
+ --model_name="${model_name}" --subj=1 \
49
+ --hidden_dim=4096 --n_blocks=4 --new_test \
50
+ --mode="${mode}" \
51
+ --imagery_data_path=/weka/proj-medarc/shared/umn-imagery
52
+
53
+ python enhanced_recon_inference.py \
54
+ --model_name="${model_name}" --subj=1 --mode="${mode}"
55
+
56
+ done
57
+ done
58
+ done
MindEyeV2/src/accel_recon_shared1000.slurm ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --account=fmri
3
+ #SBATCH --partition=p5
4
+ #SBATCH --job-name=me2_shared1000
5
+ #SBATCH --ntasks-per-node=1
6
+ #SBATCH --nodes=1
7
+ #SBATCH --gres=gpu:1
8
+ #SBATCH --gpus-per-task=1 # Set to equal gres=gpu:#
9
+ #SBATCH --time=72:00:00 # Total run time limit (HH:MM:SS)
10
+ #SBATCH -e slurms/%j.err # Ensure "slurms" directory exists for logs
11
+ #SBATCH -o slurms/%j.out
12
+ #SBATCH --comment=medarc
13
+ #SBATCH --no-requeue
14
+ #SBATCH --qos=normal
15
+
16
+ source ~/.bashrc
17
+ source /admin/home-ckadirt/fmri/bin/activate
18
+ cd /weka/proj-fmri/ckadirt/MindEyeV2/src/
19
+
20
+
21
+ # Set up networking environment variables to avoid port conflicts
22
+ export MASTER_PORT=$((RANDOM % (19000 - 11000 + 1) + 11000))
23
+ export HOSTNAMES=$(scontrol show hostnames "$SLURM_JOB_NODELIST")
24
+ export MASTER_ADDR=$(echo "$HOSTNAMES" | head -n 1)
25
+ echo "MASTER_ADDR=${MASTER_ADDR}"
26
+ echo "MASTER_PORT=${MASTER_PORT}"
27
+
28
+ export MODULEPATH=/opt/amazon/modules/modulefiles:$MODULEPATH
29
+
30
+ jupyter nbconvert enhanced_recon_inference_old.ipynb --to python
31
+ jupyter nbconvert recon_inference_old.ipynb --to python
32
+
33
+ # jupyter nbconvert final_evaluations_mi_multi_icnn.ipynb --to python
34
+
35
+
36
+ for subj in 1; do
37
+ for num_sessions in 3; do
38
+ model_name="final_subj0${subj}_pretrained_${num_sessions}sess_24bs"
39
+ echo ${model_name}
40
+ echo "new_sessions"
41
+
42
+
43
+ python recon_inference_old.py \
44
+ --data_path=/weka/proj-medarc/shared/mindeyev2_dataset \
45
+ --cache_dir=/weka/proj-medarc/shared/mindeyev2_dataset \
46
+ --model_name="${model_name}" --subj=1 \
47
+ --hidden_dim=4096 --n_blocks=4 --new_test
48
+
49
+ python enhanced_recon_inference_old.py \
50
+ --model_name="${model_name}" --subj=1
51
+
52
+ done
53
+ done
MindEyeV2/src/autoencoder/convnext.py ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3
+
4
+ # All rights reserved.
5
+
6
+ # This source code is licensed under the license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+
9
+
10
+ import torch
11
+ import torch.nn as nn
12
+ import torch.nn.functional as F
13
+ from timm.models.layers import trunc_normal_, DropPath
14
+
15
+
16
+ class Block(nn.Module):
17
+ r""" ConvNeXt Block. There are two equivalent implementations:
18
+ (1) DwConv -> LayerNorm (channels_first) -> 1x1 Conv -> GELU -> 1x1 Conv; all in (N, C, H, W)
19
+ (2) DwConv -> Permute to (N, H, W, C); LayerNorm (channels_last) -> Linear -> GELU -> Linear; Permute back
20
+ We use (2) as we find it slightly faster in PyTorch
21
+
22
+ Args:
23
+ dim (int): Number of input channels.
24
+ drop_path (float): Stochastic depth rate. Default: 0.0
25
+ layer_scale_init_value (float): Init value for Layer Scale. Default: 1e-6.
26
+ """
27
+
28
+ def __init__(self, dim, drop_path=0.0, layer_scale_init_value=1e-6):
29
+ super().__init__()
30
+ self.dwconv = nn.Conv2d(
31
+ dim, dim, kernel_size=7, padding=3, groups=dim
32
+ ) # depthwise conv
33
+ self.norm = LayerNorm(dim, eps=1e-6)
34
+ self.pwconv1 = nn.Linear(
35
+ dim, 4 * dim
36
+ ) # pointwise/1x1 convs, implemented with linear layers
37
+ self.act = nn.GELU()
38
+ self.pwconv2 = nn.Linear(4 * dim, dim)
39
+ self.gamma = (
40
+ nn.Parameter(layer_scale_init_value * torch.ones((dim)), requires_grad=True)
41
+ if layer_scale_init_value > 0
42
+ else None
43
+ )
44
+ self.drop_path = DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
45
+
46
+ def forward(self, x):
47
+ input = x
48
+ x = self.dwconv(x)
49
+ x = x.permute(0, 2, 3, 1) # (N, C, H, W) -> (N, H, W, C)
50
+ x = self.norm(x)
51
+ x = self.pwconv1(x)
52
+ x = self.act(x)
53
+ x = self.pwconv2(x)
54
+ if self.gamma is not None:
55
+ x = self.gamma * x
56
+ x = x.permute(0, 3, 1, 2) # (N, H, W, C) -> (N, C, H, W)
57
+
58
+ x = input + self.drop_path(x)
59
+ return x
60
+
61
+
62
+ class ConvNeXt(nn.Module):
63
+ r""" ConvNeXt
64
+ A PyTorch impl of : `A ConvNet for the 2020s` -
65
+ https://arxiv.org/pdf/2201.03545.pdf
66
+ Args:
67
+ in_chans (int): Number of input image channels. Default: 3
68
+ num_classes (int): Number of classes for classification head. Default: 1000
69
+ depths (tuple(int)): Number of blocks at each stage. Default: [3, 3, 9, 3]
70
+ dims (int): Feature dimension at each stage. Default: [96, 192, 384, 768]
71
+ drop_path_rate (float): Stochastic depth rate. Default: 0.
72
+ layer_scale_init_value (float): Init value for Layer Scale. Default: 1e-6.
73
+ head_init_scale (float): Init scaling value for classifier weights and biases. Default: 1.
74
+ """
75
+
76
+ def __init__(
77
+ self,
78
+ in_chans=3,
79
+ num_classes=1000,
80
+ depths=[3, 3, 9, 3],
81
+ dims=[96, 192, 384, 768],
82
+ drop_path_rate=0.1,
83
+ layer_scale_init_value=0.0,
84
+ head_init_scale=1.0,
85
+ ):
86
+ super().__init__()
87
+
88
+ self.downsample_layers = (
89
+ nn.ModuleList()
90
+ ) # stem and 3 intermediate downsampling conv layers
91
+ stem = nn.Sequential(
92
+ nn.Conv2d(in_chans, dims[0], kernel_size=4, stride=4),
93
+ LayerNorm(dims[0], eps=1e-6, data_format="channels_first"),
94
+ )
95
+ self.downsample_layers.append(stem)
96
+ for i in range(3):
97
+ downsample_layer = nn.Sequential(
98
+ LayerNorm(dims[i], eps=1e-6, data_format="channels_first"),
99
+ nn.Conv2d(dims[i], dims[i + 1], kernel_size=2, stride=2),
100
+ )
101
+ self.downsample_layers.append(downsample_layer)
102
+
103
+ self.stages = (
104
+ nn.ModuleList()
105
+ ) # 4 feature resolution stages, each consisting of multiple residual blocks
106
+ dp_rates = [x.item() for x in torch.linspace(0, drop_path_rate, sum(depths))]
107
+ cur = 0
108
+ for i in range(4):
109
+ stage = nn.Sequential(
110
+ *[
111
+ Block(
112
+ dim=dims[i],
113
+ drop_path=dp_rates[cur + j],
114
+ layer_scale_init_value=layer_scale_init_value,
115
+ )
116
+ for j in range(depths[i])
117
+ ]
118
+ )
119
+ self.stages.append(stage)
120
+ cur += depths[i]
121
+
122
+ self.norm = nn.LayerNorm(dims[-1], eps=1e-6) # final norm layer
123
+ self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
124
+
125
+ self.apply(self._init_weights)
126
+
127
+ def _init_weights(self, m):
128
+ if isinstance(m, (nn.Conv2d, nn.Linear)):
129
+ trunc_normal_(m.weight, std=0.02)
130
+ nn.init.constant_(m.bias, 0)
131
+
132
+ def forward_features(self, x):
133
+ for i in range(4):
134
+ x = self.downsample_layers[i](x)
135
+ x = self.stages[i](x)
136
+ x = x.flatten(2, 3).permute(0, 2, 1)
137
+ x = self.norm(x)
138
+ x_avg = x.mean(dim=1)
139
+ return x, x_avg
140
+
141
+ def forward(self, x):
142
+ x = self.forward_features(x)
143
+ return x
144
+
145
+
146
+ class LayerNorm(nn.Module):
147
+ r""" LayerNorm that supports two data formats: channels_last (default) or channels_first.
148
+ The ordering of the dimensions in the inputs. channels_last corresponds to inputs with
149
+ shape (batch_size, height, width, channels) while channels_first corresponds to inputs
150
+ with shape (batch_size, channels, height, width).
151
+ """
152
+
153
+ def __init__(self, normalized_shape, eps=1e-6, data_format="channels_last"):
154
+ super().__init__()
155
+ self.weight = nn.Parameter(torch.ones(normalized_shape))
156
+ self.bias = nn.Parameter(torch.zeros(normalized_shape))
157
+ self.eps = eps
158
+ self.data_format = data_format
159
+ if self.data_format not in ["channels_last", "channels_first"]:
160
+ raise NotImplementedError
161
+ self.normalized_shape = (normalized_shape,)
162
+
163
+ def forward(self, x):
164
+ if self.data_format == "channels_last":
165
+ return F.layer_norm(
166
+ x, self.normalized_shape, self.weight, self.bias, self.eps
167
+ )
168
+ elif self.data_format == "channels_first":
169
+ u = x.mean(1, keepdim=True)
170
+ s = (x - u).pow(2).mean(1, keepdim=True)
171
+ x = (x - u) / torch.sqrt(s + self.eps)
172
+ x = self.weight[:, None, None] * x + self.bias[:, None, None]
173
+ return x
174
+
175
+
176
+ def convnext_tiny(**kwargs):
177
+ model = ConvNeXt(depths=[3, 3, 9, 3], dims=[96, 192, 384, 768], **kwargs)
178
+ return model, 768
179
+
180
+
181
+ def convnext_small(**kwargs):
182
+ model = ConvNeXt(depths=[3, 3, 27, 3], dims=[96, 192, 384, 768], **kwargs)
183
+ return model, 768
184
+
185
+
186
+ def convnext_base(**kwargs):
187
+ model = ConvNeXt(depths=[3, 3, 27, 3], dims=[128, 256, 512, 1024], **kwargs)
188
+ return model, 1024
189
+
190
+
191
+ def convnext_large(**kwargs):
192
+ model = ConvNeXt(depths=[3, 3, 27, 3], dims=[192, 384, 768, 1536], **kwargs)
193
+ return model, 1536
194
+
195
+
196
+ def convnext_xlarge(**kwargs):
197
+ model = ConvNeXt(depths=[3, 3, 27, 3], dims=[256, 512, 1024, 2048], **kwargs)
198
+ return model, 2048
199
+
200
+ def MLP(mlp, embedding, norm_layer):
201
+ mlp_spec = f"{embedding}-{mlp}"
202
+ layers = []
203
+ f = list(map(int, mlp_spec.split("-")))
204
+ for i in range(len(f) - 2):
205
+ layers.append(nn.Linear(f[i], f[i + 1]))
206
+ if norm_layer == "batch_norm":
207
+ layers.append(nn.BatchNorm1d(f[i + 1]))
208
+ elif norm_layer == "layer_norm":
209
+ layers.append(nn.LayerNorm(f[i + 1]))
210
+ layers.append(nn.ReLU(True))
211
+ layers.append(nn.Linear(f[-2], f[-1], bias=False))
212
+ return nn.Sequential(*layers)
213
+
214
+ class ConvnextXL(torch.nn.Module):
215
+ def __init__(self, path):
216
+ super().__init__()
217
+ self.backbone, _ = convnext_xlarge()
218
+ self.maps_projector = MLP('512-512-512', 2048, 'layer_norm')
219
+ self.init_weights(path)
220
+
221
+ def init_weights(self, path):
222
+ sd = torch.load(path, map_location='cpu')['model']
223
+ for k in list(sd.keys()):
224
+ if 'module' in k:
225
+ sd[k.replace('module.', '')] = sd[k]
226
+ del sd[k]
227
+ try:
228
+ self.load_state_dict(sd, strict=False)
229
+ except:
230
+ pass
231
+
232
+ def forward(self, x):
233
+ p, _ = self.backbone(x) # b, hw, 2048
234
+ return p, self.maps_projector(p)
235
+
236
+
237
+ if __name__== "__main__":
238
+ m = ConvnextXL('../train_logs/models/convnext_xlarge_alpha0.75_fullckpt.pth')
239
+ preds = m(torch.randn(2, 3, 512, 512))
MindEyeV2/src/bold5k_preproc.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
MindEyeV2/src/enhanced_recon_inference.ipynb ADDED
@@ -0,0 +1,891 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "6b18f6a3-cc4f-437e-9756-c99fc6a5fad4",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "device: cuda\n"
14
+ ]
15
+ },
16
+ {
17
+ "name": "stderr",
18
+ "output_type": "stream",
19
+ "text": [
20
+ "/admin/home-ckadirt/mindeye/lib/python3.11/site-packages/accelerate/accelerator.py:457: FutureWarning: Passing the following arguments to `Accelerator` is deprecated and will be removed in version 1.0 of Accelerate: dict_keys(['split_batches']). Please pass an `accelerate.DataLoaderConfiguration` instead: \n",
21
+ "dataloader_config = DataLoaderConfiguration(split_batches=False)\n",
22
+ " warnings.warn(\n"
23
+ ]
24
+ }
25
+ ],
26
+ "source": [
27
+ "import os\n",
28
+ "import sys\n",
29
+ "import json\n",
30
+ "import argparse\n",
31
+ "import numpy as np\n",
32
+ "import math\n",
33
+ "from einops import rearrange\n",
34
+ "import time\n",
35
+ "import random\n",
36
+ "import string\n",
37
+ "import h5py\n",
38
+ "from tqdm import tqdm\n",
39
+ "\n",
40
+ "import matplotlib.pyplot as plt\n",
41
+ "import torch\n",
42
+ "import torch.nn as nn\n",
43
+ "from torchvision import transforms\n",
44
+ "from accelerate import Accelerator, DeepSpeedPlugin\n",
45
+ "\n",
46
+ "# SDXL unCLIP requires code from https://github.com/Stability-AI/generative-models/tree/main\n",
47
+ "sys.path.append('generative_models/')\n",
48
+ "import sgm\n",
49
+ "from generative_models.sgm.modules.encoders.modules import FrozenOpenCLIPImageEmbedder, FrozenCLIPEmbedder, FrozenOpenCLIPEmbedder2\n",
50
+ "from generative_models.sgm.models.diffusion import DiffusionEngine\n",
51
+ "from generative_models.sgm.util import append_dims\n",
52
+ "from omegaconf import OmegaConf\n",
53
+ "\n",
54
+ "# tf32 data type is faster than standard float32\n",
55
+ "torch.backends.cuda.matmul.allow_tf32 = True\n",
56
+ "\n",
57
+ "# custom functions #\n",
58
+ "import utils\n",
59
+ "from models import *\n",
60
+ "\n",
61
+ "accelerator = Accelerator(split_batches=False, mixed_precision=\"fp16\")\n",
62
+ "device = accelerator.device\n",
63
+ "print(\"device:\",device)"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 2,
69
+ "id": "20cdb696-1d6e-4b73-951b-b0cd1dda219a",
70
+ "metadata": {},
71
+ "outputs": [
72
+ {
73
+ "name": "stdout",
74
+ "output_type": "stream",
75
+ "text": [
76
+ "model_name: final_subj01_pretrained_375trials_24bs\n",
77
+ "--model_name=final_subj01_pretrained_375trials_24bs --subj=1 --mode=imagery\n"
78
+ ]
79
+ }
80
+ ],
81
+ "source": [
82
+ "# if running this interactively, can specify jupyter_args here for argparser to use\n",
83
+ "if utils.is_interactive():\n",
84
+ " model_name = \"final_subj01_pretrained_375trials_24bs\"\n",
85
+ " print(\"model_name:\", model_name)\n",
86
+ " mode = \"imagery\"\n",
87
+ " # global_batch_size and batch_size should already be defined in the above cells\n",
88
+ " # other variables can be specified in the following string:\n",
89
+ " jupyter_args = f\"--model_name={model_name} --subj=1 --mode={mode}\"\n",
90
+ " print(jupyter_args)\n",
91
+ " jupyter_args = jupyter_args.split()\n",
92
+ " \n",
93
+ " from IPython.display import clear_output # function to clear print outputs in cell\n",
94
+ " %load_ext autoreload \n",
95
+ " # this allows you to change functions in models.py or utils.py and have this notebook automatically update with your revisions\n",
96
+ " %autoreload 2 "
97
+ ]
98
+ },
99
+ {
100
+ "cell_type": "code",
101
+ "execution_count": 3,
102
+ "id": "4b31d7c0-f5bd-4a19-a8be-7a3a165d79b6",
103
+ "metadata": {},
104
+ "outputs": [
105
+ {
106
+ "name": "stderr",
107
+ "output_type": "stream",
108
+ "text": [
109
+ " 0%| | 0/18 [00:00<?, ?it/s]/admin/home-ckadirt/mindeye/lib/python3.11/site-packages/torchvision/transforms/functional.py:1603: UserWarning: The default value of the antialias parameter of all the resizing transforms (Resize(), RandomResizedCrop(), etc.) will change from None to True in v0.17, in order to be consistent across the PIL and Tensor backends. To suppress this warning, directly pass antialias=True (recommended, future default), antialias=None (current default, which means False for Tensors and True for PIL), or antialias=False (only works on Tensors - PIL will still use antialiasing). This also applies if you are using the inference transforms from the models weights: update the call to weights.transforms(antialias=True).\n",
110
+ " warnings.warn(\n",
111
+ "100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████��███████████████| 18/18 [00:03<00:00, 4.95it/s]"
112
+ ]
113
+ },
114
+ {
115
+ "name": "stdout",
116
+ "output_type": "stream",
117
+ "text": [
118
+ "final_subj01_pretrained_375trials_24bs\n",
119
+ "torch.Size([18, 3, 425, 425]) torch.Size([18, 10, 3, 768, 768]) torch.Size([18, 10, 256, 1664]) torch.Size([18, 10, 3, 768, 768]) (18, 10)\n"
120
+ ]
121
+ },
122
+ {
123
+ "name": "stderr",
124
+ "output_type": "stream",
125
+ "text": [
126
+ "\n"
127
+ ]
128
+ }
129
+ ],
130
+ "source": [
131
+ "parser = argparse.ArgumentParser(description=\"Model Training Configuration\")\n",
132
+ "parser.add_argument(\n",
133
+ " \"--model_name\", type=str, default=\"testing\",\n",
134
+ " help=\"will load ckpt for model found in ../train_logs/model_name\",\n",
135
+ ")\n",
136
+ "parser.add_argument(\n",
137
+ " \"--subj\",type=int, default=1, choices=[1,2,3,4,5,6,7,8],\n",
138
+ " help=\"Evaluate on which subject?\",\n",
139
+ ")\n",
140
+ "parser.add_argument(\n",
141
+ " \"--seed\",type=int,default=42,\n",
142
+ ")\n",
143
+ "parser.add_argument(\n",
144
+ " \"--mode\",type=str,default=\"vision\",choices=[\"vision\",\"imagery\",\"shared1000\"],\n",
145
+ " help=\"Evaluate on which modality?\",\n",
146
+ ")\n",
147
+ "\n",
148
+ "if utils.is_interactive():\n",
149
+ " args = parser.parse_args(jupyter_args)\n",
150
+ "else:\n",
151
+ " args = parser.parse_args()\n",
152
+ "\n",
153
+ "# create global variables without the args prefix\n",
154
+ "for attribute_name in vars(args).keys():\n",
155
+ " globals()[attribute_name] = getattr(args, attribute_name)\n",
156
+ " \n",
157
+ "# seed all random functions\n",
158
+ "utils.seed_everything(seed)\n",
159
+ "\n",
160
+ "# make output directory\n",
161
+ "os.makedirs(\"evals\",exist_ok=True)\n",
162
+ "os.makedirs(f\"evals/{model_name}\",exist_ok=True)\n",
163
+ "\n",
164
+ "# Some of these files are downloadable from huggingface: https://huggingface.co/datasets/pscotti/mindeyev2/tree/main/evals\n",
165
+ "# The others are obtained from running recon_inference.ipynb first with your desired model\n",
166
+ "all_images = torch.load(f\"evals/all_images.pt\")\n",
167
+ "rep_all_recons = torch.load(f\"evals/{model_name}/{model_name}_all_recons_{mode}.pt\")\n",
168
+ "rep_all_clipvoxels = torch.load(f\"evals/{model_name}/{model_name}_all_clipvoxels_{mode}.pt\")\n",
169
+ "rep_all_blurryrecons = torch.load(f\"evals/{model_name}/{model_name}_all_blurryrecons_{mode}.pt\")\n",
170
+ "rep_all_predcaptions = torch.load(f\"evals/{model_name}/{model_name}_all_predcaptions_{mode}.pt\")\n",
171
+ "\n",
172
+ "\n",
173
+ "resized_recons = None\n",
174
+ "resized_blurryrecons = None\n",
175
+ "for i in tqdm(range(len(all_images))):\n",
176
+ " resized_recons_ = transforms.Resize((768,768))(rep_all_recons[i]).float()\n",
177
+ " resized_blurryrecons_ = transforms.Resize((768,768))(rep_all_blurryrecons[i]).float()\n",
178
+ " if resized_recons is None:\n",
179
+ " resized_recons = resized_recons_.unsqueeze(0)\n",
180
+ " resized_blurryrecons = resized_blurryrecons_.unsqueeze(0)\n",
181
+ " else:\n",
182
+ " resized_recons = torch.cat([resized_recons, resized_recons_.unsqueeze(0)],0)\n",
183
+ " resized_blurryrecons = torch.cat([resized_blurryrecons, resized_blurryrecons_.unsqueeze(0)],0)\n",
184
+ "\n",
185
+ "rep_all_blurryrecons = resized_blurryrecons\n",
186
+ "rep_all_recons = resized_recons\n",
187
+ "\n",
188
+ "# reshape the predcaptions from 180 to 18,10\n",
189
+ "from einops import rearrange\n",
190
+ "if rep_all_predcaptions.shape[0] != resized_recons.shape[0]:\n",
191
+ " rep_all_predcaptions = rearrange(rep_all_predcaptions, '(c r) -> r c', r=resized_recons.shape[0], c=resized_recons.shape[1])\n",
192
+ "\n",
193
+ "print(model_name)\n",
194
+ "print(all_images.shape, rep_all_recons.shape, rep_all_clipvoxels.shape, rep_all_blurryrecons.shape, rep_all_predcaptions.shape)"
195
+ ]
196
+ },
197
+ {
198
+ "cell_type": "code",
199
+ "execution_count": 4,
200
+ "id": "24bdd667-0862-4561-b432-9fa7543df863",
201
+ "metadata": {},
202
+ "outputs": [
203
+ {
204
+ "name": "stderr",
205
+ "output_type": "stream",
206
+ "text": [
207
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [2048, 2048] now.\n",
208
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [2048, 2048] now.\n",
209
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048] now.\n",
210
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048] now.\n",
211
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048] now.\n",
212
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048] now.\n",
213
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048] now.\n",
214
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048] now.\n",
215
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [2048, 2048] now.\n",
216
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [2048, 2048] now.\n",
217
+ "SpatialTransformer: Found context dims [2048] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [2048, 2048] now.\n"
218
+ ]
219
+ },
220
+ {
221
+ "name": "stdout",
222
+ "output_type": "stream",
223
+ "text": [
224
+ "Initialized embedder #0: FrozenCLIPEmbedder with 123060480 params. Trainable: False\n",
225
+ "Initialized embedder #1: FrozenOpenCLIPEmbedder2 with 694659841 params. Trainable: False\n",
226
+ "Initialized embedder #2: ConcatTimestepEmbedderND with 0 params. Trainable: False\n",
227
+ "Initialized embedder #3: ConcatTimestepEmbedderND with 0 params. Trainable: False\n",
228
+ "Initialized embedder #4: ConcatTimestepEmbedderND with 0 params. Trainable: False\n",
229
+ "Restored from /weka/proj-medarc/shared/mindeyev2_dataset/zavychromaxl_v30.safetensors with 1 missing and 1 unexpected keys\n",
230
+ "Missing Keys: ['denoiser.sigmas']\n",
231
+ "Unexpected Keys: ['conditioner.embedders.0.transformer.text_model.embeddings.position_ids']\n",
232
+ "crossattn torch.Size([1, 77, 2048])\n",
233
+ "vector_suffix torch.Size([1, 1536])\n",
234
+ "---\n",
235
+ "crossattn_uc torch.Size([1, 77, 2048])\n",
236
+ "vector_uc torch.Size([1, 2816])\n"
237
+ ]
238
+ }
239
+ ],
240
+ "source": [
241
+ "config = OmegaConf.load(\"generative_models/configs/unclip6.yaml\")\n",
242
+ "config = OmegaConf.to_container(config, resolve=True)\n",
243
+ "unclip_params = config[\"model\"][\"params\"]\n",
244
+ "sampler_config = unclip_params[\"sampler_config\"]\n",
245
+ "sampler_config['params']['num_steps'] = 38\n",
246
+ "config = OmegaConf.load(\"generative_models/configs/inference/sd_xl_base.yaml\")\n",
247
+ "config = OmegaConf.to_container(config, resolve=True)\n",
248
+ "refiner_params = config[\"model\"][\"params\"]\n",
249
+ "\n",
250
+ "network_config = refiner_params[\"network_config\"]\n",
251
+ "denoiser_config = refiner_params[\"denoiser_config\"]\n",
252
+ "first_stage_config = refiner_params[\"first_stage_config\"]\n",
253
+ "conditioner_config = refiner_params[\"conditioner_config\"]\n",
254
+ "scale_factor = refiner_params[\"scale_factor\"]\n",
255
+ "disable_first_stage_autocast = refiner_params[\"disable_first_stage_autocast\"]\n",
256
+ "\n",
257
+ "# base_ckpt_path = '/weka/robin/projects/stable-research/checkpoints/sd_xl_base_1.0.safetensors'\n",
258
+ "base_ckpt_path = '/weka/proj-medarc/shared/mindeyev2_dataset/zavychromaxl_v30.safetensors'\n",
259
+ "base_engine = DiffusionEngine(network_config=network_config,\n",
260
+ " denoiser_config=denoiser_config,\n",
261
+ " first_stage_config=first_stage_config,\n",
262
+ " conditioner_config=conditioner_config,\n",
263
+ " sampler_config=sampler_config, # using the one defined by the unclip\n",
264
+ " scale_factor=scale_factor,\n",
265
+ " disable_first_stage_autocast=disable_first_stage_autocast,\n",
266
+ " ckpt_path=base_ckpt_path)\n",
267
+ "base_engine.eval().requires_grad_(False)\n",
268
+ "base_engine.to(device)\n",
269
+ "\n",
270
+ "base_text_embedder1 = FrozenCLIPEmbedder(\n",
271
+ " layer=conditioner_config['params']['emb_models'][0]['params']['layer'],\n",
272
+ " layer_idx=conditioner_config['params']['emb_models'][0]['params']['layer_idx'],\n",
273
+ ")\n",
274
+ "base_text_embedder1.to(device)\n",
275
+ "\n",
276
+ "base_text_embedder2 = FrozenOpenCLIPEmbedder2(\n",
277
+ " arch=conditioner_config['params']['emb_models'][1]['params']['arch'],\n",
278
+ " version=conditioner_config['params']['emb_models'][1]['params']['version'],\n",
279
+ " freeze=conditioner_config['params']['emb_models'][1]['params']['freeze'],\n",
280
+ " layer=conditioner_config['params']['emb_models'][1]['params']['layer'],\n",
281
+ " always_return_pooled=conditioner_config['params']['emb_models'][1]['params']['always_return_pooled'],\n",
282
+ " legacy=conditioner_config['params']['emb_models'][1]['params']['legacy'],\n",
283
+ ")\n",
284
+ "base_text_embedder2.to(device)\n",
285
+ "\n",
286
+ "batch={\"txt\": \"\",\n",
287
+ " \"original_size_as_tuple\": torch.ones(1, 2).to(device) * 768,\n",
288
+ " \"crop_coords_top_left\": torch.zeros(1, 2).to(device),\n",
289
+ " \"target_size_as_tuple\": torch.ones(1, 2).to(device) * 1024}\n",
290
+ "out = base_engine.conditioner(batch)\n",
291
+ "crossattn = out[\"crossattn\"].to(device)\n",
292
+ "vector_suffix = out[\"vector\"][:,-1536:].to(device)\n",
293
+ "print(\"crossattn\", crossattn.shape)\n",
294
+ "print(\"vector_suffix\", vector_suffix.shape)\n",
295
+ "print(\"---\")\n",
296
+ "\n",
297
+ "batch_uc={\"txt\": \"painting, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, deformed, ugly, blurry, bad anatomy, bad proportions, extra limbs, cloned face, skinny, glitchy, double torso, extra arms, extra hands, mangled fingers, missing lips, ugly face, distorted face, extra legs, anime\",\n",
298
+ " \"original_size_as_tuple\": torch.ones(1, 2).to(device) * 768,\n",
299
+ " \"crop_coords_top_left\": torch.zeros(1, 2).to(device),\n",
300
+ " \"target_size_as_tuple\": torch.ones(1, 2).to(device) * 1024}\n",
301
+ "out = base_engine.conditioner(batch_uc)\n",
302
+ "crossattn_uc = out[\"crossattn\"].to(device)\n",
303
+ "vector_uc = out[\"vector\"].to(device)\n",
304
+ "print(\"crossattn_uc\", crossattn_uc.shape)\n",
305
+ "print(\"vector_uc\", vector_uc.shape)"
306
+ ]
307
+ },
308
+ {
309
+ "cell_type": "code",
310
+ "execution_count": 5,
311
+ "id": "07f437d1-9b8e-4b13-85ad-d45062a5ce09",
312
+ "metadata": {
313
+ "tags": []
314
+ },
315
+ "outputs": [],
316
+ "source": [
317
+ "if utils.is_interactive(): plotting=False\n",
318
+ "plotting=False\n",
319
+ "num_samples = 1 # PS: I tried increasing this to 16 and picking highest cosine similarity like we did in MindEye1, it didnt seem to increase eval performance!\n",
320
+ "img2img_timepoint = 13 # 9 # higher number means more reliance on prompt, less reliance on matching the conditioning image\n",
321
+ "base_engine.sampler.guider.scale = 5 # 5 # cfg\n",
322
+ "def denoiser(x, sigma, c): return base_engine.denoiser(base_engine.model, x, sigma, c)\n",
323
+ "\n",
324
+ "if plotting or num_samples>1:\n",
325
+ " clip_img_embedder = FrozenOpenCLIPImageEmbedder(\n",
326
+ " arch=\"ViT-bigG-14\",\n",
327
+ " version=\"laion2b_s39b_b160k\",\n",
328
+ " output_tokens=True,\n",
329
+ " only_tokens=True,\n",
330
+ " )\n",
331
+ " clip_img_embedder.to(device)"
332
+ ]
333
+ },
334
+ {
335
+ "cell_type": "code",
336
+ "execution_count": 6,
337
+ "id": "939e1cbb-5836-48c2-87d8-3e493e950011",
338
+ "metadata": {
339
+ "tags": []
340
+ },
341
+ "outputs": [
342
+ {
343
+ "data": {
344
+ "application/vnd.jupyter.widget-view+json": {
345
+ "model_id": "a3e32a1951204ca79d0ab0117da33406",
346
+ "version_major": 2,
347
+ "version_minor": 0
348
+ },
349
+ "text/plain": [
350
+ " 0%| | 0/18 [00:00<?, ?it/s]"
351
+ ]
352
+ },
353
+ "metadata": {},
354
+ "output_type": "display_data"
355
+ },
356
+ {
357
+ "data": {
358
+ "application/vnd.jupyter.widget-view+json": {
359
+ "model_id": "130c932f43fd477f98c3f1787f881b92",
360
+ "version_major": 2,
361
+ "version_minor": 0
362
+ },
363
+ "text/plain": [
364
+ " 0%| | 0/10 [00:00<?, ?it/s]"
365
+ ]
366
+ },
367
+ "metadata": {},
368
+ "output_type": "display_data"
369
+ },
370
+ {
371
+ "name": "stderr",
372
+ "output_type": "stream",
373
+ "text": [
374
+ "/admin/home-ckadirt/mindeye/lib/python3.11/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
375
+ " warnings.warn(\n",
376
+ "/admin/home-ckadirt/mindeye/lib/python3.11/site-packages/torch/utils/checkpoint.py:61: UserWarning: None of the inputs have requires_grad=True. Gradients will be None\n",
377
+ " warnings.warn(\n"
378
+ ]
379
+ },
380
+ {
381
+ "name": "stdout",
382
+ "output_type": "stream",
383
+ "text": [
384
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
385
+ ]
386
+ },
387
+ {
388
+ "data": {
389
+ "application/vnd.jupyter.widget-view+json": {
390
+ "model_id": "383921dd7d074af9b6330eb68f112c27",
391
+ "version_major": 2,
392
+ "version_minor": 0
393
+ },
394
+ "text/plain": [
395
+ " 0%| | 0/10 [00:00<?, ?it/s]"
396
+ ]
397
+ },
398
+ "metadata": {},
399
+ "output_type": "display_data"
400
+ },
401
+ {
402
+ "name": "stdout",
403
+ "output_type": "stream",
404
+ "text": [
405
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
406
+ ]
407
+ },
408
+ {
409
+ "data": {
410
+ "application/vnd.jupyter.widget-view+json": {
411
+ "model_id": "5c4eb7e9e2594cfbbfac8035b762fa5a",
412
+ "version_major": 2,
413
+ "version_minor": 0
414
+ },
415
+ "text/plain": [
416
+ " 0%| | 0/10 [00:00<?, ?it/s]"
417
+ ]
418
+ },
419
+ "metadata": {},
420
+ "output_type": "display_data"
421
+ },
422
+ {
423
+ "name": "stdout",
424
+ "output_type": "stream",
425
+ "text": [
426
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
427
+ ]
428
+ },
429
+ {
430
+ "data": {
431
+ "application/vnd.jupyter.widget-view+json": {
432
+ "model_id": "20d79a05a5a643ee9063b5239a549290",
433
+ "version_major": 2,
434
+ "version_minor": 0
435
+ },
436
+ "text/plain": [
437
+ " 0%| | 0/10 [00:00<?, ?it/s]"
438
+ ]
439
+ },
440
+ "metadata": {},
441
+ "output_type": "display_data"
442
+ },
443
+ {
444
+ "name": "stdout",
445
+ "output_type": "stream",
446
+ "text": [
447
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
448
+ ]
449
+ },
450
+ {
451
+ "data": {
452
+ "application/vnd.jupyter.widget-view+json": {
453
+ "model_id": "45d9979238d04909889ff11f458adb65",
454
+ "version_major": 2,
455
+ "version_minor": 0
456
+ },
457
+ "text/plain": [
458
+ " 0%| | 0/10 [00:00<?, ?it/s]"
459
+ ]
460
+ },
461
+ "metadata": {},
462
+ "output_type": "display_data"
463
+ },
464
+ {
465
+ "name": "stdout",
466
+ "output_type": "stream",
467
+ "text": [
468
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
469
+ ]
470
+ },
471
+ {
472
+ "data": {
473
+ "application/vnd.jupyter.widget-view+json": {
474
+ "model_id": "0cbf925ddc334a9ea11c8ce310d155ec",
475
+ "version_major": 2,
476
+ "version_minor": 0
477
+ },
478
+ "text/plain": [
479
+ " 0%| | 0/10 [00:00<?, ?it/s]"
480
+ ]
481
+ },
482
+ "metadata": {},
483
+ "output_type": "display_data"
484
+ },
485
+ {
486
+ "name": "stdout",
487
+ "output_type": "stream",
488
+ "text": [
489
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
490
+ ]
491
+ },
492
+ {
493
+ "data": {
494
+ "application/vnd.jupyter.widget-view+json": {
495
+ "model_id": "b58c54fcd2924f7db8e9f1d2ea425fdf",
496
+ "version_major": 2,
497
+ "version_minor": 0
498
+ },
499
+ "text/plain": [
500
+ " 0%| | 0/10 [00:00<?, ?it/s]"
501
+ ]
502
+ },
503
+ "metadata": {},
504
+ "output_type": "display_data"
505
+ },
506
+ {
507
+ "name": "stdout",
508
+ "output_type": "stream",
509
+ "text": [
510
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
511
+ ]
512
+ },
513
+ {
514
+ "data": {
515
+ "application/vnd.jupyter.widget-view+json": {
516
+ "model_id": "03790a6b73bc4b549fb35c6ecde64a06",
517
+ "version_major": 2,
518
+ "version_minor": 0
519
+ },
520
+ "text/plain": [
521
+ " 0%| | 0/10 [00:00<?, ?it/s]"
522
+ ]
523
+ },
524
+ "metadata": {},
525
+ "output_type": "display_data"
526
+ },
527
+ {
528
+ "name": "stdout",
529
+ "output_type": "stream",
530
+ "text": [
531
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
532
+ ]
533
+ },
534
+ {
535
+ "data": {
536
+ "application/vnd.jupyter.widget-view+json": {
537
+ "model_id": "30b4e55f835943f29c1d8d3778fc6b1b",
538
+ "version_major": 2,
539
+ "version_minor": 0
540
+ },
541
+ "text/plain": [
542
+ " 0%| | 0/10 [00:00<?, ?it/s]"
543
+ ]
544
+ },
545
+ "metadata": {},
546
+ "output_type": "display_data"
547
+ },
548
+ {
549
+ "name": "stdout",
550
+ "output_type": "stream",
551
+ "text": [
552
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
553
+ ]
554
+ },
555
+ {
556
+ "data": {
557
+ "application/vnd.jupyter.widget-view+json": {
558
+ "model_id": "073db9cbbae84e76b9e1acabd2dec807",
559
+ "version_major": 2,
560
+ "version_minor": 0
561
+ },
562
+ "text/plain": [
563
+ " 0%| | 0/10 [00:00<?, ?it/s]"
564
+ ]
565
+ },
566
+ "metadata": {},
567
+ "output_type": "display_data"
568
+ },
569
+ {
570
+ "name": "stdout",
571
+ "output_type": "stream",
572
+ "text": [
573
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
574
+ ]
575
+ },
576
+ {
577
+ "data": {
578
+ "application/vnd.jupyter.widget-view+json": {
579
+ "model_id": "026d94daa9404792b3952efe47b693d1",
580
+ "version_major": 2,
581
+ "version_minor": 0
582
+ },
583
+ "text/plain": [
584
+ " 0%| | 0/10 [00:00<?, ?it/s]"
585
+ ]
586
+ },
587
+ "metadata": {},
588
+ "output_type": "display_data"
589
+ },
590
+ {
591
+ "name": "stdout",
592
+ "output_type": "stream",
593
+ "text": [
594
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
595
+ ]
596
+ },
597
+ {
598
+ "data": {
599
+ "application/vnd.jupyter.widget-view+json": {
600
+ "model_id": "bb82c763bf54416aadb250c2dfb5c4aa",
601
+ "version_major": 2,
602
+ "version_minor": 0
603
+ },
604
+ "text/plain": [
605
+ " 0%| | 0/10 [00:00<?, ?it/s]"
606
+ ]
607
+ },
608
+ "metadata": {},
609
+ "output_type": "display_data"
610
+ },
611
+ {
612
+ "name": "stdout",
613
+ "output_type": "stream",
614
+ "text": [
615
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
616
+ ]
617
+ },
618
+ {
619
+ "data": {
620
+ "application/vnd.jupyter.widget-view+json": {
621
+ "model_id": "a419df891da9468682f97224281d040e",
622
+ "version_major": 2,
623
+ "version_minor": 0
624
+ },
625
+ "text/plain": [
626
+ " 0%| | 0/10 [00:00<?, ?it/s]"
627
+ ]
628
+ },
629
+ "metadata": {},
630
+ "output_type": "display_data"
631
+ },
632
+ {
633
+ "name": "stdout",
634
+ "output_type": "stream",
635
+ "text": [
636
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
637
+ ]
638
+ },
639
+ {
640
+ "data": {
641
+ "application/vnd.jupyter.widget-view+json": {
642
+ "model_id": "ab3fbf9138c94f0d8b9ecea922208ced",
643
+ "version_major": 2,
644
+ "version_minor": 0
645
+ },
646
+ "text/plain": [
647
+ " 0%| | 0/10 [00:00<?, ?it/s]"
648
+ ]
649
+ },
650
+ "metadata": {},
651
+ "output_type": "display_data"
652
+ },
653
+ {
654
+ "name": "stdout",
655
+ "output_type": "stream",
656
+ "text": [
657
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
658
+ ]
659
+ },
660
+ {
661
+ "data": {
662
+ "application/vnd.jupyter.widget-view+json": {
663
+ "model_id": "efcc94ccbb944073b43db9d2ca41502f",
664
+ "version_major": 2,
665
+ "version_minor": 0
666
+ },
667
+ "text/plain": [
668
+ " 0%| | 0/10 [00:00<?, ?it/s]"
669
+ ]
670
+ },
671
+ "metadata": {},
672
+ "output_type": "display_data"
673
+ },
674
+ {
675
+ "name": "stdout",
676
+ "output_type": "stream",
677
+ "text": [
678
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
679
+ ]
680
+ },
681
+ {
682
+ "data": {
683
+ "application/vnd.jupyter.widget-view+json": {
684
+ "model_id": "c129efc8496e45b7971051efab9195b2",
685
+ "version_major": 2,
686
+ "version_minor": 0
687
+ },
688
+ "text/plain": [
689
+ " 0%| | 0/10 [00:00<?, ?it/s]"
690
+ ]
691
+ },
692
+ "metadata": {},
693
+ "output_type": "display_data"
694
+ },
695
+ {
696
+ "name": "stdout",
697
+ "output_type": "stream",
698
+ "text": [
699
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
700
+ ]
701
+ },
702
+ {
703
+ "data": {
704
+ "application/vnd.jupyter.widget-view+json": {
705
+ "model_id": "52da5ff9d7894bf8a18523d14cbabcdf",
706
+ "version_major": 2,
707
+ "version_minor": 0
708
+ },
709
+ "text/plain": [
710
+ " 0%| | 0/10 [00:00<?, ?it/s]"
711
+ ]
712
+ },
713
+ "metadata": {},
714
+ "output_type": "display_data"
715
+ },
716
+ {
717
+ "name": "stdout",
718
+ "output_type": "stream",
719
+ "text": [
720
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n"
721
+ ]
722
+ },
723
+ {
724
+ "data": {
725
+ "application/vnd.jupyter.widget-view+json": {
726
+ "model_id": "f45c31dc95a84e6ab3a37f893c8e5da7",
727
+ "version_major": 2,
728
+ "version_minor": 0
729
+ },
730
+ "text/plain": [
731
+ " 0%| | 0/10 [00:00<?, ?it/s]"
732
+ ]
733
+ },
734
+ "metadata": {},
735
+ "output_type": "display_data"
736
+ },
737
+ {
738
+ "name": "stdout",
739
+ "output_type": "stream",
740
+ "text": [
741
+ "all_enhancedrecons torch.Size([10, 3, 256, 256])\n",
742
+ "final_enhancedrecons torch.Size([18, 10, 3, 256, 256])\n",
743
+ "saved evals/final_subj01_pretrained_375trials_24bs/final_subj01_pretrained_375trials_24bs_all_enhancedrecons_imagery.pt\n"
744
+ ]
745
+ }
746
+ ],
747
+ "source": [
748
+ "from tqdm.auto import tqdm\n",
749
+ "\n",
750
+ "final_enhancedrecons = None\n",
751
+ "\n",
752
+ "for rep in tqdm(range(len(rep_all_recons))):\n",
753
+ " all_enhancedrecons = None\n",
754
+ " all_recons = rep_all_recons[rep]\n",
755
+ " all_clipvoxels = rep_all_clipvoxels[rep]\n",
756
+ " all_blurryrecons = rep_all_blurryrecons[rep]\n",
757
+ " all_predcaptions = rep_all_predcaptions[rep]\n",
758
+ "\n",
759
+ " for img_idx in tqdm(range(len(all_recons))):\n",
760
+ " with torch.no_grad(), torch.cuda.amp.autocast(dtype=torch.float16), base_engine.ema_scope():\n",
761
+ " base_engine.sampler.num_steps = 25\n",
762
+ " \n",
763
+ " image = all_recons[[img_idx]]\n",
764
+ " if plotting:\n",
765
+ " print(\"blur pixcorr:\",utils.pixcorr(all_blurryrecons[[img_idx]].float(), all_images[[img_idx]].float()))\n",
766
+ " print(\"blur cossim:\",nn.functional.cosine_similarity(clip_img_embedder(utils.resize(all_blurryrecons[[img_idx]].float(),256).to(device)).flatten(1), \n",
767
+ " clip_img_embedder(utils.resize(all_images[[img_idx]].float(),224).to(device)).flatten(1)))\n",
768
+ "\n",
769
+ " print(\"recon pixcorr:\",utils.pixcorr(image,all_images[[img_idx]].float()))\n",
770
+ " print(\"recon cossim:\",nn.functional.cosine_similarity(clip_img_embedder(utils.resize(image,224).to(device)).flatten(1), \n",
771
+ " clip_img_embedder(utils.resize(all_images[[img_idx]].float(),224).to(device)).flatten(1)))\n",
772
+ " \n",
773
+ " image = image.to(device)\n",
774
+ " prompt = all_predcaptions[[img_idx]][0]\n",
775
+ " # prompt = \"\"\n",
776
+ " if plotting: \n",
777
+ " print(\"prompt:\",prompt)\n",
778
+ " plt.imshow(transforms.ToPILImage()(all_blurryrecons[img_idx].float()))\n",
779
+ " plt.show()\n",
780
+ " plt.imshow(transforms.ToPILImage()(all_recons[img_idx].float()))\n",
781
+ " plt.show()\n",
782
+ " plt.imshow(transforms.ToPILImage()(image[0]))\n",
783
+ " plt.show()\n",
784
+ "\n",
785
+ " # z = torch.randn(num_samples,4,96,96).to(device)\n",
786
+ " assert image.shape[-1]==768\n",
787
+ " z = base_engine.encode_first_stage(image*2-1).repeat(num_samples,1,1,1)\n",
788
+ "\n",
789
+ " openai_clip_text = base_text_embedder1(prompt)\n",
790
+ " clip_text_tokenized, clip_text_emb = base_text_embedder2(prompt)\n",
791
+ " clip_text_emb = torch.hstack((clip_text_emb, vector_suffix))\n",
792
+ " clip_text_tokenized = torch.cat((openai_clip_text, clip_text_tokenized),dim=-1)\n",
793
+ " c = {\"crossattn\": clip_text_tokenized.repeat(num_samples,1,1), \"vector\": clip_text_emb.repeat(num_samples,1)}\n",
794
+ " uc = {\"crossattn\": crossattn_uc.repeat(num_samples,1,1), \"vector\": vector_uc.repeat(num_samples,1)}\n",
795
+ "\n",
796
+ " noise = torch.randn_like(z)\n",
797
+ " sigmas = base_engine.sampler.discretization(base_engine.sampler.num_steps).to(device)\n",
798
+ " init_z = (z + noise * append_dims(sigmas[-img2img_timepoint], z.ndim)) / torch.sqrt(1.0 + sigmas[0] ** 2.0)\n",
799
+ " sigmas = sigmas[-img2img_timepoint:].repeat(num_samples,1)\n",
800
+ "\n",
801
+ " base_engine.sampler.num_steps = sigmas.shape[-1] - 1\n",
802
+ " noised_z, _, _, _, c, uc = base_engine.sampler.prepare_sampling_loop(init_z, cond=c, uc=uc, \n",
803
+ " num_steps=base_engine.sampler.num_steps)\n",
804
+ " for timestep in range(base_engine.sampler.num_steps):\n",
805
+ " noised_z = base_engine.sampler.sampler_step(sigmas[:,timestep],\n",
806
+ " sigmas[:,timestep+1],\n",
807
+ " denoiser, noised_z, cond=c, uc=uc, gamma=0)\n",
808
+ " samples_z_base = noised_z\n",
809
+ " samples_x = base_engine.decode_first_stage(samples_z_base)\n",
810
+ " samples = torch.clamp((samples_x + 1.0) / 2.0, min=0.0, max=1.0)\n",
811
+ "\n",
812
+ " # find best sample\n",
813
+ " if plotting==False and num_samples==1:\n",
814
+ " samples = samples[0]\n",
815
+ " else:\n",
816
+ " sample_cossim = nn.functional.cosine_similarity(clip_img_embedder(utils.resize(samples,224).to(device)).flatten(1), \n",
817
+ " clip_img_embedder(utils.resize(all_images[[img_idx]].float(),224).to(device)).flatten(1))\n",
818
+ " which_sample = torch.argmax(sample_cossim)\n",
819
+ " best_cossim = torch.max(sample_cossim)\n",
820
+ "\n",
821
+ " if plotting:\n",
822
+ " print(\"samples\", samples.shape)\n",
823
+ " for n in range(num_samples):\n",
824
+ " recon = transforms.ToPILImage()(samples[n])\n",
825
+ " plt.imshow(recon)\n",
826
+ " plt.show()\n",
827
+ " if (n==which_sample).item(): print(\"CHOSEN ABOVE\")\n",
828
+ " print(\"upsampled pixcorr:\",utils.pixcorr(samples[[n]].cpu(),all_images[[img_idx]].float()))\n",
829
+ " print(\"upsampled cossim:\",nn.functional.cosine_similarity(clip_img_embedder(utils.resize(samples[[n]],224).to(device)).flatten(1), \n",
830
+ " clip_img_embedder(utils.resize(all_images[[img_idx]].float(),224).to(device)).flatten(1)))\n",
831
+ " err # dont want to do entire for loop with plotting=True\n",
832
+ "\n",
833
+ " samples = samples[which_sample]\n",
834
+ "\n",
835
+ " samples = samples.cpu()[None]\n",
836
+ " if all_enhancedrecons is None:\n",
837
+ " all_enhancedrecons = samples\n",
838
+ " else:\n",
839
+ " all_enhancedrecons = torch.vstack((all_enhancedrecons, samples))\n",
840
+ "\n",
841
+ " all_enhancedrecons = transforms.Resize((256,256))(all_enhancedrecons).float()\n",
842
+ " print(\"all_enhancedrecons\", all_enhancedrecons.shape)\n",
843
+ " if final_enhancedrecons is None:\n",
844
+ " final_enhancedrecons = all_enhancedrecons.unsqueeze(0)\n",
845
+ " else:\n",
846
+ " final_enhancedrecons = torch.vstack((final_enhancedrecons, all_enhancedrecons.unsqueeze(0)))\n",
847
+ " \n",
848
+ "\n",
849
+ "# all_enhancedrecons = transforms.Resize((256,256))(all_enhancedrecons).float()\n",
850
+ "print(\"final_enhancedrecons\", final_enhancedrecons.shape)\n",
851
+ "torch.save(final_enhancedrecons,f\"evals/{model_name}/{model_name}_all_enhancedrecons_{mode}.pt\")\n",
852
+ "print(f\"saved evals/{model_name}/{model_name}_all_enhancedrecons_{mode}.pt\")\n",
853
+ "\n",
854
+ "if not utils.is_interactive():\n",
855
+ " sys.exit(0)"
856
+ ]
857
+ },
858
+ {
859
+ "cell_type": "code",
860
+ "execution_count": 7,
861
+ "id": "b9a22a3c-e1a2-4453-beb9-101f6c477486",
862
+ "metadata": {},
863
+ "outputs": [],
864
+ "source": [
865
+ "# plt.imshow(transforms.ToPILImage()(final_enhancedrecons[6,5].float()))\n",
866
+ "# plt.show()"
867
+ ]
868
+ }
869
+ ],
870
+ "metadata": {
871
+ "kernelspec": {
872
+ "display_name": "mindeye",
873
+ "language": "python",
874
+ "name": "mindeye"
875
+ },
876
+ "language_info": {
877
+ "codemirror_mode": {
878
+ "name": "ipython",
879
+ "version": 3
880
+ },
881
+ "file_extension": ".py",
882
+ "mimetype": "text/x-python",
883
+ "name": "python",
884
+ "nbconvert_exporter": "python",
885
+ "pygments_lexer": "ipython3",
886
+ "version": "3.11.10"
887
+ }
888
+ },
889
+ "nbformat": 4,
890
+ "nbformat_minor": 5
891
+ }
MindEyeV2/src/enhanced_recon_inference_old.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
MindEyeV2/src/final_evaluations.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
MindEyeV2/src/recon_inference.py ADDED
@@ -0,0 +1,580 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[1]:
5
+
6
+
7
+ import os
8
+ import sys
9
+ import json
10
+ import argparse
11
+ import numpy as np
12
+ import math
13
+ from einops import rearrange
14
+ import time
15
+ import random
16
+ import string
17
+ import h5py
18
+ from tqdm import tqdm
19
+ import webdataset as wds
20
+
21
+ import matplotlib.pyplot as plt
22
+ import torch
23
+ import torch.nn as nn
24
+ from torchvision import transforms
25
+ from accelerate import Accelerator
26
+
27
+ # SDXL unCLIP requires code from https://github.com/Stability-AI/generative-models/tree/main
28
+ sys.path.append('generative_models/')
29
+ import sgm
30
+ from generative_models.sgm.modules.encoders.modules import FrozenOpenCLIPImageEmbedder, FrozenOpenCLIPEmbedder2
31
+ from generative_models.sgm.models.diffusion import DiffusionEngine
32
+ from generative_models.sgm.util import append_dims
33
+ from omegaconf import OmegaConf
34
+
35
+ # tf32 data type is faster than standard float32
36
+ torch.backends.cuda.matmul.allow_tf32 = True
37
+
38
+ # custom functions #
39
+ import utils
40
+ from models import *
41
+
42
+ accelerator = Accelerator(split_batches=False, mixed_precision="fp16")
43
+ device = accelerator.device
44
+ print("device:",device)
45
+
46
+
47
+ # In[2]:
48
+
49
+
50
+ # if running this interactively, can specify jupyter_args here for argparser to use
51
+ if utils.is_interactive():
52
+ model_name = "final_subj01_pretrained_375trials_24bs"
53
+ print("model_name:", model_name)
54
+
55
+ # other variables can be specified in the following string:
56
+ jupyter_args = f"--data_path=/weka/proj-medarc/shared/mindeyev2_dataset \
57
+ --cache_dir=/weka/proj-medarc/shared/mindeyev2_dataset \
58
+ --model_name={model_name} --subj=1 \
59
+ --hidden_dim=4096 --n_blocks=4 --new_test \
60
+ --mode imagery \
61
+ --imagery_data_path=/weka/proj-medarc/shared/umn-imagery "
62
+ print(jupyter_args)
63
+ jupyter_args = jupyter_args.split()
64
+
65
+ from IPython.display import clear_output # function to clear print outputs in cell
66
+ get_ipython().run_line_magic('load_ext', 'autoreload')
67
+ # this allows you to change functions in models.py or utils.py and have this notebook automatically update with your revisions
68
+ get_ipython().run_line_magic('autoreload', '2')
69
+
70
+
71
+ # In[3]:
72
+
73
+
74
+ parser = argparse.ArgumentParser(description="Model Training Configuration")
75
+ parser.add_argument(
76
+ "--model_name", type=str, default="testing",
77
+ help="will load ckpt for model found in ../train_logs/model_name",
78
+ )
79
+ parser.add_argument(
80
+ "--data_path", type=str, default=os.getcwd(),
81
+ help="Path to where NSD data is stored / where to download it to",
82
+ )
83
+ parser.add_argument(
84
+ "--cache_dir", type=str, default=os.getcwd(),
85
+ help="Path to where misc. files downloaded from huggingface are stored. Defaults to current src directory.",
86
+ )
87
+ parser.add_argument(
88
+ "--subj",type=int, default=1, choices=[1,2,3,4,5,6,7,8],
89
+ help="Validate on which subject?",
90
+ )
91
+ parser.add_argument(
92
+ "--blurry_recon",action=argparse.BooleanOptionalAction,default=True,
93
+ )
94
+ parser.add_argument(
95
+ "--n_blocks",type=int,default=4,
96
+ )
97
+ parser.add_argument(
98
+ "--hidden_dim",type=int,default=2048,
99
+ )
100
+ parser.add_argument(
101
+ "--new_test",action=argparse.BooleanOptionalAction,default=True,
102
+ )
103
+ parser.add_argument(
104
+ "--seed",type=int,default=42,
105
+ )
106
+ parser.add_argument(
107
+ "--mode",type=str,default="vision",choices=["vision","imagery","shared1000"],
108
+ )
109
+ parser.add_argument(
110
+ "--imagery_data_path", type=str, default=os.getcwd(),
111
+ help="Path to where NSD data is stored / where to download it to",
112
+ )
113
+ parser.add_argument(
114
+ "--gen_rep",type=int,default=10,
115
+ )
116
+
117
+ if utils.is_interactive():
118
+ args = parser.parse_args(jupyter_args)
119
+ else:
120
+ args = parser.parse_args()
121
+
122
+ # create global variables without the args prefix
123
+ for attribute_name in vars(args).keys():
124
+ globals()[attribute_name] = getattr(args, attribute_name)
125
+
126
+ # seed all random functions
127
+ utils.seed_everything(seed)
128
+
129
+ # make output directory
130
+ os.makedirs("evals",exist_ok=True)
131
+ os.makedirs(f"evals/{model_name}",exist_ok=True)
132
+
133
+
134
+ # In[4]:
135
+
136
+
137
+ if mode == "synthetic":
138
+ voxels, all_images = utils.load_nsd_synthetic(subject=subj, average=False, nest=True, data_root = imagery_data_path)
139
+ elif subj > 8:
140
+ _, _, voxels, all_images = utils.load_imageryrf(subject=subj-8, mode=mode, stimtype="object", average=False, nest=True, split=True, data_root = imagery_data_path)
141
+ elif mode == "shared1000":
142
+ x_train, valid_nsd_ids_train, x_test, test_nsd_ids = utils.load_nsd(subject=subj, data_path=data_path)
143
+ voxels = torch.mean(x_test, dim=1, keepdim=True)
144
+ print(f"Loaded subj {subj} test betas! {voxels.shape}")
145
+ f = h5py.File(f'{data_path}/coco_images_224_float16.hdf5', 'r')
146
+ images = f['images']
147
+
148
+ all_images = torch.zeros((len(test_nsd_ids), 3, 224, 224))
149
+ for i, idx in enumerate(test_nsd_ids):
150
+ all_images[i] = torch.from_numpy(images[idx])
151
+ del images, f
152
+ print(f"Filtered down to only the {len(test_nsd_ids)} test images for subject {subj}!")
153
+ else:
154
+ voxels, all_images = utils.load_nsd_mental_imagery(subject=subj,
155
+ mode=mode,
156
+ stimtype="all",
157
+ average=True,
158
+ nest=False,
159
+ data_root = imagery_data_path)
160
+ print(voxels.shape)
161
+ num_voxels = voxels.shape[-1]
162
+ plotting = False
163
+
164
+
165
+ # In[5]:
166
+
167
+
168
+ # voxels = {}
169
+ # # Load hdf5 data for betas
170
+ # f = h5py.File(f'{data_path}/betas_all_subj0{subj}_fp32_renorm.hdf5', 'r')
171
+ # betas = f['betas'][:]
172
+ # betas = torch.Tensor(betas).to("cpu")
173
+ # num_voxels = betas[0].shape[-1]
174
+ # voxels[f'subj0{subj}'] = betas
175
+ # print(f"num_voxels for subj0{subj}: {num_voxels}")
176
+
177
+ # if not new_test: # using old test set from before full dataset released (used in original MindEye paper)
178
+ # if subj==3:
179
+ # num_test=2113
180
+ # elif subj==4:
181
+ # num_test=1985
182
+ # elif subj==6:
183
+ # num_test=2113
184
+ # elif subj==8:
185
+ # num_test=1985
186
+ # else:
187
+ # num_test=2770
188
+ # test_url = f"{data_path}/wds/subj0{subj}/test/" + "0.tar"
189
+ # else: # using larger test set from after full dataset released
190
+ # if subj==3:
191
+ # num_test=2371
192
+ # elif subj==4:
193
+ # num_test=2188
194
+ # elif subj==6:
195
+ # num_test=2371
196
+ # elif subj==8:
197
+ # num_test=2188
198
+ # else:
199
+ # num_test=3000
200
+ # test_url = f"{data_path}/wds/subj0{subj}/new_test/" + "0.tar"
201
+
202
+ # print(test_url)
203
+ # def my_split_by_node(urls): return urls
204
+ # test_data = wds.WebDataset(test_url,resampled=False,nodesplitter=my_split_by_node)\
205
+ # .decode("torch")\
206
+ # .rename(behav="behav.npy", past_behav="past_behav.npy", future_behav="future_behav.npy", olds_behav="olds_behav.npy")\
207
+ # .to_tuple(*["behav", "past_behav", "future_behav", "olds_behav"])
208
+ # test_dl = torch.utils.data.DataLoader(test_data, batch_size=num_test, shuffle=False, drop_last=True, pin_memory=True)
209
+ # print(f"Loaded test dl for subj{subj}!\n")
210
+
211
+
212
+ # In[6]:
213
+
214
+
215
+ # # Prep images but don't load them all to memory
216
+ # f = h5py.File(f'{data_path}/coco_images_224_float16.hdf5', 'r')
217
+ # images = f['images']
218
+
219
+ # # Prep test voxels and indices of test images
220
+ # test_images_idx = []
221
+ # test_voxels_idx = []
222
+ # for test_i, (behav, past_behav, future_behav, old_behav) in enumerate(test_dl):
223
+ # test_voxels = voxels[f'subj0{subj}'][behav[:,0,5].cpu().long()]
224
+ # test_voxels_idx = np.append(test_images_idx, behav[:,0,5].cpu().numpy())
225
+ # test_images_idx = np.append(test_images_idx, behav[:,0,0].cpu().numpy())
226
+ # test_images_idx = test_images_idx.astype(int)
227
+ # test_voxels_idx = test_voxels_idx.astype(int)
228
+
229
+ # assert (test_i+1) * num_test == len(test_voxels) == len(test_images_idx)
230
+ # print(test_i, len(test_voxels), len(test_images_idx), len(np.unique(test_images_idx)))
231
+
232
+
233
+ # In[7]:
234
+
235
+
236
+ clip_img_embedder = FrozenOpenCLIPImageEmbedder(
237
+ arch="ViT-bigG-14",
238
+ version="laion2b_s39b_b160k",
239
+ output_tokens=True,
240
+ only_tokens=True,
241
+ )
242
+ clip_img_embedder.to(device)
243
+ clip_seq_dim = 256
244
+ clip_emb_dim = 1664
245
+
246
+ if blurry_recon:
247
+ from diffusers import AutoencoderKL
248
+ autoenc = AutoencoderKL(
249
+ down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D'],
250
+ up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D'],
251
+ block_out_channels=[128, 256, 512, 512],
252
+ layers_per_block=2,
253
+ sample_size=256,
254
+ )
255
+ ckpt = torch.load(f'{cache_dir}/sd_image_var_autoenc.pth')
256
+ autoenc.load_state_dict(ckpt)
257
+ autoenc.eval()
258
+ autoenc.requires_grad_(False)
259
+ autoenc.to(device)
260
+ utils.count_params(autoenc)
261
+
262
+ class MindEyeModule(nn.Module):
263
+ def __init__(self):
264
+ super(MindEyeModule, self).__init__()
265
+ def forward(self, x):
266
+ return x
267
+
268
+ model = MindEyeModule()
269
+
270
+ class RidgeRegression(torch.nn.Module):
271
+ # make sure to add weight_decay when initializing optimizer to enable regularization
272
+ def __init__(self, input_sizes, out_features):
273
+ super(RidgeRegression, self).__init__()
274
+ self.out_features = out_features
275
+ self.linears = torch.nn.ModuleList([
276
+ torch.nn.Linear(input_size, out_features) for input_size in input_sizes
277
+ ])
278
+ def forward(self, x, subj_idx):
279
+ out = self.linears[subj_idx](x[:,0]).unsqueeze(1)
280
+ return out
281
+
282
+ model.ridge = RidgeRegression([num_voxels], out_features=hidden_dim)
283
+
284
+ from diffusers.models.vae import Decoder
285
+ from models import BrainNetwork
286
+ model.backbone = BrainNetwork(h=hidden_dim, in_dim=hidden_dim, seq_len=1,
287
+ clip_size=clip_emb_dim, out_dim=clip_emb_dim*clip_seq_dim)
288
+ utils.count_params(model.ridge)
289
+ utils.count_params(model.backbone)
290
+ utils.count_params(model)
291
+
292
+ # setup diffusion prior network
293
+ out_dim = clip_emb_dim
294
+ depth = 6
295
+ dim_head = 52
296
+ heads = clip_emb_dim//52 # heads * dim_head = clip_emb_dim
297
+ timesteps = 100
298
+
299
+ prior_network = PriorNetwork(
300
+ dim=out_dim,
301
+ depth=depth,
302
+ dim_head=dim_head,
303
+ heads=heads,
304
+ causal=False,
305
+ num_tokens = clip_seq_dim,
306
+ learned_query_mode="pos_emb"
307
+ )
308
+
309
+ model.diffusion_prior = BrainDiffusionPrior(
310
+ net=prior_network,
311
+ image_embed_dim=out_dim,
312
+ condition_on_text_encodings=False,
313
+ timesteps=timesteps,
314
+ cond_drop_prob=0.2,
315
+ image_embed_scale=None,
316
+ )
317
+ model.to(device)
318
+
319
+ utils.count_params(model.diffusion_prior)
320
+ utils.count_params(model)
321
+
322
+ # Load pretrained model ckpt
323
+ tag='last'
324
+ outdir = os.path.abspath(f'../train_logs/{model_name}')
325
+ print(f"\n---loading {outdir}/{tag}.pth ckpt---\n")
326
+ try:
327
+ checkpoint = torch.load(outdir+f'/{tag}.pth', map_location='cpu')
328
+ state_dict = checkpoint['model_state_dict']
329
+ model.load_state_dict(state_dict, strict=True)
330
+ del checkpoint
331
+ except: # probably ckpt is saved using deepspeed format
332
+ import deepspeed
333
+ state_dict = deepspeed.utils.zero_to_fp32.get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir=outdir, tag=tag)
334
+ model.load_state_dict(state_dict, strict=False)
335
+ del state_dict
336
+ print("ckpt loaded!")
337
+
338
+
339
+ # In[8]:
340
+
341
+
342
+ # setup text caption networks
343
+ from transformers import AutoProcessor, AutoModelForCausalLM
344
+ from modeling_git import GitForCausalLMClipEmb
345
+ processor = AutoProcessor.from_pretrained("microsoft/git-large-coco")
346
+ clip_text_model = GitForCausalLMClipEmb.from_pretrained("microsoft/git-large-coco")
347
+ clip_text_model.to(device) # if you get OOM running this script, you can switch this to cpu and lower minibatch_size to 4
348
+ clip_text_model.eval().requires_grad_(False)
349
+ clip_text_seq_dim = 257
350
+ clip_text_emb_dim = 1024
351
+
352
+ class CLIPConverter(torch.nn.Module):
353
+ def __init__(self):
354
+ super(CLIPConverter, self).__init__()
355
+ self.linear1 = nn.Linear(clip_seq_dim, clip_text_seq_dim)
356
+ self.linear2 = nn.Linear(clip_emb_dim, clip_text_emb_dim)
357
+ def forward(self, x):
358
+ x = x.permute(0,2,1)
359
+ x = self.linear1(x)
360
+ x = self.linear2(x.permute(0,2,1))
361
+ return x
362
+
363
+ clip_convert = CLIPConverter()
364
+ state_dict = torch.load(f"{cache_dir}/bigG_to_L_epoch8.pth", map_location='cpu')['model_state_dict']
365
+ clip_convert.load_state_dict(state_dict, strict=True)
366
+ clip_convert.to(device) # if you get OOM running this script, you can switch this to cpu and lower minibatch_size to 4
367
+ del state_dict
368
+
369
+
370
+ # In[9]:
371
+
372
+
373
+ # prep unCLIP
374
+ config = OmegaConf.load("generative_models/configs/unclip6.yaml")
375
+ config = OmegaConf.to_container(config, resolve=True)
376
+ unclip_params = config["model"]["params"]
377
+ network_config = unclip_params["network_config"]
378
+ denoiser_config = unclip_params["denoiser_config"]
379
+ first_stage_config = unclip_params["first_stage_config"]
380
+ conditioner_config = unclip_params["conditioner_config"]
381
+ sampler_config = unclip_params["sampler_config"]
382
+ scale_factor = unclip_params["scale_factor"]
383
+ disable_first_stage_autocast = unclip_params["disable_first_stage_autocast"]
384
+ offset_noise_level = unclip_params["loss_fn_config"]["params"]["offset_noise_level"]
385
+
386
+ first_stage_config['target'] = 'sgm.models.autoencoder.AutoencoderKL'
387
+ sampler_config['params']['num_steps'] = 38
388
+
389
+ diffusion_engine = DiffusionEngine(network_config=network_config,
390
+ denoiser_config=denoiser_config,
391
+ first_stage_config=first_stage_config,
392
+ conditioner_config=conditioner_config,
393
+ sampler_config=sampler_config,
394
+ scale_factor=scale_factor,
395
+ disable_first_stage_autocast=disable_first_stage_autocast)
396
+ # set to inference
397
+ diffusion_engine.eval().requires_grad_(False)
398
+ diffusion_engine.to(device)
399
+
400
+ ckpt_path = f'{cache_dir}/unclip6_epoch0_step110000.ckpt'
401
+ ckpt = torch.load(ckpt_path, map_location='cpu')
402
+ diffusion_engine.load_state_dict(ckpt['state_dict'])
403
+
404
+ batch={"jpg": torch.randn(1,3,1,1).to(device), # jpg doesnt get used, it's just a placeholder
405
+ "original_size_as_tuple": torch.ones(1, 2).to(device) * 768,
406
+ "crop_coords_top_left": torch.zeros(1, 2).to(device)}
407
+ out = diffusion_engine.conditioner(batch)
408
+ vector_suffix = out["vector"].to(device)
409
+ print("vector_suffix", vector_suffix.shape)
410
+
411
+
412
+ # In[10]:
413
+
414
+
415
+ from tqdm.auto import tqdm
416
+ # get all reconstructions
417
+ model.to(device)
418
+ model.eval().requires_grad_(False)
419
+
420
+ final_all_recons = None
421
+ final_all_blurryrecons = None
422
+ final_all_predcaptions = []
423
+ final_all_clipvoxels = None
424
+
425
+ for rep in tqdm(range(gen_rep)):
426
+ # all_images = None
427
+ all_blurryrecons = None
428
+ all_recons = None
429
+ all_predcaptions = []
430
+ all_clipvoxels = None
431
+
432
+ minibatch_size = 1
433
+ num_samples_per_image = 1
434
+ assert num_samples_per_image == 1
435
+
436
+ if utils.is_interactive(): plotting=False
437
+
438
+ with torch.no_grad(), torch.cuda.amp.autocast(dtype=torch.float16):
439
+ for idx, imagery_voxel in enumerate(voxels):
440
+ # uniq_imgs = np.unique(test_images_idx)[batch:batch+minibatch_size]
441
+ # voxel = None
442
+ # for uniq_img in uniq_imgs:
443
+ # locs = np.where(test_images_idx==uniq_img)[0]
444
+ # if len(locs)==1:
445
+ # locs = locs.repeat(3)
446
+ # elif len(locs)==2:
447
+ # locs = locs.repeat(2)[:3]
448
+ # assert len(locs)==3
449
+ # if voxel is None:
450
+ # voxel = test_voxels[None,locs] # 1, num_image_repetitions, num_voxels
451
+ # else:
452
+ # voxel = torch.vstack((voxel, test_voxels[None,locs]))
453
+ voxel = imagery_voxel.to(device)
454
+ print(voxel.shape, voxel.shape)
455
+ for rep in range(1):
456
+ voxel_ridge = model.ridge(voxel.unsqueeze(0),0) # 0th index of subj_list
457
+ backbone0, clip_voxels0, blurry_image_enc0 = model.backbone(voxel_ridge)
458
+ if rep==0:
459
+ clip_voxels = clip_voxels0
460
+ backbone = backbone0
461
+ blurry_image_enc = blurry_image_enc0[0]
462
+ else:
463
+ clip_voxels += clip_voxels0
464
+ backbone += backbone0
465
+ blurry_image_enc += blurry_image_enc0[0]
466
+ clip_voxels /= 1
467
+ backbone /= 1
468
+ blurry_image_enc /= 1
469
+
470
+ # Save retrieval submodule outputs
471
+ if all_clipvoxels is None:
472
+ all_clipvoxels = clip_voxels.cpu()
473
+ else:
474
+ all_clipvoxels = torch.vstack((all_clipvoxels, clip_voxels.cpu()))
475
+
476
+ # Feed voxels through OpenCLIP-bigG diffusion prior
477
+ prior_out = model.diffusion_prior.p_sample_loop(backbone.shape,
478
+ text_cond = dict(text_embed = backbone),
479
+ cond_scale = 1., timesteps = 20)
480
+
481
+ pred_caption_emb = clip_convert(prior_out)
482
+ generated_ids = clip_text_model.generate(pixel_values=pred_caption_emb, max_length=20)
483
+ generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)
484
+ all_predcaptions = np.hstack((all_predcaptions, generated_caption))
485
+ print(generated_caption)
486
+
487
+ # Feed diffusion prior outputs through unCLIP
488
+ for i in range(len(voxel)):
489
+ samples = utils.unclip_recon(prior_out[[i]],
490
+ diffusion_engine,
491
+ vector_suffix,
492
+ num_samples=num_samples_per_image)
493
+ if all_recons is None:
494
+ all_recons = samples.cpu()
495
+ else:
496
+ all_recons = torch.vstack((all_recons, samples.cpu()))
497
+ if plotting:
498
+ for s in range(num_samples_per_image):
499
+ plt.figure(figsize=(2,2))
500
+ plt.imshow(transforms.ToPILImage()(samples[s]))
501
+ plt.axis('off')
502
+ plt.show()
503
+
504
+ if blurry_recon:
505
+ blurred_image = (autoenc.decode(blurry_image_enc/0.18215).sample/ 2 + 0.5).clamp(0,1)
506
+
507
+ for i in range(len(voxel)):
508
+ im = torch.Tensor(blurred_image[i])
509
+ if all_blurryrecons is None:
510
+ all_blurryrecons = im[None].cpu()
511
+ else:
512
+ all_blurryrecons = torch.vstack((all_blurryrecons, im[None].cpu()))
513
+ if plotting:
514
+ plt.figure(figsize=(2,2))
515
+ plt.imshow(transforms.ToPILImage()(im))
516
+ plt.axis('off')
517
+ plt.show()
518
+
519
+ if plotting:
520
+ print(model_name)
521
+ err # dont actually want to run the whole thing with plotting=True
522
+
523
+ # resize outputs before saving
524
+ imsize = 256
525
+ all_recons = transforms.Resize((imsize,imsize))(all_recons).float()
526
+ if blurry_recon:
527
+ all_blurryrecons = transforms.Resize((imsize,imsize))(all_blurryrecons).float()
528
+
529
+ # saving
530
+ print(all_recons.shape)
531
+ # # You can find the all_images file on huggingface: https://huggingface.co/datasets/pscotti/mindeyev2/tree/main/evals
532
+ # torch.save(all_images,"evals/all_images.pt")
533
+ # if blurry_recon:
534
+ # torch.save(all_blurryrecons,f"evals/{model_name}/{model_name}_all_blurryrecons.pt")
535
+ # torch.save(all_recons,f"evals/{model_name}/{model_name}_all_recons.pt")
536
+ # torch.save(all_predcaptions,f"evals/{model_name}/{model_name}_all_predcaptions.pt")
537
+ # torch.save(all_clipvoxels,f"evals/{model_name}/{model_name}_all_clipvoxels.pt")
538
+
539
+ if final_all_recons is None:
540
+ if blurry_recon:
541
+ final_all_blurryrecons = all_blurryrecons.unsqueeze(1)
542
+ final_all_recons = all_recons.unsqueeze(1)
543
+ final_all_predcaptions = all_predcaptions.copy()
544
+ final_all_clipvoxels = all_clipvoxels.unsqueeze(1)
545
+ else:
546
+ if blurry_recon:
547
+ final_all_blurryrecons = torch.cat((final_all_blurryrecons, all_blurryrecons.unsqueeze(1)), dim=1)
548
+ final_all_recons = torch.cat((final_all_recons, all_recons.unsqueeze(1)), dim=1)
549
+ final_all_predcaptions = np.hstack((final_all_predcaptions, all_predcaptions))
550
+ final_all_clipvoxels = torch.cat((final_all_clipvoxels, all_clipvoxels.unsqueeze(1)), dim=1)
551
+
552
+
553
+ # saving
554
+ print(final_all_recons.shape)
555
+ # You can find the all_images file on huggingface: https://huggingface.co/datasets/pscotti/mindeyev2/tree/main/evals
556
+ # torch.save(all_images,"evals/all_images.pt")
557
+
558
+
559
+ # if blurry_recon:
560
+ # torch.save(final_blurryrecons.half(),f"evals/{model_name}/{model_name}_all_blurryrecons_{mode}.pt")
561
+ # torch.save(final_recons.half(),f"evals/{model_name}/{model_name}_all_recons_{mode}.pt")
562
+
563
+ if blurry_recon:
564
+ torch.save(final_all_blurryrecons,f"evals/{model_name}/{model_name}_all_blurryrecons_{mode}.pt")
565
+ torch.save(final_all_recons,f"evals/{model_name}/{model_name}_all_recons_{mode}.pt")
566
+ torch.save(final_all_predcaptions,f"evals/{model_name}/{model_name}_all_predcaptions_{mode}.pt")
567
+ torch.save(final_all_clipvoxels,f"evals/{model_name}/{model_name}_all_clipvoxels_{mode}.pt")
568
+
569
+
570
+ print(f"saved {model_name} outputs!")
571
+
572
+ if not utils.is_interactive():
573
+ sys.exit(0)
574
+
575
+
576
+ # In[11]:
577
+
578
+
579
+ torch.save(all_images,"evals/all_images.pt")
580
+
MindEyeV2/src/recon_inference_old.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
MindEyeV2/src/recon_inference_old.py ADDED
@@ -0,0 +1,492 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[1]:
5
+
6
+
7
+ import os
8
+ import sys
9
+ import json
10
+ import argparse
11
+ import numpy as np
12
+ import math
13
+ from einops import rearrange
14
+ import time
15
+ import random
16
+ import string
17
+ import h5py
18
+ from tqdm import tqdm
19
+ import webdataset as wds
20
+
21
+ import matplotlib.pyplot as plt
22
+ import torch
23
+ import torch.nn as nn
24
+ from torchvision import transforms
25
+ from accelerate import Accelerator
26
+
27
+ # SDXL unCLIP requires code from https://github.com/Stability-AI/generative-models/tree/main
28
+ sys.path.append('generative_models/')
29
+ import sgm
30
+ from generative_models.sgm.modules.encoders.modules import FrozenOpenCLIPImageEmbedder, FrozenOpenCLIPEmbedder2
31
+ from generative_models.sgm.models.diffusion import DiffusionEngine
32
+ from generative_models.sgm.util import append_dims
33
+ from omegaconf import OmegaConf
34
+
35
+ # tf32 data type is faster than standard float32
36
+ torch.backends.cuda.matmul.allow_tf32 = True
37
+
38
+ # custom functions #
39
+ import utils
40
+ from models import *
41
+
42
+ accelerator = Accelerator(split_batches=False, mixed_precision="fp16")
43
+ device = accelerator.device
44
+ print("device:",device)
45
+ plotting = False
46
+
47
+
48
+ # In[2]:
49
+
50
+
51
+ # if running this interactively, can specify jupyter_args here for argparser to use
52
+ if utils.is_interactive():
53
+ model_name = "final_subj01_pretrained_3sess_24bs"
54
+ print("model_name:", model_name)
55
+
56
+ # other variables can be specified in the following string:
57
+ jupyter_args = f"--data_path=/weka/proj-medarc/shared/mindeyev2_dataset \
58
+ --cache_dir=/weka/proj-medarc/shared/mindeyev2_dataset \
59
+ --model_name={model_name} --subj=1 \
60
+ --hidden_dim=4096 --n_blocks=4 --new_test"
61
+ print(jupyter_args)
62
+ jupyter_args = jupyter_args.split()
63
+
64
+ from IPython.display import clear_output # function to clear print outputs in cell
65
+ get_ipython().run_line_magic('load_ext', 'autoreload')
66
+ # this allows you to change functions in models.py or utils.py and have this notebook automatically update with your revisions
67
+ get_ipython().run_line_magic('autoreload', '2')
68
+
69
+
70
+ # In[3]:
71
+
72
+
73
+ parser = argparse.ArgumentParser(description="Model Training Configuration")
74
+ parser.add_argument(
75
+ "--model_name", type=str, default="testing",
76
+ help="will load ckpt for model found in ../train_logs/model_name",
77
+ )
78
+ parser.add_argument(
79
+ "--data_path", type=str, default=os.getcwd(),
80
+ help="Path to where NSD data is stored / where to download it to",
81
+ )
82
+ parser.add_argument(
83
+ "--cache_dir", type=str, default=os.getcwd(),
84
+ help="Path to where misc. files downloaded from huggingface are stored. Defaults to current src directory.",
85
+ )
86
+ parser.add_argument(
87
+ "--subj",type=int, default=1, choices=[1,2,3,4,5,6,7,8],
88
+ help="Validate on which subject?",
89
+ )
90
+ parser.add_argument(
91
+ "--blurry_recon",action=argparse.BooleanOptionalAction,default=True,
92
+ )
93
+ parser.add_argument(
94
+ "--n_blocks",type=int,default=4,
95
+ )
96
+ parser.add_argument(
97
+ "--hidden_dim",type=int,default=2048,
98
+ )
99
+ parser.add_argument(
100
+ "--new_test",action=argparse.BooleanOptionalAction,default=True,
101
+ )
102
+ parser.add_argument(
103
+ "--seed",type=int,default=42,
104
+ )
105
+ if utils.is_interactive():
106
+ args = parser.parse_args(jupyter_args)
107
+ else:
108
+ args = parser.parse_args()
109
+
110
+ # create global variables without the args prefix
111
+ for attribute_name in vars(args).keys():
112
+ globals()[attribute_name] = getattr(args, attribute_name)
113
+
114
+ # seed all random functions
115
+ utils.seed_everything(seed)
116
+
117
+ # make output directory
118
+ os.makedirs("evals",exist_ok=True)
119
+ os.makedirs(f"evals/{model_name}",exist_ok=True)
120
+
121
+
122
+ # In[4]:
123
+
124
+
125
+ voxels = {}
126
+ # Load hdf5 data for betas
127
+ f = h5py.File(f'{data_path}/betas_all_subj0{subj}_fp32_renorm.hdf5', 'r')
128
+ betas = f['betas'][:]
129
+ betas = torch.Tensor(betas).to("cpu")
130
+ num_voxels = betas[0].shape[-1]
131
+ voxels[f'subj0{subj}'] = betas
132
+ print(f"num_voxels for subj0{subj}: {num_voxels}")
133
+
134
+ if not new_test: # using old test set from before full dataset released (used in original MindEye paper)
135
+ if subj==3:
136
+ num_test=2113
137
+ elif subj==4:
138
+ num_test=1985
139
+ elif subj==6:
140
+ num_test=2113
141
+ elif subj==8:
142
+ num_test=1985
143
+ else:
144
+ num_test=2770
145
+ test_url = f"{data_path}/wds/subj0{subj}/test/" + "0.tar"
146
+ else: # using larger test set from after full dataset released
147
+ if subj==3:
148
+ num_test=2371
149
+ elif subj==4:
150
+ num_test=2188
151
+ elif subj==6:
152
+ num_test=2371
153
+ elif subj==8:
154
+ num_test=2188
155
+ else:
156
+ num_test=3000
157
+ test_url = f"{data_path}/wds/subj0{subj}/new_test/" + "0.tar"
158
+
159
+ print(test_url)
160
+ def my_split_by_node(urls): return urls
161
+ test_data = wds.WebDataset(test_url,resampled=False,nodesplitter=my_split_by_node)\
162
+ .decode("torch")\
163
+ .rename(behav="behav.npy", past_behav="past_behav.npy", future_behav="future_behav.npy", olds_behav="olds_behav.npy")\
164
+ .to_tuple(*["behav", "past_behav", "future_behav", "olds_behav"])
165
+ test_dl = torch.utils.data.DataLoader(test_data, batch_size=num_test, shuffle=False, drop_last=True, pin_memory=True)
166
+ print(f"Loaded test dl for subj{subj}!\n")
167
+
168
+
169
+ # In[5]:
170
+
171
+
172
+ # Prep images but don't load them all to memory
173
+ f = h5py.File(f'{data_path}/coco_images_224_float16.hdf5', 'r')
174
+ images = f['images']
175
+
176
+ # Prep test voxels and indices of test images
177
+ test_images_idx = []
178
+ test_voxels_idx = []
179
+ for test_i, (behav, past_behav, future_behav, old_behav) in enumerate(test_dl):
180
+ test_voxels = voxels[f'subj0{subj}'][behav[:,0,5].cpu().long()]
181
+ test_voxels_idx = np.append(test_images_idx, behav[:,0,5].cpu().numpy())
182
+ test_images_idx = np.append(test_images_idx, behav[:,0,0].cpu().numpy())
183
+ test_images_idx = test_images_idx.astype(int)
184
+ test_voxels_idx = test_voxels_idx.astype(int)
185
+
186
+ assert (test_i+1) * num_test == len(test_voxels) == len(test_images_idx)
187
+ print(test_i, len(test_voxels), len(test_images_idx), len(np.unique(test_images_idx)))
188
+
189
+
190
+ # In[6]:
191
+
192
+
193
+ clip_img_embedder = FrozenOpenCLIPImageEmbedder(
194
+ arch="ViT-bigG-14",
195
+ version="laion2b_s39b_b160k",
196
+ output_tokens=True,
197
+ only_tokens=True,
198
+ )
199
+ clip_img_embedder.to(device)
200
+ clip_seq_dim = 256
201
+ clip_emb_dim = 1664
202
+
203
+ if blurry_recon:
204
+ from diffusers import AutoencoderKL
205
+ autoenc = AutoencoderKL(
206
+ down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D'],
207
+ up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D'],
208
+ block_out_channels=[128, 256, 512, 512],
209
+ layers_per_block=2,
210
+ sample_size=256,
211
+ )
212
+ ckpt = torch.load(f'{cache_dir}/sd_image_var_autoenc.pth')
213
+ autoenc.load_state_dict(ckpt)
214
+ autoenc.eval()
215
+ autoenc.requires_grad_(False)
216
+ autoenc.to(device)
217
+ utils.count_params(autoenc)
218
+
219
+ class MindEyeModule(nn.Module):
220
+ def __init__(self):
221
+ super(MindEyeModule, self).__init__()
222
+ def forward(self, x):
223
+ return x
224
+
225
+ model = MindEyeModule()
226
+
227
+ class RidgeRegression(torch.nn.Module):
228
+ # make sure to add weight_decay when initializing optimizer to enable regularization
229
+ def __init__(self, input_sizes, out_features):
230
+ super(RidgeRegression, self).__init__()
231
+ self.out_features = out_features
232
+ self.linears = torch.nn.ModuleList([
233
+ torch.nn.Linear(input_size, out_features) for input_size in input_sizes
234
+ ])
235
+ def forward(self, x, subj_idx):
236
+ out = self.linears[subj_idx](x[:,0]).unsqueeze(1)
237
+ return out
238
+
239
+ model.ridge = RidgeRegression([num_voxels], out_features=hidden_dim)
240
+
241
+ from diffusers.models.vae import Decoder
242
+ from models import BrainNetwork
243
+ model.backbone = BrainNetwork(h=hidden_dim, in_dim=hidden_dim, seq_len=1,
244
+ clip_size=clip_emb_dim, out_dim=clip_emb_dim*clip_seq_dim)
245
+ utils.count_params(model.ridge)
246
+ utils.count_params(model.backbone)
247
+ utils.count_params(model)
248
+
249
+ # setup diffusion prior network
250
+ out_dim = clip_emb_dim
251
+ depth = 6
252
+ dim_head = 52
253
+ heads = clip_emb_dim//52 # heads * dim_head = clip_emb_dim
254
+ timesteps = 100
255
+
256
+ prior_network = PriorNetwork(
257
+ dim=out_dim,
258
+ depth=depth,
259
+ dim_head=dim_head,
260
+ heads=heads,
261
+ causal=False,
262
+ num_tokens = clip_seq_dim,
263
+ learned_query_mode="pos_emb"
264
+ )
265
+
266
+ model.diffusion_prior = BrainDiffusionPrior(
267
+ net=prior_network,
268
+ image_embed_dim=out_dim,
269
+ condition_on_text_encodings=False,
270
+ timesteps=timesteps,
271
+ cond_drop_prob=0.2,
272
+ image_embed_scale=None,
273
+ )
274
+ model.to(device)
275
+
276
+ utils.count_params(model.diffusion_prior)
277
+ utils.count_params(model)
278
+
279
+ # Load pretrained model ckpt
280
+ tag='last'
281
+ outdir = os.path.abspath(f'../train_logs/{model_name}')
282
+ print(f"\n---loading {outdir}/{tag}.pth ckpt---\n")
283
+ try:
284
+ checkpoint = torch.load(outdir+f'/{tag}.pth', map_location='cpu')
285
+ state_dict = checkpoint['model_state_dict']
286
+ model.load_state_dict(state_dict, strict=True)
287
+ del checkpoint
288
+ except: # probably ckpt is saved using deepspeed format
289
+ import deepspeed
290
+ state_dict = deepspeed.utils.zero_to_fp32.get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir=outdir, tag=tag)
291
+ model.load_state_dict(state_dict, strict=False)
292
+ del state_dict
293
+ print("ckpt loaded!")
294
+
295
+
296
+ # In[7]:
297
+
298
+
299
+ # setup text caption networks
300
+ from transformers import AutoProcessor, AutoModelForCausalLM
301
+ from modeling_git import GitForCausalLMClipEmb
302
+ processor = AutoProcessor.from_pretrained("microsoft/git-large-coco")
303
+ clip_text_model = GitForCausalLMClipEmb.from_pretrained("microsoft/git-large-coco")
304
+ clip_text_model.to(device) # if you get OOM running this script, you can switch this to cpu and lower minibatch_size to 4
305
+ clip_text_model.eval().requires_grad_(False)
306
+ clip_text_seq_dim = 257
307
+ clip_text_emb_dim = 1024
308
+
309
+ class CLIPConverter(torch.nn.Module):
310
+ def __init__(self):
311
+ super(CLIPConverter, self).__init__()
312
+ self.linear1 = nn.Linear(clip_seq_dim, clip_text_seq_dim)
313
+ self.linear2 = nn.Linear(clip_emb_dim, clip_text_emb_dim)
314
+ def forward(self, x):
315
+ x = x.permute(0,2,1)
316
+ x = self.linear1(x)
317
+ x = self.linear2(x.permute(0,2,1))
318
+ return x
319
+
320
+ clip_convert = CLIPConverter()
321
+ state_dict = torch.load(f"{cache_dir}/bigG_to_L_epoch8.pth", map_location='cpu')['model_state_dict']
322
+ clip_convert.load_state_dict(state_dict, strict=True)
323
+ clip_convert.to(device) # if you get OOM running this script, you can switch this to cpu and lower minibatch_size to 4
324
+ del state_dict
325
+
326
+
327
+ # In[8]:
328
+
329
+
330
+ # prep unCLIP
331
+ config = OmegaConf.load("generative_models/configs/unclip6.yaml")
332
+ config = OmegaConf.to_container(config, resolve=True)
333
+ unclip_params = config["model"]["params"]
334
+ network_config = unclip_params["network_config"]
335
+ denoiser_config = unclip_params["denoiser_config"]
336
+ first_stage_config = unclip_params["first_stage_config"]
337
+ conditioner_config = unclip_params["conditioner_config"]
338
+ sampler_config = unclip_params["sampler_config"]
339
+ scale_factor = unclip_params["scale_factor"]
340
+ disable_first_stage_autocast = unclip_params["disable_first_stage_autocast"]
341
+ offset_noise_level = unclip_params["loss_fn_config"]["params"]["offset_noise_level"]
342
+
343
+ first_stage_config['target'] = 'sgm.models.autoencoder.AutoencoderKL'
344
+ sampler_config['params']['num_steps'] = 38
345
+
346
+ diffusion_engine = DiffusionEngine(network_config=network_config,
347
+ denoiser_config=denoiser_config,
348
+ first_stage_config=first_stage_config,
349
+ conditioner_config=conditioner_config,
350
+ sampler_config=sampler_config,
351
+ scale_factor=scale_factor,
352
+ disable_first_stage_autocast=disable_first_stage_autocast)
353
+ # set to inference
354
+ diffusion_engine.eval().requires_grad_(False)
355
+ diffusion_engine.to(device)
356
+
357
+ ckpt_path = f'{cache_dir}/unclip6_epoch0_step110000.ckpt'
358
+ ckpt = torch.load(ckpt_path, map_location='cpu')
359
+ diffusion_engine.load_state_dict(ckpt['state_dict'])
360
+
361
+ batch={"jpg": torch.randn(1,3,1,1).to(device), # jpg doesnt get used, it's just a placeholder
362
+ "original_size_as_tuple": torch.ones(1, 2).to(device) * 768,
363
+ "crop_coords_top_left": torch.zeros(1, 2).to(device)}
364
+ out = diffusion_engine.conditioner(batch)
365
+ vector_suffix = out["vector"].to(device)
366
+ print("vector_suffix", vector_suffix.shape)
367
+
368
+
369
+ # In[9]:
370
+
371
+
372
+ # get all reconstructions
373
+ model.to(device)
374
+ model.eval().requires_grad_(False)
375
+
376
+ # all_images = None
377
+ all_blurryrecons = None
378
+ all_recons = None
379
+ all_predcaptions = []
380
+ all_clipvoxels = None
381
+
382
+ minibatch_size = 1
383
+ num_samples_per_image = 1
384
+ assert num_samples_per_image == 1
385
+
386
+ if utils.is_interactive(): plotting=True
387
+
388
+ with torch.no_grad(), torch.cuda.amp.autocast(dtype=torch.float16):
389
+ for batch in tqdm(range(0,len(np.unique(test_images_idx)),minibatch_size)):
390
+ uniq_imgs = np.unique(test_images_idx)[batch:batch+minibatch_size]
391
+ voxel = None
392
+ for uniq_img in uniq_imgs:
393
+ locs = np.where(test_images_idx==uniq_img)[0]
394
+ if len(locs)==1:
395
+ locs = locs.repeat(3)
396
+ elif len(locs)==2:
397
+ locs = locs.repeat(2)[:3]
398
+ assert len(locs)==3
399
+ if voxel is None:
400
+ voxel = test_voxels[None,locs] # 1, num_image_repetitions, num_voxels
401
+ else:
402
+ voxel = torch.vstack((voxel, test_voxels[None,locs]))
403
+ voxel = voxel.to(device)
404
+
405
+ for rep in range(3):
406
+ voxel_ridge = model.ridge(voxel[:,[rep]],0) # 0th index of subj_list
407
+ backbone0, clip_voxels0, blurry_image_enc0 = model.backbone(voxel_ridge)
408
+ if rep==0:
409
+ clip_voxels = clip_voxels0
410
+ backbone = backbone0
411
+ blurry_image_enc = blurry_image_enc0[0]
412
+ else:
413
+ clip_voxels += clip_voxels0
414
+ backbone += backbone0
415
+ blurry_image_enc += blurry_image_enc0[0]
416
+ clip_voxels /= 3
417
+ backbone /= 3
418
+ blurry_image_enc /= 3
419
+
420
+ # Save retrieval submodule outputs
421
+ if all_clipvoxels is None:
422
+ all_clipvoxels = clip_voxels.cpu()
423
+ else:
424
+ all_clipvoxels = torch.vstack((all_clipvoxels, clip_voxels.cpu()))
425
+
426
+ # Feed voxels through OpenCLIP-bigG diffusion prior
427
+ prior_out = model.diffusion_prior.p_sample_loop(backbone.shape,
428
+ text_cond = dict(text_embed = backbone),
429
+ cond_scale = 1., timesteps = 20)
430
+
431
+ pred_caption_emb = clip_convert(prior_out)
432
+ generated_ids = clip_text_model.generate(pixel_values=pred_caption_emb, max_length=20)
433
+ generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)
434
+ all_predcaptions = np.hstack((all_predcaptions, generated_caption))
435
+ print(generated_caption)
436
+
437
+ # Feed diffusion prior outputs through unCLIP
438
+ for i in range(len(voxel)):
439
+ samples = utils.unclip_recon(prior_out[[i]],
440
+ diffusion_engine,
441
+ vector_suffix,
442
+ num_samples=num_samples_per_image)
443
+ if all_recons is None:
444
+ all_recons = samples.cpu()
445
+ else:
446
+ all_recons = torch.vstack((all_recons, samples.cpu()))
447
+ if plotting:
448
+ for s in range(num_samples_per_image):
449
+ plt.figure(figsize=(2,2))
450
+ plt.imshow(transforms.ToPILImage()(samples[s]))
451
+ plt.axis('off')
452
+ plt.show()
453
+
454
+ if blurry_recon:
455
+ blurred_image = (autoenc.decode(blurry_image_enc/0.18215).sample/ 2 + 0.5).clamp(0,1)
456
+
457
+ for i in range(len(voxel)):
458
+ im = torch.Tensor(blurred_image[i])
459
+ if all_blurryrecons is None:
460
+ all_blurryrecons = im[None].cpu()
461
+ else:
462
+ all_blurryrecons = torch.vstack((all_blurryrecons, im[None].cpu()))
463
+ if plotting:
464
+ plt.figure(figsize=(2,2))
465
+ plt.imshow(transforms.ToPILImage()(im))
466
+ plt.axis('off')
467
+ plt.show()
468
+
469
+ if plotting:
470
+ print(model_name)
471
+ err # dont actually want to run the whole thing with plotting=True
472
+
473
+ # resize outputs before saving
474
+ imsize = 256
475
+ all_recons = transforms.Resize((imsize,imsize))(all_recons).float()
476
+ if blurry_recon:
477
+ all_blurryrecons = transforms.Resize((imsize,imsize))(all_blurryrecons).float()
478
+
479
+ # saving
480
+ print(all_recons.shape)
481
+ # # You can find the all_images file on huggingface: https://huggingface.co/datasets/pscotti/mindeyev2/tree/main/evals
482
+ # torch.save(all_images,"evals/all_images.pt")
483
+ if blurry_recon:
484
+ torch.save(all_blurryrecons,f"evals/{model_name}/{model_name}_all_blurryrecons.pt")
485
+ torch.save(all_recons,f"evals/{model_name}/{model_name}_all_recons.pt")
486
+ torch.save(all_predcaptions,f"evals/{model_name}/{model_name}_all_predcaptions.pt")
487
+ torch.save(all_clipvoxels,f"evals/{model_name}/{model_name}_all_clipvoxels.pt")
488
+ print(f"saved {model_name} outputs!")
489
+
490
+ if not utils.is_interactive():
491
+ sys.exit(0)
492
+
MindEyeV2/src/wandb/debug-cli.ckadirt.log ADDED
File without changes
MindEyeV2/src/wandb/debug-internal.log ADDED
The diff for this file is too large to render. See raw diff
 
MindEyeV2/src/wandb/debug.log ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2024-12-10 21:57:28,176 INFO MainThread:842903 [wandb_setup.py:_flush():76] Current SDK version is 0.17.1
2
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_setup.py:_flush():76] Configure stats pid to 842903
3
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_setup.py:_flush():76] Loading settings from /admin/home-ckadirt/.config/wandb/settings
4
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_setup.py:_flush():76] Loading settings from /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/settings
5
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_setup.py:_flush():76] Loading settings from environment variables: {}
6
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_setup.py:_flush():76] Applying setup settings: {'_disable_service': False}
7
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_setup.py:_flush():76] Inferring run settings from compute environment: {'program_relpath': 'src/TrainB5k.py', 'program_abspath': '/weka/proj-fmri/ckadirt/MindEyeV2/src/TrainB5k.py', 'program': '/weka/proj-fmri/ckadirt/MindEyeV2/src/TrainB5k.py'}
8
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_setup.py:_flush():76] Applying login settings: {}
9
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_init.py:_log_setup():520] Logging user logs to /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20241210_215728-bold5k_nsdm1/logs/debug.log
10
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_init.py:_log_setup():521] Logging internal logs to /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20241210_215728-bold5k_nsdm1/logs/debug-internal.log
11
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_init.py:init():560] calling init triggers
12
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_init.py:init():567] wandb.init called with sweep_config: {}
13
+ config: {'model_name': 'bold5k_nsdm1', 'global_batch_size': '21', 'batch_size': 21, 'num_epochs': 150, 'num_sessions': 15, 'num_params': 2239051016, 'clip_scale': 1.0, 'prior_scale': 30.0, 'blur_scale': 0.5, 'use_image_aug': True, 'max_lr': 0.0003, 'mixup_pct': 0.33, 'num_samples_per_epoch': 4323, 'num_test': 480, 'ckpt_interval': 999, 'ckpt_saving': False, 'seed': 42, 'distributed': False, 'num_devices': 1, 'world_size': 1}
14
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_init.py:init():610] starting backend
15
+ 2024-12-10 21:57:28,177 INFO MainThread:842903 [wandb_init.py:init():614] setting up manager
16
+ 2024-12-10 21:57:28,179 INFO MainThread:842903 [backend.py:_multiprocessing_setup():105] multiprocessing start_methods=fork,spawn,forkserver, using: spawn
17
+ 2024-12-10 21:57:28,182 INFO MainThread:842903 [wandb_init.py:init():622] backend started and connected
18
+ 2024-12-10 21:57:28,187 INFO MainThread:842903 [wandb_init.py:init():711] updated telemetry
19
+ 2024-12-10 21:57:28,198 INFO MainThread:842903 [wandb_init.py:init():744] communicating run to backend with 90.0 second timeout
20
+ 2024-12-10 21:57:28,693 INFO MainThread:842903 [wandb_init.py:init():787] run resumed
21
+ 2024-12-10 21:57:28,707 INFO MainThread:842903 [wandb_run.py:_on_init():2402] communicating current version
22
+ 2024-12-10 21:57:28,770 INFO MainThread:842903 [wandb_run.py:_on_init():2411] got version response upgrade_message: "wandb version 0.19.0 is available! To upgrade, please run:\n $ pip install wandb --upgrade"
23
+
24
+ 2024-12-10 21:57:28,770 INFO MainThread:842903 [wandb_init.py:init():795] starting run threads in backend
25
+ 2024-12-10 21:57:29,319 INFO MainThread:842903 [wandb_run.py:_console_start():2380] atexit reg
26
+ 2024-12-10 21:57:29,319 INFO MainThread:842903 [wandb_run.py:_redirect():2235] redirect: wrap_raw
27
+ 2024-12-10 21:57:29,319 INFO MainThread:842903 [wandb_run.py:_redirect():2300] Wrapping output streams.
28
+ 2024-12-10 21:57:29,319 INFO MainThread:842903 [wandb_run.py:_redirect():2325] Redirects installed.
29
+ 2024-12-10 21:57:29,322 INFO MainThread:842903 [wandb_init.py:init():838] run started, returning control to user process
30
+ 2024-12-11 00:59:32,641 WARNING MsgRouterThr:842903 [router.py:message_loop():77] message_loop has been closed
MindEyeV2/src/wandb/run-20240618_035407-rr-test/files/config.yaml ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ wandb_version: 1
2
+
3
+ model_name:
4
+ desc: null
5
+ value: rr-test
6
+ global_batch_size:
7
+ desc: null
8
+ value: '21'
9
+ batch_size:
10
+ desc: null
11
+ value: 3
12
+ num_epochs:
13
+ desc: null
14
+ value: 150
15
+ num_sessions:
16
+ desc: null
17
+ value: 40
18
+ num_params:
19
+ desc: null
20
+ value: 573919937
21
+ clip_scale:
22
+ desc: null
23
+ value: 1.0
24
+ prior_scale:
25
+ desc: null
26
+ value: 30.0
27
+ blur_scale:
28
+ desc: null
29
+ value: 0.5
30
+ use_image_aug:
31
+ desc: null
32
+ value: false
33
+ max_lr:
34
+ desc: null
35
+ value: 0.0003
36
+ mixup_pct:
37
+ desc: null
38
+ value: 0.33
39
+ num_samples_per_epoch:
40
+ desc: null
41
+ value: 3750
42
+ num_test:
43
+ desc: null
44
+ value: 3000
45
+ ckpt_interval:
46
+ desc: null
47
+ value: 999
48
+ ckpt_saving:
49
+ desc: null
50
+ value: true
51
+ seed:
52
+ desc: null
53
+ value: 42
54
+ distributed:
55
+ desc: null
56
+ value: true
57
+ num_devices:
58
+ desc: null
59
+ value: 8
60
+ world_size:
61
+ desc: null
62
+ value: 1
63
+ train_url:
64
+ desc: null
65
+ value: /weka/proj-medarc/shared/mindeyev2_dataset/wds/subj08/train/{0..29}.tar
66
+ test_url:
67
+ desc: null
68
+ value: /weka/proj-medarc/shared/mindeyev2_dataset/wds/subj02/new_test/0.tar
69
+ _wandb:
70
+ desc: null
71
+ value:
72
+ python_version: 3.11.9
73
+ cli_version: 0.17.1
74
+ framework: huggingface
75
+ huggingface_version: 4.37.2
76
+ is_jupyter_run: false
77
+ is_kaggle_kernel: false
78
+ start_time: 1718682847
79
+ t:
80
+ 1:
81
+ - 1
82
+ - 9
83
+ - 11
84
+ - 41
85
+ - 49
86
+ - 55
87
+ - 63
88
+ - 71
89
+ - 79
90
+ - 83
91
+ - 103
92
+ 3:
93
+ - 13
94
+ - 14
95
+ - 16
96
+ - 23
97
+ 4: 3.11.9
98
+ 5: 0.17.1
99
+ 6: 4.37.2
100
+ 8:
101
+ - 5
102
+ 13: linux-x86_64
MindEyeV2/src/wandb/run-20240618_035407-rr-test/logs/debug-internal.log ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2024-06-18 03:54:07,351 INFO StreamThr :2245613 [internal.py:wandb_internal():85] W&B internal server running at pid: 2245613, started at: 2024-06-18 03:54:07.345742
2
+ 2024-06-18 03:54:07,352 DEBUG HandlerThread:2245613 [handler.py:handle_request():158] handle_request: status
3
+ 2024-06-18 03:54:07,375 INFO WriterThread:2245613 [datastore.py:open_for_write():87] open: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_035407-rr-test/run-rr-test.wandb
4
+ 2024-06-18 03:54:07,379 DEBUG SenderThread:2245613 [sender.py:send():379] send: header
5
+ 2024-06-18 03:54:07,462 DEBUG SenderThread:2245613 [sender.py:send():379] send: run
6
+ 2024-06-18 03:54:07,474 INFO SenderThread:2245613 [sender.py:_setup_resume():749] checking resume status for None/mindeye_semantic_cluster/rr-test
7
+ 2024-06-18 03:54:07,670 ERROR SenderThread:2245613 [internal_api.py:execute():344] 401 response executing GraphQL.
8
+ 2024-06-18 03:54:07,670 ERROR SenderThread:2245613 [internal_api.py:execute():345] {"errors":[{"message":"user is not logged in","path":["upsertBucket"],"extensions":{"code":"PERMISSION_ERROR"}}],"data":{"upsertBucket":null}}
9
+ 2024-06-18 03:54:07,670 ERROR SenderThread:2245613 [sender.py:send_run():1009] The API key you provided is either invalid or missing. If the `WANDB_API_KEY` environment variable is set, make sure it is correct. Otherwise, to resolve this issue, you may try running the 'wandb login --relogin' command. If you are using a local server, make sure that you're using the correct hostname. If you're not sure, you can try logging in again using the 'wandb login --relogin --host [hostname]' command.(Error 401: Unauthorized)
10
+ Traceback (most recent call last):
11
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/sdk/lib/retry.py", line 131, in __call__
12
+ result = self._call_fn(*args, **kwargs)
13
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/sdk/internal/internal_api.py", line 340, in execute
15
+ return self.client.execute(*args, **kwargs) # type: ignore
16
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/vendor/gql-0.2.0/wandb_gql/client.py", line 52, in execute
18
+ result = self._get_result(document, *args, **kwargs)
19
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/vendor/gql-0.2.0/wandb_gql/client.py", line 60, in _get_result
21
+ return self.transport.execute(document, *args, **kwargs)
22
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/sdk/lib/gql_request.py", line 59, in execute
24
+ request.raise_for_status()
25
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/requests/models.py", line 1024, in raise_for_status
26
+ raise HTTPError(http_error_msg, response=self)
27
+ requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.wandb.ai/graphql
28
+
29
+ During handling of the above exception, another exception occurred:
30
+
31
+ Traceback (most recent call last):
32
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/sdk/internal/sender.py", line 1007, in send_run
33
+ server_run = self._init_run(run, config_value_dict)
34
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/sdk/internal/sender.py", line 1079, in _init_run
36
+ server_run, inserted, server_messages = self._api.upsert_run(
37
+ ^^^^^^^^^^^^^^^^^^^^^
38
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/apis/normalize.py", line 73, in wrapper
39
+ raise err
40
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/apis/normalize.py", line 41, in wrapper
41
+ return func(*args, **kwargs)
42
+ ^^^^^^^^^^^^^^^^^^^^^
43
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/sdk/internal/internal_api.py", line 2188, in upsert_run
44
+ response = self.gql(
45
+ ^^^^^^^^^
46
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/sdk/internal/internal_api.py", line 312, in gql
47
+ ret = self._retry_gql(
48
+ ^^^^^^^^^^^^^^^^
49
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/sdk/lib/retry.py", line 147, in __call__
50
+ retry_timedelta_triggered = check_retry_fn(e)
51
+ ^^^^^^^^^^^^^^^^^
52
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/util.py", line 965, in check_retry_fn
53
+ return fallback_retry_fn(e)
54
+ ^^^^^^^^^^^^^^^^^^^^
55
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/util.py", line 896, in no_retry_auth
56
+ raise AuthenticationError(
57
+ wandb.errors.AuthenticationError: The API key you provided is either invalid or missing. If the `WANDB_API_KEY` environment variable is set, make sure it is correct. Otherwise, to resolve this issue, you may try running the 'wandb login --relogin' command. If you are using a local server, make sure that you're using the correct hostname. If you're not sure, you can try logging in again using the 'wandb login --relogin --host [hostname]' command.(Error 401: Unauthorized)
58
+ 2024-06-18 03:54:07,847 DEBUG HandlerThread:2245613 [handler.py:handle_request():158] handle_request: shutdown
59
+ 2024-06-18 03:54:07,847 INFO HandlerThread:2245613 [handler.py:finish():882] shutting down handler
60
+ 2024-06-18 03:54:08,462 INFO WriterThread:2245613 [datastore.py:close():296] close: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_035407-rr-test/run-rr-test.wandb
61
+ 2024-06-18 03:54:08,695 INFO SenderThread:2245613 [sender.py:finish():1608] shutting down sender
MindEyeV2/src/wandb/run-20240618_035407-rr-test/logs/debug.log ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2024-06-18 03:54:07,333 INFO MainThread:2245259 [wandb_setup.py:_flush():76] Current SDK version is 0.17.1
2
+ 2024-06-18 03:54:07,334 INFO MainThread:2245259 [wandb_setup.py:_flush():76] Configure stats pid to 2245259
3
+ 2024-06-18 03:54:07,334 INFO MainThread:2245259 [wandb_setup.py:_flush():76] Loading settings from /admin/home-ckadirt/.config/wandb/settings
4
+ 2024-06-18 03:54:07,334 INFO MainThread:2245259 [wandb_setup.py:_flush():76] Loading settings from /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/settings
5
+ 2024-06-18 03:54:07,334 INFO MainThread:2245259 [wandb_setup.py:_flush():76] Loading settings from environment variables: {}
6
+ 2024-06-18 03:54:07,334 INFO MainThread:2245259 [wandb_setup.py:_flush():76] Applying setup settings: {'_disable_service': False}
7
+ 2024-06-18 03:54:07,334 INFO MainThread:2245259 [wandb_setup.py:_flush():76] Inferring run settings from compute environment: {'program_relpath': 'src/TrainCluster.py', 'program_abspath': '/weka/proj-fmri/ckadirt/MindEyeV2/src/TrainCluster.py', 'program': '/weka/proj-fmri/ckadirt/MindEyeV2/src/TrainCluster.py'}
8
+ 2024-06-18 03:54:07,334 INFO MainThread:2245259 [wandb_setup.py:_flush():76] Applying login settings: {}
9
+ 2024-06-18 03:54:07,334 INFO MainThread:2245259 [wandb_init.py:_log_setup():520] Logging user logs to /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_035407-rr-test/logs/debug.log
10
+ 2024-06-18 03:54:07,335 INFO MainThread:2245259 [wandb_init.py:_log_setup():521] Logging internal logs to /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_035407-rr-test/logs/debug-internal.log
11
+ 2024-06-18 03:54:07,335 INFO MainThread:2245259 [wandb_init.py:init():560] calling init triggers
12
+ 2024-06-18 03:54:07,335 INFO MainThread:2245259 [wandb_init.py:init():567] wandb.init called with sweep_config: {}
13
+ config: {'model_name': 'rr-test', 'global_batch_size': '21', 'batch_size': 3, 'num_epochs': 150, 'num_sessions': 40, 'num_params': 573919937, 'clip_scale': 1.0, 'prior_scale': 30.0, 'blur_scale': 0.5, 'use_image_aug': False, 'max_lr': 0.0003, 'mixup_pct': 0.33, 'num_samples_per_epoch': 3750, 'num_test': 3000, 'ckpt_interval': 999, 'ckpt_saving': True, 'seed': 42, 'distributed': True, 'num_devices': 8, 'world_size': 1, 'train_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj08/train/{0..29}.tar', 'test_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj02/new_test/0.tar'}
14
+ 2024-06-18 03:54:07,335 INFO MainThread:2245259 [wandb_init.py:init():610] starting backend
15
+ 2024-06-18 03:54:07,335 INFO MainThread:2245259 [wandb_init.py:init():614] setting up manager
16
+ 2024-06-18 03:54:07,344 INFO MainThread:2245259 [backend.py:_multiprocessing_setup():105] multiprocessing start_methods=fork,spawn,forkserver, using: spawn
17
+ 2024-06-18 03:54:07,352 INFO MainThread:2245259 [wandb_init.py:init():622] backend started and connected
18
+ 2024-06-18 03:54:07,374 INFO MainThread:2245259 [wandb_init.py:init():711] updated telemetry
19
+ 2024-06-18 03:54:07,461 INFO MainThread:2245259 [wandb_init.py:init():744] communicating run to backend with 90.0 second timeout
20
+ 2024-06-18 03:54:07,695 ERROR MainThread:2245259 [wandb_init.py:init():770] encountered error: The API key you provided is either invalid or missing. If the `WANDB_API_KEY` environment variable is set, make sure it is correct. Otherwise, to resolve this issue, you may try running the 'wandb login --relogin' command. If you are using a local server, make sure that you're using the correct hostname. If you're not sure, you can try logging in again using the 'wandb login --relogin --host [hostname]' command.(Error 401: Unauthorized)
21
+ 2024-06-18 03:54:07,695 ERROR MainThread:2245259 [wandb_init.py:init():1181] error in wandb.init()
22
+ Traceback (most recent call last):
23
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/sdk/wandb_init.py", line 1171, in init
24
+ return wi.init()
25
+ ^^^^^^^^^
26
+ File "/admin/home-ckadirt/fmri/lib/python3.11/site-packages/wandb/sdk/wandb_init.py", line 776, in init
27
+ raise error
28
+ wandb.errors.AuthenticationError: The API key you provided is either invalid or missing. If the `WANDB_API_KEY` environment variable is set, make sure it is correct. Otherwise, to resolve this issue, you may try running the 'wandb login --relogin' command. If you are using a local server, make sure that you're using the correct hostname. If you're not sure, you can try logging in again using the 'wandb login --relogin --host [hostname]' command.(Error 401: Unauthorized)
29
+ 2024-06-18 03:54:08,847 WARNING MsgRouterThr:2245259 [router.py:message_loop():77] message_loop has been closed
MindEyeV2/src/wandb/run-20240618_035407-rr-test/run-rr-test.wandb ADDED
Binary file (1.02 kB). View file
 
MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/code/src/TrainCluster.py ADDED
@@ -0,0 +1,1069 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # # Import packages & functions
5
+
6
+ # In[1]:
7
+
8
+
9
+ import os
10
+ import sys
11
+ import json
12
+ import argparse
13
+ import numpy as np
14
+ import math
15
+ from einops import rearrange
16
+ import time
17
+ import random
18
+ import string
19
+ import h5py
20
+ from tqdm import tqdm
21
+ import webdataset as wds
22
+
23
+ import matplotlib.pyplot as plt
24
+ import torch
25
+ import torch.nn as nn
26
+ from torchvision import transforms
27
+ from accelerate import Accelerator
28
+
29
+ # SDXL unCLIP requires code from https://github.com/Stability-AI/generative-models/tree/main
30
+ sys.path.append('generative_models/')
31
+ import sgm
32
+ from generative_models.sgm.modules.encoders.modules import FrozenOpenCLIPImageEmbedder # bigG embedder
33
+
34
+ # tf32 data type is faster than standard float32
35
+ torch.backends.cuda.matmul.allow_tf32 = True
36
+
37
+ # custom functions #
38
+ import utils
39
+
40
+
41
+ # In[2]:
42
+
43
+
44
+ ### Multi-GPU config ###
45
+ local_rank = os.getenv('RANK')
46
+ if local_rank is None:
47
+ local_rank = 0
48
+ else:
49
+ local_rank = int(local_rank)
50
+ print("LOCAL RANK ", local_rank)
51
+
52
+ data_type = torch.float16 # change depending on your mixed_precision
53
+ num_devices = torch.cuda.device_count()
54
+ if num_devices==0: num_devices = 1
55
+
56
+ # First use "accelerate config" in terminal and setup using deepspeed stage 2 with CPU offloading!
57
+ accelerator = Accelerator(split_batches=False, mixed_precision="fp16")
58
+ if utils.is_interactive(): # set batch size here if using interactive notebook instead of submitting job
59
+ global_batch_size = batch_size = 8
60
+ else:
61
+ global_batch_size = os.environ["GLOBAL_BATCH_SIZE"]
62
+ batch_size = int(os.environ["GLOBAL_BATCH_SIZE"]) // num_devices
63
+
64
+
65
+ # In[3]:
66
+
67
+
68
+ print("PID of this process =",os.getpid())
69
+ device = accelerator.device
70
+ print("device:",device)
71
+ world_size = accelerator.state.num_processes
72
+ distributed = not accelerator.state.distributed_type == 'NO'
73
+ num_devices = torch.cuda.device_count()
74
+ if num_devices==0 or not distributed: num_devices = 1
75
+ num_workers = num_devices
76
+ print(accelerator.state)
77
+
78
+ print("distributed =",distributed, "num_devices =", num_devices, "local rank =", local_rank, "world size =", world_size, "data_type =", data_type)
79
+ print = accelerator.print # only print if local_rank=0
80
+
81
+
82
+ # # Configurations
83
+
84
+ # In[4]:
85
+
86
+
87
+ # if running this interactively, can specify jupyter_args here for argparser to use
88
+ if utils.is_interactive():
89
+ model_name = "testing"
90
+ print("model_name:", model_name)
91
+
92
+ # global_batch_size and batch_size should already be defined in the 2nd cell block
93
+ jupyter_args = f"--data_path=/weka/proj-medarc/shared/mindeyev2_dataset \
94
+ --cache_dir=/weka/proj-medarc/shared/cache \
95
+ --model_name={model_name} \
96
+ --no-multi_subject --subj=1 --batch_size={batch_size} --num_sessions=40 \
97
+ --hidden_dim=1024 --clip_scale=1. \
98
+ --no-blurry_recon --blur_scale=.5 \
99
+ --use_prior --prior_scale=30 \
100
+ --n_blocks=4 --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --no-use_image_aug \
101
+ --ckpt_interval=999 --no-ckpt_saving --no-wandb_log"
102
+ # --multisubject_ckpt=../train_logs/multisubject_subj01_1024_24bs_nolow
103
+
104
+ print(jupyter_args)
105
+ jupyter_args = jupyter_args.split()
106
+
107
+ from IPython.display import clear_output # function to clear print outputs in cell
108
+ get_ipython().run_line_magic('load_ext', 'autoreload')
109
+ # this allows you to change functions in models.py or utils.py and have this notebook automatically update with your revisions
110
+ get_ipython().run_line_magic('autoreload', '2')
111
+
112
+
113
+ # In[5]:
114
+
115
+
116
+ parser = argparse.ArgumentParser(description="Model Training Configuration")
117
+ parser.add_argument(
118
+ "--model_name", type=str, default="testing",
119
+ help="name of model, used for ckpt saving and wandb logging (if enabled)",
120
+ )
121
+ parser.add_argument(
122
+ "--data_path", type=str, default=os.getcwd(),
123
+ help="Path to where NSD data is stored / where to download it to",
124
+ )
125
+ parser.add_argument(
126
+ "--cache_dir", type=str, default=os.getcwd(),
127
+ help="Path to where misc. files downloaded from huggingface are stored. Defaults to current src directory.",
128
+ )
129
+ parser.add_argument(
130
+ "--subj",type=int, default=1, choices=[1,2,3,4,5,6,7,8],
131
+ help="Validate on which subject?",
132
+ )
133
+ parser.add_argument(
134
+ "--multisubject_ckpt", type=str, default=None,
135
+ help="Path to pre-trained multisubject model to finetune a single subject from. multisubject must be False.",
136
+ )
137
+ parser.add_argument(
138
+ "--num_sessions", type=int, default=1,
139
+ help="Number of training sessions to include",
140
+ )
141
+ parser.add_argument(
142
+ "--use_prior",action=argparse.BooleanOptionalAction,default=True,
143
+ help="whether to train diffusion prior (True) or just rely on retrieval part of the pipeline (False)",
144
+ )
145
+ parser.add_argument(
146
+ "--batch_size", type=int, default=16,
147
+ help="Batch size can be increased by 10x if only training retreival submodule and not diffusion prior",
148
+ )
149
+ parser.add_argument(
150
+ "--wandb_log",action=argparse.BooleanOptionalAction,default=False,
151
+ help="whether to log to wandb",
152
+ )
153
+ parser.add_argument(
154
+ "--wandb_project",type=str,default="stability",
155
+ help="wandb project name",
156
+ )
157
+ parser.add_argument(
158
+ "--mixup_pct",type=float,default=.33,
159
+ help="proportion of way through training when to switch from BiMixCo to SoftCLIP",
160
+ )
161
+ parser.add_argument(
162
+ "--blurry_recon",action=argparse.BooleanOptionalAction,default=True,
163
+ help="whether to output blurry reconstructions",
164
+ )
165
+ parser.add_argument(
166
+ "--blur_scale",type=float,default=.5,
167
+ help="multiply loss from blurry recons by this number",
168
+ )
169
+ parser.add_argument(
170
+ "--clip_scale",type=float,default=1.,
171
+ help="multiply contrastive loss by this number",
172
+ )
173
+ parser.add_argument(
174
+ "--prior_scale",type=float,default=30,
175
+ help="multiply diffusion prior loss by this",
176
+ )
177
+ parser.add_argument(
178
+ "--use_image_aug",action=argparse.BooleanOptionalAction,default=False,
179
+ help="whether to use image augmentation",
180
+ )
181
+ parser.add_argument(
182
+ "--num_epochs",type=int,default=150,
183
+ help="number of epochs of training",
184
+ )
185
+ parser.add_argument(
186
+ "--multi_subject",action=argparse.BooleanOptionalAction,default=False,
187
+ )
188
+ parser.add_argument(
189
+ "--new_test",action=argparse.BooleanOptionalAction,default=True,
190
+ )
191
+ parser.add_argument(
192
+ "--n_blocks",type=int,default=4,
193
+ )
194
+ parser.add_argument(
195
+ "--hidden_dim",type=int,default=1024,
196
+ )
197
+ parser.add_argument(
198
+ "--lr_scheduler_type",type=str,default='cycle',choices=['cycle','linear'],
199
+ )
200
+ parser.add_argument(
201
+ "--ckpt_saving",action=argparse.BooleanOptionalAction,default=True,
202
+ )
203
+ parser.add_argument(
204
+ "--ckpt_interval",type=int,default=5,
205
+ help="save backup ckpt and reconstruct every x epochs",
206
+ )
207
+ parser.add_argument(
208
+ "--seed",type=int,default=42,
209
+ )
210
+ parser.add_argument(
211
+ "--max_lr",type=float,default=3e-4,
212
+ )
213
+
214
+ if utils.is_interactive():
215
+ args = parser.parse_args(jupyter_args)
216
+ else:
217
+ args = parser.parse_args()
218
+
219
+ # create global variables without the args prefix
220
+ for attribute_name in vars(args).keys():
221
+ globals()[attribute_name] = getattr(args, attribute_name)
222
+
223
+ # seed all random functions
224
+ utils.seed_everything(seed)
225
+
226
+ outdir = os.path.abspath(f'../train_logs/{model_name}')
227
+ if not os.path.exists(outdir) and ckpt_saving:
228
+ os.makedirs(outdir,exist_ok=True)
229
+
230
+ if use_image_aug or blurry_recon:
231
+ import kornia
232
+ from kornia.augmentation.container import AugmentationSequential
233
+ if use_image_aug:
234
+ img_augment = AugmentationSequential(
235
+ kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1, p=0.3),
236
+ same_on_batch=False,
237
+ data_keys=["input"],
238
+ )
239
+
240
+ if multi_subject:
241
+ subj_list = np.arange(1,9)
242
+ subj_list = subj_list[subj_list != subj]
243
+ else:
244
+ subj_list = [subj]
245
+
246
+ print("subj_list", subj_list, "num_sessions", num_sessions)
247
+
248
+
249
+ # # Prep data, models, and dataloaders
250
+
251
+ # ### Creating wds dataloader, preload betas and all 73k possible images
252
+
253
+ # In[6]:
254
+
255
+
256
+ def my_split_by_node(urls): return urls
257
+ num_voxels_list = []
258
+
259
+ if multi_subject:
260
+ nsessions_allsubj=np.array([40, 40, 32, 30, 40, 32, 40, 30])
261
+ num_samples_per_epoch = (750*40) // num_devices
262
+ else:
263
+ num_samples_per_epoch = (750*num_sessions) // num_devices
264
+
265
+ print("dividing batch size by subj_list, which will then be concatenated across subj during training...")
266
+ batch_size = batch_size // len(subj_list)
267
+
268
+ num_iterations_per_epoch = num_samples_per_epoch // (batch_size*len(subj_list))
269
+
270
+ print("batch_size =", batch_size, "num_iterations_per_epoch =",num_iterations_per_epoch, "num_samples_per_epoch =",num_samples_per_epoch)
271
+
272
+
273
+ # In[7]:
274
+
275
+
276
+ train_data = {}
277
+ train_dl = {}
278
+ num_voxels = {}
279
+ voxels = {}
280
+ for s in subj_list:
281
+ print(f"Training with {num_sessions} sessions")
282
+ if multi_subject:
283
+ train_url = f"{data_path}/wds/subj0{s}/train/" + "{0.." + f"{nsessions_allsubj[s-1]-1}" + "}.tar"
284
+ else:
285
+ train_url = f"{data_path}/wds/subj0{s}/train/" + "{0.." + f"{num_sessions-1}" + "}.tar"
286
+ print(train_url)
287
+
288
+ train_data[f'subj0{s}'] = wds.WebDataset(train_url,resampled=True,nodesplitter=my_split_by_node)\
289
+ .shuffle(750, initial=1500, rng=random.Random(42))\
290
+ .decode("torch")\
291
+ .rename(behav="behav.npy", past_behav="past_behav.npy", future_behav="future_behav.npy", olds_behav="olds_behav.npy")\
292
+ .to_tuple(*["behav", "past_behav", "future_behav", "olds_behav"])
293
+ train_dl[f'subj0{s}'] = torch.utils.data.DataLoader(train_data[f'subj0{s}'], batch_size=batch_size, shuffle=False, drop_last=False, pin_memory=True)
294
+
295
+ f = h5py.File(f'{data_path}/betas_all_subj0{s}_fp32_renorm.hdf5', 'r')
296
+ betas = f['betas'][:]
297
+ betas = torch.Tensor(betas).to("cpu").to(data_type)
298
+ num_voxels_list.append(betas[0].shape[-1])
299
+ num_voxels[f'subj0{s}'] = betas[0].shape[-1]
300
+ voxels[f'subj0{s}'] = betas
301
+ print(f"num_voxels for subj0{s}: {num_voxels[f'subj0{s}']}")
302
+
303
+ print("Loaded all subj train dls and betas!\n")
304
+
305
+ # Validate only on one subject
306
+ if multi_subject:
307
+ subj = subj_list[0] # cant validate on the actual held out person so picking first in subj_list
308
+ if not new_test: # using old test set from before full dataset released (used in original MindEye paper)
309
+ if subj==3:
310
+ num_test=2113
311
+ elif subj==4:
312
+ num_test=1985
313
+ elif subj==6:
314
+ num_test=2113
315
+ elif subj==8:
316
+ num_test=1985
317
+ else:
318
+ num_test=2770
319
+ test_url = f"{data_path}/wds/subj0{subj}/test/" + "0.tar"
320
+ elif new_test: # using larger test set from after full dataset released
321
+ if subj==3:
322
+ num_test=2371
323
+ elif subj==4:
324
+ num_test=2188
325
+ elif subj==6:
326
+ num_test=2371
327
+ elif subj==8:
328
+ num_test=2188
329
+ else:
330
+ num_test=3000
331
+ test_url = f"{data_path}/wds/subj0{subj}/new_test/" + "0.tar"
332
+ print(test_url)
333
+ test_data = wds.WebDataset(test_url,resampled=False,nodesplitter=my_split_by_node)\
334
+ .shuffle(750, initial=1500, rng=random.Random(42))\
335
+ .decode("torch")\
336
+ .rename(behav="behav.npy", past_behav="past_behav.npy", future_behav="future_behav.npy", olds_behav="olds_behav.npy")\
337
+ .to_tuple(*["behav", "past_behav", "future_behav", "olds_behav"])
338
+ test_dl = torch.utils.data.DataLoader(test_data, batch_size=num_test, shuffle=False, drop_last=True, pin_memory=True)
339
+ print(f"Loaded test dl for subj{subj}!\n")
340
+
341
+
342
+ # In[8]:
343
+
344
+
345
+ # Load 73k NSD images
346
+ f = h5py.File(f'{data_path}/coco_images_224_float16.hdf5', 'r')
347
+ images = f['images']
348
+ print("Loaded all 73k possible NSD images to cpu!", images.shape)
349
+
350
+
351
+ # ## Load models
352
+
353
+ # ### CLIP image embeddings model
354
+
355
+ # In[9]:
356
+
357
+
358
+ clip_img_embedder = FrozenOpenCLIPImageEmbedder(
359
+ arch="ViT-bigG-14",
360
+ version="laion2b_s39b_b160k",
361
+ output_tokens=True,
362
+ only_tokens=True,
363
+ )
364
+ clip_img_embedder.to(device)
365
+
366
+ clip_seq_dim = 256
367
+ clip_emb_dim = 1664
368
+
369
+
370
+ # ### SD VAE
371
+
372
+ # In[10]:
373
+
374
+
375
+ if blurry_recon:
376
+ from diffusers import AutoencoderKL
377
+ autoenc = AutoencoderKL(
378
+ down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D'],
379
+ up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D', 'UpDecoderBlock2D'],
380
+ block_out_channels=[128, 256, 512, 512],
381
+ layers_per_block=2,
382
+ sample_size=256,
383
+ )
384
+ ckpt = torch.load(f'{cache_dir}/sd_image_var_autoenc.pth')
385
+ autoenc.load_state_dict(ckpt)
386
+
387
+ autoenc.eval()
388
+ autoenc.requires_grad_(False)
389
+ autoenc.to(device)
390
+ utils.count_params(autoenc)
391
+
392
+ from autoencoder.convnext import ConvnextXL
393
+ cnx = ConvnextXL(f'{cache_dir}/convnext_xlarge_alpha0.75_fullckpt.pth')
394
+ cnx.requires_grad_(False)
395
+ cnx.eval()
396
+ cnx.to(device)
397
+
398
+ mean = torch.tensor([0.485, 0.456, 0.406]).to(device).reshape(1,3,1,1)
399
+ std = torch.tensor([0.228, 0.224, 0.225]).to(device).reshape(1,3,1,1)
400
+
401
+ blur_augs = AugmentationSequential(
402
+ kornia.augmentation.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1, p=0.8),
403
+ kornia.augmentation.RandomGrayscale(p=0.1),
404
+ kornia.augmentation.RandomSolarize(p=0.1),
405
+ kornia.augmentation.RandomResizedCrop((224,224), scale=(.9,.9), ratio=(1,1), p=1.0),
406
+ data_keys=["input"],
407
+ )
408
+
409
+
410
+ # ### MindEye modules
411
+
412
+ # In[11]:
413
+
414
+
415
+ class MindEyeModule(nn.Module):
416
+ def __init__(self):
417
+ super(MindEyeModule, self).__init__()
418
+ def forward(self, x):
419
+ return x
420
+
421
+ model = MindEyeModule()
422
+ model
423
+
424
+
425
+ # In[12]:
426
+
427
+
428
+ class RidgeRegression(torch.nn.Module):
429
+ # make sure to add weight_decay when initializing optimizer to enable regularization
430
+ def __init__(self, input_sizes, out_features):
431
+ super(RidgeRegression, self).__init__()
432
+ self.out_features = out_features
433
+ self.linears = torch.nn.ModuleList([
434
+ torch.nn.Linear(input_size, out_features) for input_size in input_sizes
435
+ ])
436
+ def forward(self, x, subj_idx):
437
+ out = self.linears[subj_idx](x[:,0]).unsqueeze(1)
438
+ return out
439
+
440
+ class IndividRidgeRegression(torch.nn.Module):
441
+ def __init__(self, input_size, out_features):
442
+ super(IndividRidgeRegression, self).__init__()
443
+ self.out_features = out_features
444
+ self.linear = torch.nn.Linear(input_size, out_features)
445
+ def forward(self, x):
446
+ out = self.linear(x)
447
+ return out
448
+
449
+ model.ridge = RidgeRegression(num_voxels_list, out_features=hidden_dim)
450
+ utils.count_params(model.ridge)
451
+ utils.count_params(model)
452
+
453
+ # test on subject 1 with fake data
454
+ b = torch.randn((2,1,num_voxels_list[0]))
455
+ print(b.shape, model.ridge(b,0).shape)
456
+
457
+
458
+ # In[13]:
459
+
460
+
461
+ from models import BrainNetwork
462
+ model.backbone = BrainNetwork(h=hidden_dim, in_dim=hidden_dim, seq_len=1, n_blocks=n_blocks,
463
+ clip_size=clip_emb_dim, out_dim=clip_emb_dim*clip_seq_dim,
464
+ blurry_recon=blurry_recon, clip_scale=clip_scale)
465
+ utils.count_params(model.backbone)
466
+ utils.count_params(model)
467
+
468
+ # test that the model works on some fake data
469
+ b = torch.randn((2,1,hidden_dim))
470
+ print("b.shape",b.shape)
471
+
472
+ backbone_, clip_, blur_ = model.backbone(b)
473
+ print(backbone_.shape, clip_.shape, blur_[0].shape, blur_[1].shape)
474
+
475
+
476
+ # ### Load semantic clusters
477
+
478
+ # In[14]:
479
+
480
+
481
+ path_semantic_names = "/weka/proj-medarc/shared/mindeyev2_dataset/semantic_cluster_names.npy"
482
+ path_semantic_cluster = "/weka/proj-medarc/shared/mindeyev2_dataset/COCO_73k_semantic_cluster.npy"
483
+ semantic_cluster_names = np.load(path_semantic_names)
484
+ semantic_cluster = np.load(path_semantic_cluster)
485
+ possible_semantic_clusters = np.unique(semantic_cluster)
486
+
487
+ # one-hot encode semantic clusters
488
+ # move possible_semantic_clusters to numbers and create a dictionary
489
+ semantic_cluster_dict = {cluster: i for i, cluster in enumerate(possible_semantic_clusters)}
490
+ semantic_cluster_onehot = torch.zeros((len(semantic_cluster), len(possible_semantic_clusters)))
491
+ for i, cluster in enumerate(semantic_cluster):
492
+ semantic_cluster_onehot[i, semantic_cluster_dict[cluster]] = 1
493
+
494
+
495
+ print("semantic_cluster_onehot.shape", semantic_cluster_onehot.shape)
496
+
497
+ num_seman_clusters = len(np.unique(semantic_cluster))
498
+ print("num_seman_clusters", num_seman_clusters)
499
+
500
+
501
+ # ### Adding the ridge regression to the class
502
+
503
+ # In[15]:
504
+
505
+
506
+ # if use_prior:
507
+ # from models import *
508
+
509
+ # # setup diffusion prior network
510
+ # out_dim = clip_emb_dim
511
+ # depth = 6
512
+ # dim_head = 52
513
+ # heads = clip_emb_dim//52 # heads * dim_head = clip_emb_dim
514
+ # timesteps = 100
515
+
516
+ # prior_network = PriorNetwork(
517
+ # dim=out_dim,
518
+ # depth=depth,
519
+ # dim_head=dim_head,
520
+ # heads=heads,
521
+ # causal=False,
522
+ # num_tokens = clip_seq_dim,
523
+ # learned_query_mode="pos_emb"
524
+ # )
525
+
526
+ # model.diffusion_prior = BrainDiffusionPrior(
527
+ # net=prior_network,
528
+ # image_embed_dim=out_dim,
529
+ # condition_on_text_encodings=False,
530
+ # timesteps=timesteps,
531
+ # cond_drop_prob=0.2,
532
+ # image_embed_scale=None,
533
+ # )
534
+
535
+ # utils.count_params(model.diffusion_prior)
536
+ # utils.count_params(model)
537
+
538
+ model.RRClassifier = IndividRidgeRegression(clip_emb_dim*clip_seq_dim, out_features=num_seman_clusters)
539
+ utils.count_params(model.RRClassifier)
540
+ utils.count_params(model)
541
+
542
+
543
+ # ### Setup optimizer / lr / ckpt saving
544
+
545
+ # In[16]:
546
+
547
+
548
+ no_decay = ['bias', 'LayerNorm.bias', 'LayerNorm.weight']
549
+
550
+ opt_grouped_parameters = [
551
+ {'params': [p for n, p in model.ridge.named_parameters()], 'weight_decay': 1e-2},
552
+ {'params': [p for n, p in model.backbone.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},
553
+ {'params': [p for n, p in model.backbone.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0},
554
+ ]
555
+ # if use_prior:
556
+ # opt_grouped_parameters.extend([
557
+ # {'params': [p for n, p in model.diffusion_prior.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 1e-2},
558
+ # {'params': [p for n, p in model.diffusion_prior.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0}
559
+ # ])
560
+ opt_grouped_parameters.extend([
561
+ {'params': [p for n, p in model.RRClassifier.named_parameters()], 'weight_decay': 1e-2},
562
+ ])
563
+
564
+ optimizer = torch.optim.AdamW(opt_grouped_parameters, lr=max_lr)
565
+
566
+ if lr_scheduler_type == 'linear':
567
+ lr_scheduler = torch.optim.lr_scheduler.LinearLR(
568
+ optimizer,
569
+ total_iters=int(np.floor(num_epochs*num_iterations_per_epoch)),
570
+ last_epoch=-1
571
+ )
572
+ elif lr_scheduler_type == 'cycle':
573
+ total_steps=int(np.floor(num_epochs*num_iterations_per_epoch))
574
+ print("total_steps", total_steps)
575
+ lr_scheduler = torch.optim.lr_scheduler.OneCycleLR(
576
+ optimizer,
577
+ max_lr=max_lr,
578
+ total_steps=total_steps,
579
+ final_div_factor=1000,
580
+ last_epoch=-1, pct_start=2/num_epochs
581
+ )
582
+
583
+ def save_ckpt(tag):
584
+ ckpt_path = outdir+f'/{tag}.pth'
585
+ if accelerator.is_main_process:
586
+ unwrapped_model = accelerator.unwrap_model(model)
587
+ torch.save({
588
+ 'epoch': epoch,
589
+ 'model_state_dict': unwrapped_model.state_dict(),
590
+ 'optimizer_state_dict': optimizer.state_dict(),
591
+ 'lr_scheduler': lr_scheduler.state_dict(),
592
+ 'train_losses': losses,
593
+ 'test_losses': test_losses,
594
+ 'lrs': lrs,
595
+ }, ckpt_path)
596
+ print(f"\n---saved {outdir}/{tag} ckpt!---\n")
597
+
598
+ def load_ckpt(tag,load_lr=True,load_optimizer=True,load_epoch=True,strict=True,outdir=outdir,multisubj_loading=False):
599
+ print(f"\n---loading {outdir}/{tag}.pth ckpt---\n")
600
+ checkpoint = torch.load(outdir+'/last.pth', map_location='cpu')
601
+ state_dict = checkpoint['model_state_dict']
602
+ if multisubj_loading: # remove incompatible ridge layer that will otherwise error
603
+ state_dict.pop('ridge.linears.0.weight',None)
604
+ model.load_state_dict(state_dict, strict=strict)
605
+ if load_epoch:
606
+ globals()["epoch"] = checkpoint['epoch']
607
+ print("Epoch",epoch)
608
+ if load_optimizer:
609
+ optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
610
+ if load_lr:
611
+ lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])
612
+ del checkpoint
613
+
614
+ print("\nDone with model preparations!")
615
+ num_params = utils.count_params(model)
616
+
617
+
618
+ # # Weights and Biases
619
+
620
+ # In[17]:
621
+
622
+
623
+ if local_rank==0 and wandb_log: # only use main process for wandb logging
624
+ import wandb
625
+ wandb_project = 'mindeye_semantic_cluster'
626
+ print(f"wandb {wandb_project} run {model_name}")
627
+ # need to configure wandb beforehand in terminal with "wandb init"!
628
+ wandb_config = {
629
+ "model_name": model_name,
630
+ "global_batch_size": global_batch_size,
631
+ "batch_size": batch_size,
632
+ "num_epochs": num_epochs,
633
+ "num_sessions": num_sessions,
634
+ "num_params": num_params,
635
+ "clip_scale": clip_scale,
636
+ "prior_scale": prior_scale,
637
+ "blur_scale": blur_scale,
638
+ "use_image_aug": use_image_aug,
639
+ "max_lr": max_lr,
640
+ "mixup_pct": mixup_pct,
641
+ "num_samples_per_epoch": num_samples_per_epoch,
642
+ "num_test": num_test,
643
+ "ckpt_interval": ckpt_interval,
644
+ "ckpt_saving": ckpt_saving,
645
+ "seed": seed,
646
+ "distributed": distributed,
647
+ "num_devices": num_devices,
648
+ "world_size": world_size,
649
+ "train_url": train_url,
650
+ "test_url": test_url,
651
+ }
652
+ print("wandb_config:\n",wandb_config)
653
+ print("wandb_id:",model_name)
654
+ wandb.init(
655
+ id=model_name,
656
+ project=wandb_project,
657
+ name=model_name,
658
+ config=wandb_config,
659
+ resume="allow",
660
+ )
661
+ else:
662
+ wandb_log = False
663
+
664
+
665
+ # # Main
666
+
667
+ # In[18]:
668
+
669
+
670
+ epoch = 0
671
+ losses, test_losses, lrs = [], [], []
672
+ best_test_loss = 1e9
673
+ torch.cuda.empty_cache()
674
+
675
+
676
+ # In[19]:
677
+
678
+
679
+ # load multisubject stage1 ckpt if set
680
+ if multisubject_ckpt is not None:
681
+ load_ckpt("last",outdir=multisubject_ckpt,load_lr=False,load_optimizer=False,load_epoch=False,strict=False,multisubj_loading=True)
682
+
683
+
684
+ # In[20]:
685
+
686
+
687
+ train_dls = [train_dl[f'subj0{s}'] for s in subj_list]
688
+
689
+ model, optimizer, *train_dls, lr_scheduler, semantic_cluster_onehot = accelerator.prepare(model, optimizer, *train_dls, lr_scheduler, semantic_cluster_onehot)
690
+ # leaving out test_dl since we will only have local_rank 0 device do evals
691
+
692
+
693
+ # In[21]:
694
+
695
+
696
+ print(num_iterations_per_epoch)
697
+
698
+
699
+ # In[26]:
700
+
701
+
702
+ print(f"{model_name} starting with epoch {epoch} / {num_epochs}")
703
+ progress_bar = tqdm(range(epoch,num_epochs), ncols=1200, disable=(local_rank!=0))
704
+ test_image, test_voxel = None, None
705
+ mse = nn.MSELoss()
706
+ l1 = nn.L1Loss()
707
+ soft_loss_temps = utils.cosine_anneal(0.004, 0.0075, num_epochs - int(mixup_pct * num_epochs))
708
+
709
+ for epoch in progress_bar:
710
+ model.train()
711
+
712
+ fwd_percent_correct = 0.
713
+ bwd_percent_correct = 0.
714
+ test_fwd_percent_correct = 0.
715
+ test_bwd_percent_correct = 0.
716
+
717
+ recon_cossim = 0.
718
+ test_recon_cossim = 0.
719
+ recon_mse = 0.
720
+ test_recon_mse = 0.
721
+
722
+ loss_clip_total = 0.
723
+ loss_blurry_total = 0.
724
+ loss_blurry_cont_total = 0.
725
+ test_loss_clip_total = 0.
726
+
727
+ loss_prior_total = 0.
728
+ test_loss_prior_total = 0.
729
+
730
+ loss_RR_total = 0.
731
+ test_loss_RR_total = 0.
732
+
733
+ blurry_pixcorr = 0.
734
+ test_blurry_pixcorr = 0. # needs >.456 to beat low-level subj01 results in mindeye v1
735
+
736
+ # pre-load all batches for this epoch (it's MUCH faster to pre-load in bulk than to separate loading per batch)
737
+ voxel_iters = {} # empty dict because diff subjects have differing # of voxels
738
+ image_iters = torch.zeros(num_iterations_per_epoch, batch_size*len(subj_list), 3, 224, 224).float()
739
+ annot_iters = {}
740
+ perm_iters, betas_iters, select_iters = {}, {}, {}
741
+ images_indexes = {}
742
+ for s, train_dl in enumerate(train_dls):
743
+ with torch.cuda.amp.autocast(dtype=data_type):
744
+ iter = -1
745
+ for behav0, past_behav0, future_behav0, old_behav0 in train_dl:
746
+ # Load images to cpu from hdf5 (requires sorted indexing)
747
+ image_idx = behav0[:,0,0].cpu().long().numpy()
748
+
749
+ image0, image_sorted_idx = np.unique(image_idx, return_index=True)
750
+ if len(image0) != len(image_idx): # hdf5 cant handle duplicate indexing
751
+ continue
752
+ iter += 1
753
+ image0 = torch.tensor(images[image0], dtype=data_type)
754
+ image_iters[iter,s*batch_size:s*batch_size+batch_size] = image0
755
+ images_indexes[f"subj0{s}_iter{iter}"] = image_sorted_idx
756
+
757
+ # Load voxels for current batch, matching above indexing
758
+ voxel_idx = behav0[:,0,5].cpu().long().numpy()
759
+ voxel_sorted_idx = voxel_idx[image_sorted_idx]
760
+ voxel0 = voxels[f'subj0{subj_list[s]}'][voxel_sorted_idx]
761
+ voxel0 = torch.Tensor(voxel0).unsqueeze(1)
762
+
763
+ if epoch < int(mixup_pct * num_epochs):
764
+ voxel0, perm, betas, select = utils.mixco(voxel0)
765
+ perm_iters[f"subj0{subj_list[s]}_iter{iter}"] = perm
766
+ betas_iters[f"subj0{subj_list[s]}_iter{iter}"] = betas
767
+ select_iters[f"subj0{subj_list[s]}_iter{iter}"] = select
768
+
769
+ voxel_iters[f"subj0{subj_list[s]}_iter{iter}"] = voxel0
770
+
771
+ if iter >= num_iterations_per_epoch-1:
772
+ break
773
+
774
+ # you now have voxel_iters and image_iters with num_iterations_per_epoch batches each
775
+ for train_i in range(num_iterations_per_epoch):
776
+ with torch.cuda.amp.autocast(dtype=data_type):
777
+ optimizer.zero_grad()
778
+ loss=0.
779
+
780
+ voxel_list = [voxel_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
781
+ image = image_iters[train_i].detach()
782
+ image = image.to(device)
783
+
784
+ if use_image_aug:
785
+ image = img_augment(image)
786
+
787
+ clip_target = clip_img_embedder(image)
788
+ assert not torch.any(torch.isnan(clip_target))
789
+
790
+ if epoch < int(mixup_pct * num_epochs):
791
+ perm_list = [perm_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
792
+ perm = torch.cat(perm_list, dim=0)
793
+ betas_list = [betas_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
794
+ betas = torch.cat(betas_list, dim=0)
795
+ select_list = [select_iters[f"subj0{s}_iter{train_i}"].detach().to(device) for s in subj_list]
796
+ select = torch.cat(select_list, dim=0)
797
+
798
+ voxel_ridge_list = [model.ridge(voxel_list[si],si) for si,s in enumerate(subj_list)]
799
+ voxel_ridge = torch.cat(voxel_ridge_list, dim=0)
800
+
801
+ backbone, clip_voxels, blurry_image_enc_ = model.backbone(voxel_ridge)
802
+
803
+ if clip_scale>0:
804
+ clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)
805
+ clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)
806
+
807
+ # if use_prior:
808
+ # loss_prior, prior_out = model.diffusion_prior(text_embed=backbone, image_embed=clip_target)
809
+ # loss_prior_total += loss_prior.item()
810
+ # loss_prior *= prior_scale
811
+ # loss += loss_prior
812
+
813
+ # recon_cossim += nn.functional.cosine_similarity(prior_out, clip_target).mean().item()
814
+ # recon_mse += mse(prior_out, clip_target).item()
815
+
816
+ logits = model.RRClassifier(backbone.flatten(1))
817
+ loss_RR = nn.functional.cross_entropy(logits, torch.argmax(semantic_cluster_onehot[images_indexes[f"subj0{s}_iter{train_i}"]], dim=1).to(logits.device))
818
+ #print("backbone.shape",backbone.shape, "clip_voxels.shape",clip_voxels.shape, "blurry_image_enc_[0].shape",blurry_image_enc_[0].shape, "blurry_image_enc_[1].shape",blurry_image_enc_[1].shape)
819
+ #something
820
+
821
+ loss_RR_total += loss_RR.item()
822
+ loss += loss_RR
823
+
824
+ if clip_scale>0:
825
+ if epoch < int(mixup_pct * num_epochs):
826
+ loss_clip = utils.mixco_nce(
827
+ clip_voxels_norm,
828
+ clip_target_norm,
829
+ temp=.006,
830
+ perm=perm, betas=betas, select=select)
831
+ else:
832
+ epoch_temp = soft_loss_temps[epoch-int(mixup_pct*num_epochs)]
833
+ loss_clip = utils.soft_clip_loss(
834
+ clip_voxels_norm,
835
+ clip_target_norm,
836
+ temp=epoch_temp)
837
+
838
+ loss_clip_total += loss_clip.item()
839
+ loss_clip *= clip_scale
840
+ loss += loss_clip
841
+
842
+ if blurry_recon:
843
+ image_enc_pred, transformer_feats = blurry_image_enc_
844
+
845
+ image_enc = autoenc.encode(2*image-1).latent_dist.mode() * 0.18215
846
+ loss_blurry = l1(image_enc_pred, image_enc)
847
+ loss_blurry_total += loss_blurry.item()
848
+
849
+ if epoch < int(mixup_pct * num_epochs):
850
+ image_enc_shuf = image_enc[perm]
851
+ betas_shape = [-1] + [1]*(len(image_enc.shape)-1)
852
+ image_enc[select] = image_enc[select] * betas[select].reshape(*betas_shape) + \
853
+ image_enc_shuf[select] * (1 - betas[select]).reshape(*betas_shape)
854
+
855
+ image_norm = (image - mean)/std
856
+ image_aug = (blur_augs(image) - mean)/std
857
+ _, cnx_embeds = cnx(image_norm)
858
+ _, cnx_aug_embeds = cnx(image_aug)
859
+
860
+ cont_loss = utils.soft_cont_loss(
861
+ nn.functional.normalize(transformer_feats.reshape(-1, transformer_feats.shape[-1]), dim=-1),
862
+ nn.functional.normalize(cnx_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),
863
+ nn.functional.normalize(cnx_aug_embeds.reshape(-1, cnx_embeds.shape[-1]), dim=-1),
864
+ temp=0.2)
865
+ loss_blurry_cont_total += cont_loss.item()
866
+
867
+ loss += (loss_blurry + 0.1*cont_loss) * blur_scale #/.18215
868
+
869
+ if clip_scale>0:
870
+ # forward and backward top 1 accuracy
871
+ labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device)
872
+ fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()
873
+ bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()
874
+
875
+ if blurry_recon:
876
+ with torch.no_grad():
877
+ # only doing pixcorr eval on a subset of the samples per batch because its costly & slow to compute autoenc.decode()
878
+ random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)
879
+ blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample/ 2 + 0.5).clamp(0,1)
880
+ pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)
881
+ blurry_pixcorr += pixcorr.item()
882
+
883
+ utils.check_loss(loss)
884
+ accelerator.backward(loss)
885
+ optimizer.step()
886
+
887
+ losses.append(loss.item())
888
+ lrs.append(optimizer.param_groups[0]['lr'])
889
+
890
+ if lr_scheduler_type is not None:
891
+ lr_scheduler.step()
892
+
893
+ model.eval()
894
+ if local_rank==0:
895
+ with torch.no_grad(), torch.cuda.amp.autocast(dtype=data_type):
896
+ for test_i, (behav, past_behav, future_behav, old_behav) in enumerate(test_dl):
897
+ # all test samples should be loaded per batch such that test_i should never exceed 0
898
+ assert len(behav) == num_test
899
+
900
+ ## Average same-image repeats ##
901
+ if test_image is None:
902
+ voxel = voxels[f'subj0{subj}'][behav[:,0,5].cpu().long()].unsqueeze(1)
903
+
904
+ image = behav[:,0,0].cpu().long()
905
+
906
+ unique_image, sort_indices = torch.unique(image, return_inverse=True)
907
+ for im in unique_image:
908
+ locs = torch.where(im == image)[0]
909
+ if len(locs)==1:
910
+ locs = locs.repeat(3)
911
+ elif len(locs)==2:
912
+ locs = locs.repeat(2)[:3]
913
+ assert len(locs)==3
914
+ if test_image is None:
915
+ test_image = torch.Tensor(images[im][None])
916
+ test_voxel = voxel[locs][None]
917
+ else:
918
+ test_image = torch.vstack((test_image, torch.Tensor(images[im][None])))
919
+ test_voxel = torch.vstack((test_voxel, voxel[locs][None]))
920
+
921
+ loss=0.
922
+
923
+ test_indices = torch.arange(len(test_voxel))[:300]
924
+ voxel = test_voxel[test_indices].to(device)
925
+ image = test_image[test_indices].to(device)
926
+ assert len(image) == 300
927
+
928
+ clip_target = clip_img_embedder(image.float())
929
+
930
+ for rep in range(3):
931
+ voxel_ridge = model.ridge(voxel[:,rep],0) # 0th index of subj_list
932
+ backbone0, clip_voxels0, blurry_image_enc_ = model.backbone(voxel_ridge)
933
+
934
+ logits0 = model.RRClassifier(backbone0.flatten(1))
935
+
936
+ if rep==0:
937
+ clip_voxels = clip_voxels0
938
+ backbone = backbone0
939
+ logits = logits0
940
+ else:
941
+ clip_voxels += clip_voxels0
942
+ backbone += backbone0
943
+ logits += logits0
944
+ clip_voxels /= 3
945
+ backbone /= 3
946
+ logits /= 3
947
+
948
+ print(logits.shape, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).shape)
949
+ RR_loss = nn.functional.cross_entropy(logits, torch.argmax(semantic_cluster_onehot[test_indices], dim=1).to(logits.device))
950
+ test_loss_RR_total += RR_loss.item()
951
+ loss += RR_loss
952
+
953
+ if clip_scale>0:
954
+ clip_voxels_norm = nn.functional.normalize(clip_voxels.flatten(1), dim=-1)
955
+ clip_target_norm = nn.functional.normalize(clip_target.flatten(1), dim=-1)
956
+
957
+ # for some evals, only doing a subset of the samples per batch because of computational cost
958
+ random_samps = np.random.choice(np.arange(len(image)), size=len(image)//5, replace=False)
959
+
960
+ # if use_prior:
961
+ # loss_prior, contaminated_prior_out = model.diffusion_prior(text_embed=backbone[random_samps], image_embed=clip_target[random_samps])
962
+ # test_loss_prior_total += loss_prior.item()
963
+ # loss_prior *= prior_scale
964
+ # loss += loss_prior
965
+
966
+ if clip_scale>0:
967
+ loss_clip = utils.soft_clip_loss(
968
+ clip_voxels_norm,
969
+ clip_target_norm,
970
+ temp=.006)
971
+
972
+ test_loss_clip_total += loss_clip.item()
973
+ loss_clip = loss_clip * clip_scale
974
+ loss += loss_clip
975
+
976
+ if blurry_recon:
977
+ image_enc_pred, _ = blurry_image_enc_
978
+ blurry_recon_images = (autoenc.decode(image_enc_pred[random_samps]/0.18215).sample / 2 + 0.5).clamp(0,1)
979
+ pixcorr = utils.pixcorr(image[random_samps], blurry_recon_images)
980
+ test_blurry_pixcorr += pixcorr.item()
981
+
982
+ if clip_scale>0:
983
+ # forward and backward top 1 accuracy
984
+ labels = torch.arange(len(clip_voxels_norm)).to(clip_voxels_norm.device)
985
+ test_fwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_voxels_norm, clip_target_norm), labels, k=1).item()
986
+ test_bwd_percent_correct += utils.topk(utils.batchwise_cosine_similarity(clip_target_norm, clip_voxels_norm), labels, k=1).item()
987
+
988
+ utils.check_loss(loss)
989
+ test_losses.append(loss.item())
990
+
991
+ assert (test_i+1) == 1
992
+ logs = {"train/loss": np.mean(losses[-(train_i+1):]),
993
+ "test/loss": np.mean(test_losses[-(test_i+1):]),
994
+ "train/lr": lrs[-1],
995
+ "train/num_steps": len(losses),
996
+ "test/num_steps": len(test_losses),
997
+ "train/fwd_pct_correct": fwd_percent_correct / (train_i + 1),
998
+ "train/bwd_pct_correct": bwd_percent_correct / (train_i + 1),
999
+ "test/test_fwd_pct_correct": test_fwd_percent_correct / (test_i + 1),
1000
+ "test/test_bwd_pct_correct": test_bwd_percent_correct / (test_i + 1),
1001
+ "train/loss_clip_total": loss_clip_total / (train_i + 1),
1002
+ "train/loss_blurry_total": loss_blurry_total / (train_i + 1),
1003
+ "train/loss_blurry_cont_total": loss_blurry_cont_total / (train_i + 1),
1004
+ "test/loss_clip_total": test_loss_clip_total / (test_i + 1),
1005
+ "train/blurry_pixcorr": blurry_pixcorr / (train_i + 1),
1006
+ "test/blurry_pixcorr": test_blurry_pixcorr / (test_i + 1),
1007
+ "train/recon_cossim": recon_cossim / (train_i + 1),
1008
+ "test/recon_cossim": test_recon_cossim / (test_i + 1),
1009
+ "train/recon_mse": recon_mse / (train_i + 1),
1010
+ "test/recon_mse": test_recon_mse / (test_i + 1),
1011
+ "train/loss_prior": loss_prior_total / (train_i + 1),
1012
+ "test/loss_prior": test_loss_prior_total / (test_i + 1),
1013
+ "train/loss_RR": loss_RR_total / (train_i + 1),
1014
+ "test/loss_RR": test_loss_RR_total / (test_i + 1),
1015
+ }
1016
+
1017
+ # if finished training, save jpg recons if they exist
1018
+ if (epoch == num_epochs-1) or (epoch % ckpt_interval == 0):
1019
+ if blurry_recon:
1020
+ image_enc = autoenc.encode(2*image[:4]-1).latent_dist.mode() * 0.18215
1021
+ # transform blurry recon latents to images and plot it
1022
+ fig, axes = plt.subplots(1, 8, figsize=(10, 4))
1023
+ jj=-1
1024
+ for j in [0,1,2,3]:
1025
+ jj+=1
1026
+ axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))
1027
+ axes[jj].axis('off')
1028
+ jj+=1
1029
+ axes[jj].imshow(utils.torch_to_Image((autoenc.decode(image_enc_pred[[j]]/0.18215).sample / 2 + 0.5).clamp(0,1)))
1030
+ axes[jj].axis('off')
1031
+
1032
+ if wandb_log:
1033
+ logs[f"test/blur_recons"] = wandb.Image(fig, caption=f"epoch{epoch:03d}")
1034
+ plt.close()
1035
+ else:
1036
+ plt.show()
1037
+
1038
+ progress_bar.set_postfix(**logs)
1039
+
1040
+ if wandb_log: wandb.log(logs)
1041
+
1042
+ # Save model checkpoint and reconstruct
1043
+ if (ckpt_saving) and (epoch % ckpt_interval == 0):
1044
+ save_ckpt(f'last')
1045
+
1046
+ # wait for other GPUs to catch up if needed
1047
+ accelerator.wait_for_everyone()
1048
+ torch.cuda.empty_cache()
1049
+
1050
+ print("\n===Finished!===\n")
1051
+ if ckpt_saving:
1052
+ save_ckpt(f'last')
1053
+
1054
+
1055
+ # In[ ]:
1056
+
1057
+
1058
+ plt.plot(losses)
1059
+ plt.show()
1060
+ plt.plot(test_losses)
1061
+ plt.show()
1062
+
1063
+
1064
+ # In[29]:
1065
+
1066
+
1067
+ import wandb
1068
+ wandb.login()
1069
+
MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/config.yaml ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ wandb_version: 1
2
+
3
+ model_name:
4
+ desc: null
5
+ value: rr-test
6
+ global_batch_size:
7
+ desc: null
8
+ value: '21'
9
+ batch_size:
10
+ desc: null
11
+ value: 3
12
+ num_epochs:
13
+ desc: null
14
+ value: 150
15
+ num_sessions:
16
+ desc: null
17
+ value: 40
18
+ num_params:
19
+ desc: null
20
+ value: 573919937
21
+ clip_scale:
22
+ desc: null
23
+ value: 1.0
24
+ prior_scale:
25
+ desc: null
26
+ value: 30.0
27
+ blur_scale:
28
+ desc: null
29
+ value: 0.5
30
+ use_image_aug:
31
+ desc: null
32
+ value: false
33
+ max_lr:
34
+ desc: null
35
+ value: 0.0003
36
+ mixup_pct:
37
+ desc: null
38
+ value: 0.33
39
+ num_samples_per_epoch:
40
+ desc: null
41
+ value: 3750
42
+ num_test:
43
+ desc: null
44
+ value: 3000
45
+ ckpt_interval:
46
+ desc: null
47
+ value: 999
48
+ ckpt_saving:
49
+ desc: null
50
+ value: true
51
+ seed:
52
+ desc: null
53
+ value: 42
54
+ distributed:
55
+ desc: null
56
+ value: true
57
+ num_devices:
58
+ desc: null
59
+ value: 8
60
+ world_size:
61
+ desc: null
62
+ value: 1
63
+ train_url:
64
+ desc: null
65
+ value: /weka/proj-medarc/shared/mindeyev2_dataset/wds/subj08/train/{0..29}.tar
66
+ test_url:
67
+ desc: null
68
+ value: /weka/proj-medarc/shared/mindeyev2_dataset/wds/subj02/new_test/0.tar
69
+ _wandb:
70
+ desc: null
71
+ value:
72
+ code_path: code/src/TrainCluster.py
73
+ python_version: 3.11.9
74
+ cli_version: 0.17.1
75
+ framework: huggingface
76
+ huggingface_version: 4.37.2
77
+ is_jupyter_run: false
78
+ is_kaggle_kernel: false
79
+ start_time: 1718712973
80
+ t:
81
+ 1:
82
+ - 1
83
+ - 9
84
+ - 11
85
+ - 41
86
+ - 49
87
+ - 55
88
+ - 63
89
+ - 71
90
+ - 79
91
+ - 83
92
+ - 103
93
+ 3:
94
+ - 13
95
+ - 14
96
+ - 16
97
+ - 23
98
+ 4: 3.11.9
99
+ 5: 0.17.1
100
+ 6: 4.37.2
101
+ 8:
102
+ - 5
103
+ 13: linux-x86_64
MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/diff.patch ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/src/Train.ipynb b/src/Train.ipynb
2
+ index 91922c8..396549d 100644
3
+ --- a/src/Train.ipynb
4
+ +++ b/src/Train.ipynb
5
+ @@ -99,7 +99,7 @@
6
+ "name": "stdout",
7
+ "output_type": "stream",
8
+ "text": [
9
+ - "PID of this process = 3001293\n",
10
+ + "PID of this process = 3520819\n",
11
+ "device: cuda\n",
12
+ "Distributed environment: DistributedType.NO\n",
13
+ "Num processes: 1\n",
14
+ @@ -1362,9 +1362,9 @@
15
+ ],
16
+ "metadata": {
17
+ "kernelspec": {
18
+ - "display_name": "mindeye",
19
+ + "display_name": "Python 3 (ipykernel)",
20
+ "language": "python",
21
+ - "name": "mindeye"
22
+ + "name": "python3"
23
+ },
24
+ "language_info": {
25
+ "codemirror_mode": {
26
+ diff --git a/src/accel.slurm b/src/accel.slurm
27
+ index 1c1dfbc..5623c78 100644
28
+ --- a/src/accel.slurm
29
+ +++ b/src/accel.slurm
30
+ @@ -1,7 +1,7 @@
31
+ #!/bin/bash
32
+ -#SBATCH --account=topfmri
33
+ -#SBATCH --partition=a40x
34
+ -#SBATCH --job-name=eye
35
+ +#SBATCH --account=fmri
36
+ +#SBATCH --partition=p5
37
+ +#SBATCH --job-name=eyeRR
38
+ #SBATCH --nodes=1
39
+ #SBATCH --gres=gpu:1
40
+ #SBATCH --time=48:00:00 # total run time limit (HH:MM:SS)
41
+ @@ -12,11 +12,11 @@
42
+ #SBATCH --exclusive
43
+
44
+ # Make sure you activate your fmri environment created from src/setup.sh
45
+ -cd /weka/proj-fmri/paulscotti/MindEyeV2/src
46
+ -source fmri/bin/activate
47
+ +cd /weka/proj-fmri/ckadirt/MindEyeV2/src
48
+ +source /admin/home-ckadirt/fmri/bin/activate
49
+
50
+ # The following line converts your jupyter notebook into a python script runnable with Slurm
51
+ -jupyter nbconvert Train.ipynb --to python
52
+ +jupyter nbconvert TrainCluster.ipynb --to python
53
+
54
+ export NUM_GPUS=1 # Set to equal gres=gpu:#!
55
+ export BATCH_SIZE=21 # 21 for multisubject / 24 for singlesubject (orig. paper used 42 for multisubject / 24 for singlesubject)
56
+ @@ -32,9 +32,9 @@ echo MASTER_PORT=${MASTER_PORT}
57
+ echo WORLD_SIZE=${COUNT_NODE}
58
+
59
+ # multisubject pretraining
60
+ -model_name="multisubject_excludingsubj01_40sess"
61
+ +model_name="rr-test"
62
+ echo model_name=${model_name}
63
+ -accelerate launch --num_processes=$(($NUM_GPUS * $COUNT_NODE)) --num_machines=$COUNT_NODE --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --mixed_precision=fp16 Train.py --data_path=/weka/proj-fmri/shared/mindeyev2_dataset --cache_dir=/weka/proj-fmri/shared/cache --model_name=${model_name} --multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --use_prior --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
64
+ +accelerate launch --num_processes=$(($NUM_GPUS * $COUNT_NODE)) --num_machines=$COUNT_NODE --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --mixed_precision=fp16 TrainCluster.py --data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=${model_name} --multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
65
+
66
+ # singlesubject finetuning
67
+ #model_name="finetuned_subj01_40sess"
68
+ diff --git a/src/recon_inference.ipynb b/src/recon_inference.ipynb
69
+ index 10d7e27..0593e7e 100644
70
+ --- a/src/recon_inference.ipynb
71
+ +++ b/src/recon_inference.ipynb
72
+ @@ -12,7 +12,6 @@
73
+ "name": "stdout",
74
+ "output_type": "stream",
75
+ "text": [
76
+ - "LOCAL RANK 0\n",
77
+ "device: cuda\n"
78
+ ]
79
+ }
80
+ @@ -60,7 +59,7 @@
81
+ },
82
+ {
83
+ "cell_type": "code",
84
+ - "execution_count": 33,
85
+ + "execution_count": 2,
86
+ "id": "e52985b1-95ff-487b-8b2d-cc1ad1c190b8",
87
+ "metadata": {
88
+ "tags": []
89
+ @@ -71,9 +70,7 @@
90
+ "output_type": "stream",
91
+ "text": [
92
+ "model_name: final_subj01_pretrained_40sess_24bs\n",
93
+ - "--data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/mindeyev2_dataset --model_name=final_subj01_pretrained_40sess_24bs --subj=1 --hidden_dim=4096 --n_blocks=4 --new_test\n",
94
+ - "The autoreload extension is already loaded. To reload it, use:\n",
95
+ - " %reload_ext autoreload\n"
96
+ + "--data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/mindeyev2_dataset --model_name=final_subj01_pretrained_40sess_24bs --subj=1 --hidden_dim=4096 --n_blocks=4 --new_test\n"
97
+ ]
98
+ }
99
+ ],
100
+ @@ -99,7 +96,7 @@
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ - "execution_count": 34,
105
+ + "execution_count": 3,
106
+ "id": "49e5dae4-606d-4dc6-b420-df9e4c14737e",
107
+ "metadata": {
108
+ "tags": []
109
+ @@ -157,7 +154,7 @@
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ - "execution_count": 35,
114
+ + "execution_count": 4,
115
+ "id": "64672583-9f00-46f5-8d4e-00e4c7068a1d",
116
+ "metadata": {
117
+ "tags": []
118
+ @@ -221,7 +218,7 @@
119
+ },
120
+ {
121
+ "cell_type": "code",
122
+ - "execution_count": 36,
123
+ + "execution_count": 5,
124
+ "id": "a3cbeea8-e95b-48d9-9bc2-91af260c93d1",
125
+ "metadata": {},
126
+ "outputs": [
127
+ @@ -254,39 +251,10 @@
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ - "execution_count": 38,
132
+ + "execution_count": null,
133
+ "id": "3afc4858-b6a6-4a52-9303-b4a50ea5cc0b",
134
+ "metadata": {},
135
+ - "outputs": [
136
+ - {
137
+ - "name": "stdout",
138
+ - "output_type": "stream",
139
+ - "text": [
140
+ - "param counts:\n",
141
+ - "83,653,863 total\n",
142
+ - "0 trainable\n",
143
+ - "param counts:\n",
144
+ - "64,409,600 total\n",
145
+ - "64,409,600 trainable\n",
146
+ - "param counts:\n",
147
+ - "1,903,020,028 total\n",
148
+ - "1,903,020,028 trainable\n",
149
+ - "param counts:\n",
150
+ - "1,967,429,628 total\n",
151
+ - "1,967,429,628 trainable\n",
152
+ - "param counts:\n",
153
+ - "259,865,216 total\n",
154
+ - "259,865,200 trainable\n",
155
+ - "param counts:\n",
156
+ - "2,227,294,844 total\n",
157
+ - "2,227,294,828 trainable\n",
158
+ - "\n",
159
+ - "---loading /weka/proj-fmri/paulscotti/MindEye2_git/train_logs/final_subj01_pretrained_40sess_24bs/last.pth ckpt---\n",
160
+ - "\n",
161
+ - "ckpt loaded!\n"
162
+ - ]
163
+ - }
164
+ - ],
165
+ + "outputs": [],
166
+ "source": [
167
+ "clip_img_embedder = FrozenOpenCLIPImageEmbedder(\n",
168
+ " arch=\"ViT-bigG-14\",\n",
169
+ @@ -393,7 +361,7 @@
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ - "execution_count": 30,
174
+ + "execution_count": null,
175
+ "id": "295824db-ab3d-450c-90fb-f656e48994ba",
176
+ "metadata": {
177
+ "tags": []
178
+ @@ -430,38 +398,10 @@
179
+ },
180
+ {
181
+ "cell_type": "code",
182
+ - "execution_count": 31,
183
+ + "execution_count": null,
184
+ "id": "f726f617-39f5-49e2-8d0c-d11d27d01c30",
185
+ "metadata": {},
186
+ - "outputs": [
187
+ - {
188
+ - "name": "stderr",
189
+ - "output_type": "stream",
190
+ - "text": [
191
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
192
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
193
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
194
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
195
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
196
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
197
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
198
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
199
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
200
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
201
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n"
202
+ - ]
203
+ - },
204
+ - {
205
+ - "name": "stdout",
206
+ - "output_type": "stream",
207
+ - "text": [
208
+ - "Initialized embedder #0: FrozenOpenCLIPImageEmbedder with 1909889025 params. Trainable: False\n",
209
+ - "Initialized embedder #1: ConcatTimestepEmbedderND with 0 params. Trainable: False\n",
210
+ - "Initialized embedder #2: ConcatTimestepEmbedderND with 0 params. Trainable: False\n",
211
+ - "vector_suffix torch.Size([1, 1024])\n"
212
+ - ]
213
+ - }
214
+ - ],
215
+ + "outputs": [],
216
+ "source": [
217
+ "# prep unCLIP\n",
218
+ "config = OmegaConf.load(\"generative_models/configs/unclip6.yaml\")\n",
219
+ @@ -715,9 +655,9 @@
220
+ ],
221
+ "metadata": {
222
+ "kernelspec": {
223
+ - "display_name": "mindeye",
224
+ + "display_name": "Python 3 (ipykernel)",
225
+ "language": "python",
226
+ - "name": "mindeye"
227
+ + "name": "python3"
228
+ },
229
+ "language_info": {
230
+ "codemirror_mode": {
MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/requirements.txt ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Babel==2.15.0
2
+ CoCa-pytorch==0.1.0
3
+ GitPython==3.1.43
4
+ Jinja2==3.1.4
5
+ MarkupSafe==2.1.5
6
+ PyYAML==6.0.1
7
+ Pygments==2.18.0
8
+ QtPy==2.4.1
9
+ Send2Trash==1.8.3
10
+ absl-py==2.1.0
11
+ accelerate==0.24.1
12
+ aiohttp==3.9.5
13
+ aiosignal==1.3.1
14
+ annotated-types==0.7.0
15
+ antlr4-python3-runtime==4.9.3
16
+ anyio==4.4.0
17
+ argon2-cffi-bindings==21.2.0
18
+ argon2-cffi==23.1.0
19
+ arrow==1.3.0
20
+ asttokens==2.4.1
21
+ async-lru==2.0.4
22
+ attrs==23.2.0
23
+ beartype==0.18.5
24
+ beautifulsoup4==4.12.3
25
+ bleach==6.1.0
26
+ braceexpand==0.1.7
27
+ certifi==2024.6.2
28
+ cffi==1.16.0
29
+ charset-normalizer==3.3.2
30
+ click==8.1.7
31
+ clip-anytorch==2.6.0
32
+ clip==1.0
33
+ comm==0.2.2
34
+ contourpy==1.2.1
35
+ cycler==0.12.1
36
+ dalle2-pytorch==1.15.6
37
+ datasets==2.20.0
38
+ debugpy==1.8.1
39
+ decorator==5.1.1
40
+ deepspeed==0.13.1
41
+ defusedxml==0.7.1
42
+ diffusers==0.23.0
43
+ dill==0.3.8
44
+ docker-pycreds==0.4.0
45
+ einops==0.8.0
46
+ einx==0.3.0
47
+ ema-pytorch==0.5.0
48
+ embedding-reader==1.7.0
49
+ evaluate==0.4.1
50
+ executing==2.0.1
51
+ fastjsonschema==2.20.0
52
+ filelock==3.15.1
53
+ fonttools==4.53.0
54
+ fqdn==1.5.1
55
+ frozendict==2.4.4
56
+ frozenlist==1.4.1
57
+ fsspec==2024.5.0
58
+ ftfy==6.2.0
59
+ gitdb==4.0.11
60
+ h11==0.14.0
61
+ h5py==3.10.0
62
+ hjson==3.1.0
63
+ httpcore==1.0.5
64
+ httpx==0.27.0
65
+ huggingface-hub==0.23.4
66
+ idna==3.7
67
+ imageio==2.34.1
68
+ importlib_metadata==7.1.0
69
+ ipykernel==6.29.4
70
+ ipython==8.25.0
71
+ ipywidgets==8.1.3
72
+ isoduration==20.11.0
73
+ jedi==0.19.1
74
+ joblib==1.4.2
75
+ json5==0.9.25
76
+ jsonpointer==3.0.0
77
+ jsonschema-specifications==2023.12.1
78
+ jsonschema==4.22.0
79
+ jupyter-console==6.6.3
80
+ jupyter-events==0.10.0
81
+ jupyter-lsp==2.2.5
82
+ jupyter==1.0.0
83
+ jupyter_client==8.6.2
84
+ jupyter_core==5.7.2
85
+ jupyter_server==2.14.1
86
+ jupyter_server_terminals==0.5.3
87
+ jupyterlab==4.2.2
88
+ jupyterlab_nvdashboard==0.11.0
89
+ jupyterlab_pygments==0.3.0
90
+ jupyterlab_server==2.27.2
91
+ jupyterlab_widgets==3.0.11
92
+ kiwisolver==1.4.5
93
+ kornia==0.7.1
94
+ lazy_loader==0.4
95
+ lightning-utilities==0.11.2
96
+ matplotlib-inline==0.1.7
97
+ matplotlib==3.8.2
98
+ mistune==3.0.2
99
+ mpmath==1.3.0
100
+ multidict==6.0.5
101
+ multiprocess==0.70.16
102
+ nbclient==0.10.0
103
+ nbconvert==7.16.4
104
+ nbformat==5.10.4
105
+ nest-asyncio==1.6.0
106
+ networkx==3.3
107
+ ninja==1.11.1.1
108
+ nltk==3.8.1
109
+ notebook==7.2.1
110
+ notebook_shim==0.2.4
111
+ numpy==1.26.4
112
+ nvidia-cublas-cu12==12.1.3.1
113
+ nvidia-cuda-cupti-cu12==12.1.105
114
+ nvidia-cuda-nvrtc-cu12==12.1.105
115
+ nvidia-cuda-runtime-cu12==12.1.105
116
+ nvidia-cudnn-cu12==8.9.2.26
117
+ nvidia-cufft-cu12==11.0.2.54
118
+ nvidia-curand-cu12==10.3.2.106
119
+ nvidia-cusolver-cu12==11.4.5.107
120
+ nvidia-cusparse-cu12==12.1.0.106
121
+ nvidia-nccl-cu12==2.18.1
122
+ nvidia-nvjitlink-cu12==12.5.40
123
+ nvidia-nvtx-cu12==12.1.105
124
+ omegaconf==2.3.0
125
+ open-clip-torch==2.24.0
126
+ overrides==7.7.0
127
+ packaging==24.1
128
+ pandas==2.2.0
129
+ pandocfilters==1.5.1
130
+ parso==0.8.4
131
+ pexpect==4.9.0
132
+ pillow==10.3.0
133
+ pip==24.0
134
+ platformdirs==4.2.2
135
+ prometheus_client==0.20.0
136
+ prompt_toolkit==3.0.47
137
+ protobuf==5.27.1
138
+ psutil==5.9.8
139
+ ptyprocess==0.7.0
140
+ pure-eval==0.2.2
141
+ py-cpuinfo==9.0.0
142
+ pyarrow-hotfix==0.6
143
+ pyarrow==15.0.2
144
+ pycparser==2.22
145
+ pydantic==2.7.4
146
+ pydantic_core==2.18.4
147
+ pynvml==11.5.0
148
+ pyparsing==3.1.2
149
+ python-dateutil==2.9.0.post0
150
+ python-json-logger==2.0.7
151
+ pytorch-lightning==2.0.1
152
+ pytorch-warmup==0.1.1
153
+ pytz==2024.1
154
+ pyzmq==26.0.3
155
+ qtconsole==5.5.2
156
+ referencing==0.35.1
157
+ regex==2024.5.15
158
+ requests==2.32.3
159
+ resize-right==0.0.2
160
+ responses==0.18.0
161
+ rfc3339-validator==0.1.4
162
+ rfc3986-validator==0.1.1
163
+ rotary-embedding-torch==0.6.2
164
+ rouge_score==0.1.2
165
+ rpds-py==0.18.1
166
+ safetensors==0.4.3
167
+ scikit-image==0.22.0
168
+ scikit-learn==1.5.0
169
+ scipy==1.13.1
170
+ sentence-transformers==2.5.1
171
+ sentencepiece==0.2.0
172
+ sentry-sdk==2.5.1
173
+ setproctitle==1.3.3
174
+ setuptools==65.5.0
175
+ six==1.16.0
176
+ smmap==5.0.1
177
+ sniffio==1.3.1
178
+ soupsieve==2.5
179
+ stack-data==0.6.3
180
+ sympy==1.12.1
181
+ terminado==0.18.1
182
+ threadpoolctl==3.5.0
183
+ tifffile==2024.5.22
184
+ timm==1.0.3
185
+ tinycss2==1.3.0
186
+ tokenizers==0.15.2
187
+ torch-fidelity==0.3.0
188
+ torch==2.1.0
189
+ torchmetrics==1.3.0.post0
190
+ torchvision==0.16.0
191
+ tornado==6.4.1
192
+ tqdm==4.66.4
193
+ traitlets==5.14.3
194
+ transformers==4.37.2
195
+ triton==2.1.0
196
+ types-python-dateutil==2.9.0.20240316
197
+ typing_extensions==4.12.2
198
+ tzdata==2024.1
199
+ umap==0.1.1
200
+ uri-template==1.3.0
201
+ urllib3==2.2.1
202
+ vector-quantize-pytorch==1.14.24
203
+ wandb==0.17.1
204
+ wcwidth==0.2.13
205
+ webcolors==24.6.0
206
+ webdataset==0.2.73
207
+ webencodings==0.5.1
208
+ websocket-client==1.8.0
209
+ widgetsnbextension==4.0.11
210
+ x-clip==0.14.4
211
+ xformers==0.0.22.post7
212
+ xxhash==3.4.1
213
+ yarl==1.9.4
214
+ zipp==3.19.2
MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/wandb-metadata.json ADDED
@@ -0,0 +1,1057 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "os": "Linux-5.15.0-1058-aws-x86_64-with-glibc2.31",
3
+ "python": "3.11.9",
4
+ "heartbeatAt": "2024-06-18T12:16:14.300329",
5
+ "startedAt": "2024-06-18T12:16:13.354272",
6
+ "docker": null,
7
+ "cuda": null,
8
+ "args": [
9
+ "--data_path=/weka/proj-medarc/shared/mindeyev2_dataset",
10
+ "--cache_dir=/weka/proj-medarc/shared/cache",
11
+ "--model_name=rr-test",
12
+ "--multi_subject",
13
+ "--subj=1",
14
+ "--batch_size=21",
15
+ "--max_lr=3e-4",
16
+ "--mixup_pct=.33",
17
+ "--num_epochs=150",
18
+ "--prior_scale=30",
19
+ "--clip_scale=1",
20
+ "--no-blurry_recon",
21
+ "--blur_scale=.5",
22
+ "--no-use_image_aug",
23
+ "--n_blocks=4",
24
+ "--hidden_dim=1024",
25
+ "--num_sessions=40",
26
+ "--ckpt_interval=999",
27
+ "--ckpt_saving",
28
+ "--wandb_log"
29
+ ],
30
+ "state": "running",
31
+ "program": "/weka/proj-fmri/ckadirt/MindEyeV2/src/TrainCluster.py",
32
+ "codePathLocal": "TrainCluster.py",
33
+ "codePath": "src/TrainCluster.py",
34
+ "git": {
35
+ "remote": "https://github.com/MedARC-AI/MindEyeV2.git",
36
+ "commit": "a3588f0fadc81bdb0cc3e15993c01f8dd64dc7fe"
37
+ },
38
+ "email": null,
39
+ "root": "/weka/proj-fmri/ckadirt/MindEyeV2",
40
+ "host": "ip-10-0-154-61",
41
+ "username": "ckadirt",
42
+ "executable": "/admin/home-ckadirt/fmri/bin/python3.11",
43
+ "cpu_count": 96,
44
+ "cpu_count_logical": 192,
45
+ "cpu_freq": {
46
+ "current": 2694.2966979166763,
47
+ "min": 0.0,
48
+ "max": 0.0
49
+ },
50
+ "cpu_freq_per_core": [
51
+ {
52
+ "current": 2649.998,
53
+ "min": 0.0,
54
+ "max": 0.0
55
+ },
56
+ {
57
+ "current": 2649.998,
58
+ "min": 0.0,
59
+ "max": 0.0
60
+ },
61
+ {
62
+ "current": 2649.998,
63
+ "min": 0.0,
64
+ "max": 0.0
65
+ },
66
+ {
67
+ "current": 2649.998,
68
+ "min": 0.0,
69
+ "max": 0.0
70
+ },
71
+ {
72
+ "current": 2649.998,
73
+ "min": 0.0,
74
+ "max": 0.0
75
+ },
76
+ {
77
+ "current": 2649.998,
78
+ "min": 0.0,
79
+ "max": 0.0
80
+ },
81
+ {
82
+ "current": 2649.998,
83
+ "min": 0.0,
84
+ "max": 0.0
85
+ },
86
+ {
87
+ "current": 2649.998,
88
+ "min": 0.0,
89
+ "max": 0.0
90
+ },
91
+ {
92
+ "current": 2649.998,
93
+ "min": 0.0,
94
+ "max": 0.0
95
+ },
96
+ {
97
+ "current": 2649.998,
98
+ "min": 0.0,
99
+ "max": 0.0
100
+ },
101
+ {
102
+ "current": 2649.998,
103
+ "min": 0.0,
104
+ "max": 0.0
105
+ },
106
+ {
107
+ "current": 2649.998,
108
+ "min": 0.0,
109
+ "max": 0.0
110
+ },
111
+ {
112
+ "current": 2649.998,
113
+ "min": 0.0,
114
+ "max": 0.0
115
+ },
116
+ {
117
+ "current": 2649.998,
118
+ "min": 0.0,
119
+ "max": 0.0
120
+ },
121
+ {
122
+ "current": 2649.998,
123
+ "min": 0.0,
124
+ "max": 0.0
125
+ },
126
+ {
127
+ "current": 2649.998,
128
+ "min": 0.0,
129
+ "max": 0.0
130
+ },
131
+ {
132
+ "current": 2649.998,
133
+ "min": 0.0,
134
+ "max": 0.0
135
+ },
136
+ {
137
+ "current": 2649.998,
138
+ "min": 0.0,
139
+ "max": 0.0
140
+ },
141
+ {
142
+ "current": 2649.998,
143
+ "min": 0.0,
144
+ "max": 0.0
145
+ },
146
+ {
147
+ "current": 2649.998,
148
+ "min": 0.0,
149
+ "max": 0.0
150
+ },
151
+ {
152
+ "current": 2649.998,
153
+ "min": 0.0,
154
+ "max": 0.0
155
+ },
156
+ {
157
+ "current": 2649.998,
158
+ "min": 0.0,
159
+ "max": 0.0
160
+ },
161
+ {
162
+ "current": 2649.998,
163
+ "min": 0.0,
164
+ "max": 0.0
165
+ },
166
+ {
167
+ "current": 2649.998,
168
+ "min": 0.0,
169
+ "max": 0.0
170
+ },
171
+ {
172
+ "current": 2649.998,
173
+ "min": 0.0,
174
+ "max": 0.0
175
+ },
176
+ {
177
+ "current": 2649.998,
178
+ "min": 0.0,
179
+ "max": 0.0
180
+ },
181
+ {
182
+ "current": 2649.998,
183
+ "min": 0.0,
184
+ "max": 0.0
185
+ },
186
+ {
187
+ "current": 2649.998,
188
+ "min": 0.0,
189
+ "max": 0.0
190
+ },
191
+ {
192
+ "current": 2649.998,
193
+ "min": 0.0,
194
+ "max": 0.0
195
+ },
196
+ {
197
+ "current": 2649.998,
198
+ "min": 0.0,
199
+ "max": 0.0
200
+ },
201
+ {
202
+ "current": 2649.998,
203
+ "min": 0.0,
204
+ "max": 0.0
205
+ },
206
+ {
207
+ "current": 2649.998,
208
+ "min": 0.0,
209
+ "max": 0.0
210
+ },
211
+ {
212
+ "current": 2649.998,
213
+ "min": 0.0,
214
+ "max": 0.0
215
+ },
216
+ {
217
+ "current": 2649.998,
218
+ "min": 0.0,
219
+ "max": 0.0
220
+ },
221
+ {
222
+ "current": 2649.998,
223
+ "min": 0.0,
224
+ "max": 0.0
225
+ },
226
+ {
227
+ "current": 2649.998,
228
+ "min": 0.0,
229
+ "max": 0.0
230
+ },
231
+ {
232
+ "current": 2649.998,
233
+ "min": 0.0,
234
+ "max": 0.0
235
+ },
236
+ {
237
+ "current": 2649.998,
238
+ "min": 0.0,
239
+ "max": 0.0
240
+ },
241
+ {
242
+ "current": 2649.998,
243
+ "min": 0.0,
244
+ "max": 0.0
245
+ },
246
+ {
247
+ "current": 2649.998,
248
+ "min": 0.0,
249
+ "max": 0.0
250
+ },
251
+ {
252
+ "current": 3112.839,
253
+ "min": 0.0,
254
+ "max": 0.0
255
+ },
256
+ {
257
+ "current": 2649.998,
258
+ "min": 0.0,
259
+ "max": 0.0
260
+ },
261
+ {
262
+ "current": 2649.998,
263
+ "min": 0.0,
264
+ "max": 0.0
265
+ },
266
+ {
267
+ "current": 2649.998,
268
+ "min": 0.0,
269
+ "max": 0.0
270
+ },
271
+ {
272
+ "current": 3597.447,
273
+ "min": 0.0,
274
+ "max": 0.0
275
+ },
276
+ {
277
+ "current": 3597.107,
278
+ "min": 0.0,
279
+ "max": 0.0
280
+ },
281
+ {
282
+ "current": 3596.856,
283
+ "min": 0.0,
284
+ "max": 0.0
285
+ },
286
+ {
287
+ "current": 3597.522,
288
+ "min": 0.0,
289
+ "max": 0.0
290
+ },
291
+ {
292
+ "current": 3597.648,
293
+ "min": 0.0,
294
+ "max": 0.0
295
+ },
296
+ {
297
+ "current": 3598.753,
298
+ "min": 0.0,
299
+ "max": 0.0
300
+ },
301
+ {
302
+ "current": 3598.438,
303
+ "min": 0.0,
304
+ "max": 0.0
305
+ },
306
+ {
307
+ "current": 3597.905,
308
+ "min": 0.0,
309
+ "max": 0.0
310
+ },
311
+ {
312
+ "current": 2649.998,
313
+ "min": 0.0,
314
+ "max": 0.0
315
+ },
316
+ {
317
+ "current": 2649.998,
318
+ "min": 0.0,
319
+ "max": 0.0
320
+ },
321
+ {
322
+ "current": 2649.998,
323
+ "min": 0.0,
324
+ "max": 0.0
325
+ },
326
+ {
327
+ "current": 2649.998,
328
+ "min": 0.0,
329
+ "max": 0.0
330
+ },
331
+ {
332
+ "current": 2649.998,
333
+ "min": 0.0,
334
+ "max": 0.0
335
+ },
336
+ {
337
+ "current": 2649.998,
338
+ "min": 0.0,
339
+ "max": 0.0
340
+ },
341
+ {
342
+ "current": 2649.998,
343
+ "min": 0.0,
344
+ "max": 0.0
345
+ },
346
+ {
347
+ "current": 2649.998,
348
+ "min": 0.0,
349
+ "max": 0.0
350
+ },
351
+ {
352
+ "current": 2649.998,
353
+ "min": 0.0,
354
+ "max": 0.0
355
+ },
356
+ {
357
+ "current": 2649.998,
358
+ "min": 0.0,
359
+ "max": 0.0
360
+ },
361
+ {
362
+ "current": 2649.998,
363
+ "min": 0.0,
364
+ "max": 0.0
365
+ },
366
+ {
367
+ "current": 2649.998,
368
+ "min": 0.0,
369
+ "max": 0.0
370
+ },
371
+ {
372
+ "current": 2649.998,
373
+ "min": 0.0,
374
+ "max": 0.0
375
+ },
376
+ {
377
+ "current": 2649.998,
378
+ "min": 0.0,
379
+ "max": 0.0
380
+ },
381
+ {
382
+ "current": 2649.998,
383
+ "min": 0.0,
384
+ "max": 0.0
385
+ },
386
+ {
387
+ "current": 2649.998,
388
+ "min": 0.0,
389
+ "max": 0.0
390
+ },
391
+ {
392
+ "current": 2649.998,
393
+ "min": 0.0,
394
+ "max": 0.0
395
+ },
396
+ {
397
+ "current": 2649.998,
398
+ "min": 0.0,
399
+ "max": 0.0
400
+ },
401
+ {
402
+ "current": 2649.998,
403
+ "min": 0.0,
404
+ "max": 0.0
405
+ },
406
+ {
407
+ "current": 2649.998,
408
+ "min": 0.0,
409
+ "max": 0.0
410
+ },
411
+ {
412
+ "current": 2649.998,
413
+ "min": 0.0,
414
+ "max": 0.0
415
+ },
416
+ {
417
+ "current": 2649.998,
418
+ "min": 0.0,
419
+ "max": 0.0
420
+ },
421
+ {
422
+ "current": 2649.998,
423
+ "min": 0.0,
424
+ "max": 0.0
425
+ },
426
+ {
427
+ "current": 2649.998,
428
+ "min": 0.0,
429
+ "max": 0.0
430
+ },
431
+ {
432
+ "current": 2649.998,
433
+ "min": 0.0,
434
+ "max": 0.0
435
+ },
436
+ {
437
+ "current": 2649.998,
438
+ "min": 0.0,
439
+ "max": 0.0
440
+ },
441
+ {
442
+ "current": 2649.998,
443
+ "min": 0.0,
444
+ "max": 0.0
445
+ },
446
+ {
447
+ "current": 2649.998,
448
+ "min": 0.0,
449
+ "max": 0.0
450
+ },
451
+ {
452
+ "current": 2649.998,
453
+ "min": 0.0,
454
+ "max": 0.0
455
+ },
456
+ {
457
+ "current": 2649.998,
458
+ "min": 0.0,
459
+ "max": 0.0
460
+ },
461
+ {
462
+ "current": 2649.998,
463
+ "min": 0.0,
464
+ "max": 0.0
465
+ },
466
+ {
467
+ "current": 2649.998,
468
+ "min": 0.0,
469
+ "max": 0.0
470
+ },
471
+ {
472
+ "current": 2649.998,
473
+ "min": 0.0,
474
+ "max": 0.0
475
+ },
476
+ {
477
+ "current": 2649.998,
478
+ "min": 0.0,
479
+ "max": 0.0
480
+ },
481
+ {
482
+ "current": 2649.998,
483
+ "min": 0.0,
484
+ "max": 0.0
485
+ },
486
+ {
487
+ "current": 2649.998,
488
+ "min": 0.0,
489
+ "max": 0.0
490
+ },
491
+ {
492
+ "current": 2649.998,
493
+ "min": 0.0,
494
+ "max": 0.0
495
+ },
496
+ {
497
+ "current": 2649.998,
498
+ "min": 0.0,
499
+ "max": 0.0
500
+ },
501
+ {
502
+ "current": 2649.998,
503
+ "min": 0.0,
504
+ "max": 0.0
505
+ },
506
+ {
507
+ "current": 2649.998,
508
+ "min": 0.0,
509
+ "max": 0.0
510
+ },
511
+ {
512
+ "current": 2649.998,
513
+ "min": 0.0,
514
+ "max": 0.0
515
+ },
516
+ {
517
+ "current": 2649.998,
518
+ "min": 0.0,
519
+ "max": 0.0
520
+ },
521
+ {
522
+ "current": 2649.998,
523
+ "min": 0.0,
524
+ "max": 0.0
525
+ },
526
+ {
527
+ "current": 2649.998,
528
+ "min": 0.0,
529
+ "max": 0.0
530
+ },
531
+ {
532
+ "current": 2649.998,
533
+ "min": 0.0,
534
+ "max": 0.0
535
+ },
536
+ {
537
+ "current": 2649.998,
538
+ "min": 0.0,
539
+ "max": 0.0
540
+ },
541
+ {
542
+ "current": 2649.998,
543
+ "min": 0.0,
544
+ "max": 0.0
545
+ },
546
+ {
547
+ "current": 2649.998,
548
+ "min": 0.0,
549
+ "max": 0.0
550
+ },
551
+ {
552
+ "current": 2649.998,
553
+ "min": 0.0,
554
+ "max": 0.0
555
+ },
556
+ {
557
+ "current": 2649.998,
558
+ "min": 0.0,
559
+ "max": 0.0
560
+ },
561
+ {
562
+ "current": 2649.998,
563
+ "min": 0.0,
564
+ "max": 0.0
565
+ },
566
+ {
567
+ "current": 2649.998,
568
+ "min": 0.0,
569
+ "max": 0.0
570
+ },
571
+ {
572
+ "current": 2649.998,
573
+ "min": 0.0,
574
+ "max": 0.0
575
+ },
576
+ {
577
+ "current": 2649.998,
578
+ "min": 0.0,
579
+ "max": 0.0
580
+ },
581
+ {
582
+ "current": 2649.998,
583
+ "min": 0.0,
584
+ "max": 0.0
585
+ },
586
+ {
587
+ "current": 2649.998,
588
+ "min": 0.0,
589
+ "max": 0.0
590
+ },
591
+ {
592
+ "current": 2649.998,
593
+ "min": 0.0,
594
+ "max": 0.0
595
+ },
596
+ {
597
+ "current": 2649.998,
598
+ "min": 0.0,
599
+ "max": 0.0
600
+ },
601
+ {
602
+ "current": 2649.998,
603
+ "min": 0.0,
604
+ "max": 0.0
605
+ },
606
+ {
607
+ "current": 2649.998,
608
+ "min": 0.0,
609
+ "max": 0.0
610
+ },
611
+ {
612
+ "current": 2649.998,
613
+ "min": 0.0,
614
+ "max": 0.0
615
+ },
616
+ {
617
+ "current": 2649.998,
618
+ "min": 0.0,
619
+ "max": 0.0
620
+ },
621
+ {
622
+ "current": 2649.998,
623
+ "min": 0.0,
624
+ "max": 0.0
625
+ },
626
+ {
627
+ "current": 2649.998,
628
+ "min": 0.0,
629
+ "max": 0.0
630
+ },
631
+ {
632
+ "current": 2649.998,
633
+ "min": 0.0,
634
+ "max": 0.0
635
+ },
636
+ {
637
+ "current": 2649.998,
638
+ "min": 0.0,
639
+ "max": 0.0
640
+ },
641
+ {
642
+ "current": 2649.998,
643
+ "min": 0.0,
644
+ "max": 0.0
645
+ },
646
+ {
647
+ "current": 2649.998,
648
+ "min": 0.0,
649
+ "max": 0.0
650
+ },
651
+ {
652
+ "current": 2649.998,
653
+ "min": 0.0,
654
+ "max": 0.0
655
+ },
656
+ {
657
+ "current": 2649.998,
658
+ "min": 0.0,
659
+ "max": 0.0
660
+ },
661
+ {
662
+ "current": 2649.998,
663
+ "min": 0.0,
664
+ "max": 0.0
665
+ },
666
+ {
667
+ "current": 2649.998,
668
+ "min": 0.0,
669
+ "max": 0.0
670
+ },
671
+ {
672
+ "current": 2649.998,
673
+ "min": 0.0,
674
+ "max": 0.0
675
+ },
676
+ {
677
+ "current": 2649.998,
678
+ "min": 0.0,
679
+ "max": 0.0
680
+ },
681
+ {
682
+ "current": 2649.998,
683
+ "min": 0.0,
684
+ "max": 0.0
685
+ },
686
+ {
687
+ "current": 2649.998,
688
+ "min": 0.0,
689
+ "max": 0.0
690
+ },
691
+ {
692
+ "current": 2649.998,
693
+ "min": 0.0,
694
+ "max": 0.0
695
+ },
696
+ {
697
+ "current": 2649.998,
698
+ "min": 0.0,
699
+ "max": 0.0
700
+ },
701
+ {
702
+ "current": 2649.998,
703
+ "min": 0.0,
704
+ "max": 0.0
705
+ },
706
+ {
707
+ "current": 2649.998,
708
+ "min": 0.0,
709
+ "max": 0.0
710
+ },
711
+ {
712
+ "current": 2649.998,
713
+ "min": 0.0,
714
+ "max": 0.0
715
+ },
716
+ {
717
+ "current": 2649.998,
718
+ "min": 0.0,
719
+ "max": 0.0
720
+ },
721
+ {
722
+ "current": 2649.998,
723
+ "min": 0.0,
724
+ "max": 0.0
725
+ },
726
+ {
727
+ "current": 2649.998,
728
+ "min": 0.0,
729
+ "max": 0.0
730
+ },
731
+ {
732
+ "current": 2649.998,
733
+ "min": 0.0,
734
+ "max": 0.0
735
+ },
736
+ {
737
+ "current": 2649.998,
738
+ "min": 0.0,
739
+ "max": 0.0
740
+ },
741
+ {
742
+ "current": 2649.998,
743
+ "min": 0.0,
744
+ "max": 0.0
745
+ },
746
+ {
747
+ "current": 2649.998,
748
+ "min": 0.0,
749
+ "max": 0.0
750
+ },
751
+ {
752
+ "current": 2649.998,
753
+ "min": 0.0,
754
+ "max": 0.0
755
+ },
756
+ {
757
+ "current": 2649.998,
758
+ "min": 0.0,
759
+ "max": 0.0
760
+ },
761
+ {
762
+ "current": 2649.998,
763
+ "min": 0.0,
764
+ "max": 0.0
765
+ },
766
+ {
767
+ "current": 2649.998,
768
+ "min": 0.0,
769
+ "max": 0.0
770
+ },
771
+ {
772
+ "current": 2649.998,
773
+ "min": 0.0,
774
+ "max": 0.0
775
+ },
776
+ {
777
+ "current": 2649.998,
778
+ "min": 0.0,
779
+ "max": 0.0
780
+ },
781
+ {
782
+ "current": 2649.998,
783
+ "min": 0.0,
784
+ "max": 0.0
785
+ },
786
+ {
787
+ "current": 2649.998,
788
+ "min": 0.0,
789
+ "max": 0.0
790
+ },
791
+ {
792
+ "current": 2649.998,
793
+ "min": 0.0,
794
+ "max": 0.0
795
+ },
796
+ {
797
+ "current": 2649.998,
798
+ "min": 0.0,
799
+ "max": 0.0
800
+ },
801
+ {
802
+ "current": 2649.998,
803
+ "min": 0.0,
804
+ "max": 0.0
805
+ },
806
+ {
807
+ "current": 2649.998,
808
+ "min": 0.0,
809
+ "max": 0.0
810
+ },
811
+ {
812
+ "current": 2649.998,
813
+ "min": 0.0,
814
+ "max": 0.0
815
+ },
816
+ {
817
+ "current": 2649.998,
818
+ "min": 0.0,
819
+ "max": 0.0
820
+ },
821
+ {
822
+ "current": 2649.998,
823
+ "min": 0.0,
824
+ "max": 0.0
825
+ },
826
+ {
827
+ "current": 2649.998,
828
+ "min": 0.0,
829
+ "max": 0.0
830
+ },
831
+ {
832
+ "current": 2649.998,
833
+ "min": 0.0,
834
+ "max": 0.0
835
+ },
836
+ {
837
+ "current": 2649.998,
838
+ "min": 0.0,
839
+ "max": 0.0
840
+ },
841
+ {
842
+ "current": 2649.998,
843
+ "min": 0.0,
844
+ "max": 0.0
845
+ },
846
+ {
847
+ "current": 2649.998,
848
+ "min": 0.0,
849
+ "max": 0.0
850
+ },
851
+ {
852
+ "current": 2649.998,
853
+ "min": 0.0,
854
+ "max": 0.0
855
+ },
856
+ {
857
+ "current": 2649.998,
858
+ "min": 0.0,
859
+ "max": 0.0
860
+ },
861
+ {
862
+ "current": 2649.998,
863
+ "min": 0.0,
864
+ "max": 0.0
865
+ },
866
+ {
867
+ "current": 2649.998,
868
+ "min": 0.0,
869
+ "max": 0.0
870
+ },
871
+ {
872
+ "current": 2649.998,
873
+ "min": 0.0,
874
+ "max": 0.0
875
+ },
876
+ {
877
+ "current": 2649.998,
878
+ "min": 0.0,
879
+ "max": 0.0
880
+ },
881
+ {
882
+ "current": 2649.998,
883
+ "min": 0.0,
884
+ "max": 0.0
885
+ },
886
+ {
887
+ "current": 2649.998,
888
+ "min": 0.0,
889
+ "max": 0.0
890
+ },
891
+ {
892
+ "current": 2649.998,
893
+ "min": 0.0,
894
+ "max": 0.0
895
+ },
896
+ {
897
+ "current": 2649.998,
898
+ "min": 0.0,
899
+ "max": 0.0
900
+ },
901
+ {
902
+ "current": 2649.998,
903
+ "min": 0.0,
904
+ "max": 0.0
905
+ },
906
+ {
907
+ "current": 3362.07,
908
+ "min": 0.0,
909
+ "max": 0.0
910
+ },
911
+ {
912
+ "current": 2649.998,
913
+ "min": 0.0,
914
+ "max": 0.0
915
+ },
916
+ {
917
+ "current": 2649.998,
918
+ "min": 0.0,
919
+ "max": 0.0
920
+ },
921
+ {
922
+ "current": 2649.998,
923
+ "min": 0.0,
924
+ "max": 0.0
925
+ },
926
+ {
927
+ "current": 2649.998,
928
+ "min": 0.0,
929
+ "max": 0.0
930
+ },
931
+ {
932
+ "current": 2649.998,
933
+ "min": 0.0,
934
+ "max": 0.0
935
+ },
936
+ {
937
+ "current": 3374.828,
938
+ "min": 0.0,
939
+ "max": 0.0
940
+ },
941
+ {
942
+ "current": 2649.998,
943
+ "min": 0.0,
944
+ "max": 0.0
945
+ },
946
+ {
947
+ "current": 2649.998,
948
+ "min": 0.0,
949
+ "max": 0.0
950
+ },
951
+ {
952
+ "current": 2649.998,
953
+ "min": 0.0,
954
+ "max": 0.0
955
+ },
956
+ {
957
+ "current": 2649.998,
958
+ "min": 0.0,
959
+ "max": 0.0
960
+ },
961
+ {
962
+ "current": 2649.998,
963
+ "min": 0.0,
964
+ "max": 0.0
965
+ },
966
+ {
967
+ "current": 2649.998,
968
+ "min": 0.0,
969
+ "max": 0.0
970
+ },
971
+ {
972
+ "current": 2649.998,
973
+ "min": 0.0,
974
+ "max": 0.0
975
+ },
976
+ {
977
+ "current": 2649.998,
978
+ "min": 0.0,
979
+ "max": 0.0
980
+ },
981
+ {
982
+ "current": 2649.998,
983
+ "min": 0.0,
984
+ "max": 0.0
985
+ },
986
+ {
987
+ "current": 2649.998,
988
+ "min": 0.0,
989
+ "max": 0.0
990
+ },
991
+ {
992
+ "current": 2649.998,
993
+ "min": 0.0,
994
+ "max": 0.0
995
+ },
996
+ {
997
+ "current": 2649.998,
998
+ "min": 0.0,
999
+ "max": 0.0
1000
+ },
1001
+ {
1002
+ "current": 2649.998,
1003
+ "min": 0.0,
1004
+ "max": 0.0
1005
+ },
1006
+ {
1007
+ "current": 2649.998,
1008
+ "min": 0.0,
1009
+ "max": 0.0
1010
+ }
1011
+ ],
1012
+ "disk": {
1013
+ "/": {
1014
+ "total": 232.4169158935547,
1015
+ "used": 170.42882919311523
1016
+ }
1017
+ },
1018
+ "gpu": "NVIDIA H100 80GB HBM3",
1019
+ "gpu_count": 8,
1020
+ "gpu_devices": [
1021
+ {
1022
+ "name": "NVIDIA H100 80GB HBM3",
1023
+ "memory_total": 85520809984
1024
+ },
1025
+ {
1026
+ "name": "NVIDIA H100 80GB HBM3",
1027
+ "memory_total": 85520809984
1028
+ },
1029
+ {
1030
+ "name": "NVIDIA H100 80GB HBM3",
1031
+ "memory_total": 85520809984
1032
+ },
1033
+ {
1034
+ "name": "NVIDIA H100 80GB HBM3",
1035
+ "memory_total": 85520809984
1036
+ },
1037
+ {
1038
+ "name": "NVIDIA H100 80GB HBM3",
1039
+ "memory_total": 85520809984
1040
+ },
1041
+ {
1042
+ "name": "NVIDIA H100 80GB HBM3",
1043
+ "memory_total": 85520809984
1044
+ },
1045
+ {
1046
+ "name": "NVIDIA H100 80GB HBM3",
1047
+ "memory_total": 85520809984
1048
+ },
1049
+ {
1050
+ "name": "NVIDIA H100 80GB HBM3",
1051
+ "memory_total": 85520809984
1052
+ }
1053
+ ],
1054
+ "memory": {
1055
+ "total": 1999.962516784668
1056
+ }
1057
+ }
MindEyeV2/src/wandb/run-20240618_121613-rr-test/logs/debug-internal.log ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2024-06-18 12:16:13,467 INFO StreamThr :828956 [internal.py:wandb_internal():85] W&B internal server running at pid: 828956, started at: 2024-06-18 12:16:13.463596
2
+ 2024-06-18 12:16:13,468 DEBUG HandlerThread:828956 [handler.py:handle_request():158] handle_request: status
3
+ 2024-06-18 12:16:13,492 INFO WriterThread:828956 [datastore.py:open_for_write():87] open: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_121613-rr-test/run-rr-test.wandb
4
+ 2024-06-18 12:16:13,496 DEBUG SenderThread:828956 [sender.py:send():379] send: header
5
+ 2024-06-18 12:16:13,562 DEBUG SenderThread:828956 [sender.py:send():379] send: run
6
+ 2024-06-18 12:16:13,574 INFO SenderThread:828956 [sender.py:_setup_resume():749] checking resume status for None/mindeye_semantic_cluster/rr-test
7
+ 2024-06-18 12:16:14,023 INFO SenderThread:828956 [dir_watcher.py:__init__():211] watching files in: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_121613-rr-test/files
8
+ 2024-06-18 12:16:14,023 INFO SenderThread:828956 [sender.py:_start_run_threads():1188] run started: rr-test with start time 1718712973.469764
9
+ 2024-06-18 12:16:14,048 DEBUG HandlerThread:828956 [handler.py:handle_request():158] handle_request: check_version
10
+ 2024-06-18 12:16:14,048 DEBUG SenderThread:828956 [sender.py:send_request():406] send_request: check_version
11
+ 2024-06-18 12:16:14,148 DEBUG HandlerThread:828956 [handler.py:handle_request():158] handle_request: run_start
12
+ 2024-06-18 12:16:14,236 DEBUG HandlerThread:828956 [system_info.py:__init__():26] System info init
13
+ 2024-06-18 12:16:14,236 DEBUG HandlerThread:828956 [system_info.py:__init__():41] System info init done
14
+ 2024-06-18 12:16:14,236 INFO HandlerThread:828956 [system_monitor.py:start():194] Starting system monitor
15
+ 2024-06-18 12:16:14,237 INFO SystemMonitor:828956 [system_monitor.py:_start():158] Starting system asset monitoring threads
16
+ 2024-06-18 12:16:14,237 INFO HandlerThread:828956 [system_monitor.py:probe():214] Collecting system info
17
+ 2024-06-18 12:16:14,237 INFO SystemMonitor:828956 [interfaces.py:start():188] Started cpu monitoring
18
+ 2024-06-18 12:16:14,238 INFO SystemMonitor:828956 [interfaces.py:start():188] Started disk monitoring
19
+ 2024-06-18 12:16:14,238 INFO SystemMonitor:828956 [interfaces.py:start():188] Started gpu monitoring
20
+ 2024-06-18 12:16:14,239 INFO SystemMonitor:828956 [interfaces.py:start():188] Started memory monitoring
21
+ 2024-06-18 12:16:14,239 INFO SystemMonitor:828956 [interfaces.py:start():188] Started network monitoring
22
+ 2024-06-18 12:16:14,300 DEBUG HandlerThread:828956 [system_info.py:probe():152] Probing system
23
+ 2024-06-18 12:16:14,308 DEBUG HandlerThread:828956 [system_info.py:_probe_git():137] Probing git
24
+ 2024-06-18 12:16:14,331 DEBUG HandlerThread:828956 [system_info.py:_probe_git():145] Probing git done
25
+ 2024-06-18 12:16:14,331 DEBUG HandlerThread:828956 [system_info.py:probe():200] Probing system done
26
+ 2024-06-18 12:16:14,332 DEBUG HandlerThread:828956 [system_monitor.py:probe():223] {'os': 'Linux-5.15.0-1058-aws-x86_64-with-glibc2.31', 'python': '3.11.9', 'heartbeatAt': '2024-06-18T12:16:14.300329', 'startedAt': '2024-06-18T12:16:13.354272', 'docker': None, 'cuda': None, 'args': ('--data_path=/weka/proj-medarc/shared/mindeyev2_dataset', '--cache_dir=/weka/proj-medarc/shared/cache', '--model_name=rr-test', '--multi_subject', '--subj=1', '--batch_size=21', '--max_lr=3e-4', '--mixup_pct=.33', '--num_epochs=150', '--prior_scale=30', '--clip_scale=1', '--no-blurry_recon', '--blur_scale=.5', '--no-use_image_aug', '--n_blocks=4', '--hidden_dim=1024', '--num_sessions=40', '--ckpt_interval=999', '--ckpt_saving', '--wandb_log'), 'state': 'running', 'program': '/weka/proj-fmri/ckadirt/MindEyeV2/src/TrainCluster.py', 'codePathLocal': 'TrainCluster.py', 'codePath': 'src/TrainCluster.py', 'git': {'remote': 'https://github.com/MedARC-AI/MindEyeV2.git', 'commit': 'a3588f0fadc81bdb0cc3e15993c01f8dd64dc7fe'}, 'email': None, 'root': '/weka/proj-fmri/ckadirt/MindEyeV2', 'host': 'ip-10-0-154-61', 'username': 'ckadirt', 'executable': '/admin/home-ckadirt/fmri/bin/python3.11', 'cpu_count': 96, 'cpu_count_logical': 192, 'cpu_freq': {'current': 2694.2966979166763, 'min': 0.0, 'max': 0.0}, 'cpu_freq_per_core': [{'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3112.839, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3597.447, 'min': 0.0, 'max': 0.0}, {'current': 3597.107, 'min': 0.0, 'max': 0.0}, {'current': 3596.856, 'min': 0.0, 'max': 0.0}, {'current': 3597.522, 'min': 0.0, 'max': 0.0}, {'current': 3597.648, 'min': 0.0, 'max': 0.0}, {'current': 3598.753, 'min': 0.0, 'max': 0.0}, {'current': 3598.438, 'min': 0.0, 'max': 0.0}, {'current': 3597.905, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3362.07, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3374.828, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}], 'disk': {'/': {'total': 232.4169158935547, 'used': 170.42882919311523}}, 'gpu': 'NVIDIA H100 80GB HBM3', 'gpu_count': 8, 'gpu_devices': [{'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}], 'memory': {'total': 1999.962516784668}}
27
+ 2024-06-18 12:16:14,332 INFO HandlerThread:828956 [system_monitor.py:probe():224] Finished collecting system info
28
+ 2024-06-18 12:16:14,332 INFO HandlerThread:828956 [system_monitor.py:probe():227] Publishing system info
29
+ 2024-06-18 12:16:14,332 DEBUG HandlerThread:828956 [system_info.py:_save_code():44] Saving code
30
+ 2024-06-18 12:16:14,365 DEBUG HandlerThread:828956 [system_info.py:_save_code():67] Saving code done
31
+ 2024-06-18 12:16:14,365 DEBUG HandlerThread:828956 [system_info.py:_save_patches():84] Saving git patches
32
+ 2024-06-18 12:16:15,014 DEBUG HandlerThread:828956 [system_info.py:_save_patches():126] Saving git patches done
33
+ 2024-06-18 12:16:15,021 INFO HandlerThread:828956 [system_monitor.py:probe():229] Finished publishing system info
34
+ 2024-06-18 12:16:15,033 INFO Thread-12 :828956 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/diff.patch
35
+ 2024-06-18 12:16:15,033 INFO Thread-12 :828956 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/code/src/TrainCluster.py
36
+ 2024-06-18 12:16:15,033 INFO Thread-12 :828956 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/wandb-metadata.json
37
+ 2024-06-18 12:16:15,033 INFO Thread-12 :828956 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/code/src
38
+ 2024-06-18 12:16:15,033 INFO Thread-12 :828956 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/code
39
+ 2024-06-18 12:16:15,039 DEBUG SenderThread:828956 [sender.py:send():379] send: files
40
+ 2024-06-18 12:16:15,040 INFO SenderThread:828956 [sender.py:_save_file():1454] saving file wandb-metadata.json with policy now
41
+ 2024-06-18 12:16:15,040 INFO SenderThread:828956 [sender.py:_save_file():1454] saving file code/src/TrainCluster.py with policy now
42
+ 2024-06-18 12:16:15,040 INFO SenderThread:828956 [sender.py:_save_file():1454] saving file diff.patch with policy now
43
+ 2024-06-18 12:16:15,566 INFO wandb-upload_0:828956 [upload_job.py:push():130] Uploaded file /tmp/tmp9o0_c5jjwandb/05oxlsji-wandb-metadata.json
44
+ 2024-06-18 12:16:15,628 DEBUG HandlerThread:828956 [handler.py:handle_request():158] handle_request: python_packages
45
+ 2024-06-18 12:16:15,629 DEBUG SenderThread:828956 [sender.py:send_request():406] send_request: python_packages
46
+ 2024-06-18 12:16:15,629 DEBUG HandlerThread:828956 [handler.py:handle_request():158] handle_request: stop_status
47
+ 2024-06-18 12:16:15,630 DEBUG HandlerThread:828956 [handler.py:handle_request():158] handle_request: internal_messages
48
+ 2024-06-18 12:16:15,635 DEBUG SenderThread:828956 [sender.py:send_request():406] send_request: stop_status
49
+ 2024-06-18 12:16:15,811 DEBUG SenderThread:828956 [sender.py:send():379] send: telemetry
50
+ 2024-06-18 12:16:15,866 INFO wandb-upload_2:828956 [upload_job.py:push():130] Uploaded file /tmp/tmp9o0_c5jjwandb/xypu7qg2-diff.patch
51
+ 2024-06-18 12:16:15,886 INFO wandb-upload_1:828956 [upload_job.py:push():130] Uploaded file /tmp/tmp9o0_c5jjwandb/z7aiv2ba-code/src/TrainCluster.py
52
+ 2024-06-18 12:16:16,048 INFO Thread-12 :828956 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_121613-rr-test/files/requirements.txt
MindEyeV2/src/wandb/run-20240618_121613-rr-test/logs/debug.log ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2024-06-18 12:16:13,451 INFO MainThread:828664 [wandb_setup.py:_flush():76] Current SDK version is 0.17.1
2
+ 2024-06-18 12:16:13,451 INFO MainThread:828664 [wandb_setup.py:_flush():76] Configure stats pid to 828664
3
+ 2024-06-18 12:16:13,451 INFO MainThread:828664 [wandb_setup.py:_flush():76] Loading settings from /admin/home-ckadirt/.config/wandb/settings
4
+ 2024-06-18 12:16:13,451 INFO MainThread:828664 [wandb_setup.py:_flush():76] Loading settings from /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/settings
5
+ 2024-06-18 12:16:13,451 INFO MainThread:828664 [wandb_setup.py:_flush():76] Loading settings from environment variables: {}
6
+ 2024-06-18 12:16:13,451 INFO MainThread:828664 [wandb_setup.py:_flush():76] Applying setup settings: {'_disable_service': False}
7
+ 2024-06-18 12:16:13,451 INFO MainThread:828664 [wandb_setup.py:_flush():76] Inferring run settings from compute environment: {'program_relpath': 'src/TrainCluster.py', 'program_abspath': '/weka/proj-fmri/ckadirt/MindEyeV2/src/TrainCluster.py', 'program': '/weka/proj-fmri/ckadirt/MindEyeV2/src/TrainCluster.py'}
8
+ 2024-06-18 12:16:13,451 INFO MainThread:828664 [wandb_setup.py:_flush():76] Applying login settings: {}
9
+ 2024-06-18 12:16:13,452 INFO MainThread:828664 [wandb_init.py:_log_setup():520] Logging user logs to /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_121613-rr-test/logs/debug.log
10
+ 2024-06-18 12:16:13,453 INFO MainThread:828664 [wandb_init.py:_log_setup():521] Logging internal logs to /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_121613-rr-test/logs/debug-internal.log
11
+ 2024-06-18 12:16:13,453 INFO MainThread:828664 [wandb_init.py:init():560] calling init triggers
12
+ 2024-06-18 12:16:13,453 INFO MainThread:828664 [wandb_init.py:init():567] wandb.init called with sweep_config: {}
13
+ config: {'model_name': 'rr-test', 'global_batch_size': '21', 'batch_size': 3, 'num_epochs': 150, 'num_sessions': 40, 'num_params': 573919937, 'clip_scale': 1.0, 'prior_scale': 30.0, 'blur_scale': 0.5, 'use_image_aug': False, 'max_lr': 0.0003, 'mixup_pct': 0.33, 'num_samples_per_epoch': 3750, 'num_test': 3000, 'ckpt_interval': 999, 'ckpt_saving': True, 'seed': 42, 'distributed': True, 'num_devices': 8, 'world_size': 1, 'train_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj08/train/{0..29}.tar', 'test_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj02/new_test/0.tar'}
14
+ 2024-06-18 12:16:13,453 INFO MainThread:828664 [wandb_init.py:init():610] starting backend
15
+ 2024-06-18 12:16:13,453 INFO MainThread:828664 [wandb_init.py:init():614] setting up manager
16
+ 2024-06-18 12:16:13,462 INFO MainThread:828664 [backend.py:_multiprocessing_setup():105] multiprocessing start_methods=fork,spawn,forkserver, using: spawn
17
+ 2024-06-18 12:16:13,468 INFO MainThread:828664 [wandb_init.py:init():622] backend started and connected
18
+ 2024-06-18 12:16:13,492 INFO MainThread:828664 [wandb_init.py:init():711] updated telemetry
19
+ 2024-06-18 12:16:13,562 INFO MainThread:828664 [wandb_init.py:init():744] communicating run to backend with 90.0 second timeout
20
+ 2024-06-18 12:16:14,047 INFO MainThread:828664 [wandb_run.py:_on_init():2402] communicating current version
21
+ 2024-06-18 12:16:14,091 INFO MainThread:828664 [wandb_run.py:_on_init():2411] got version response upgrade_message: "wandb version 0.17.2 is available! To upgrade, please run:\n $ pip install wandb --upgrade"
22
+
23
+ 2024-06-18 12:16:14,092 INFO MainThread:828664 [wandb_init.py:init():795] starting run threads in backend
24
+ 2024-06-18 12:16:15,629 INFO MainThread:828664 [wandb_run.py:_console_start():2380] atexit reg
25
+ 2024-06-18 12:16:15,629 INFO MainThread:828664 [wandb_run.py:_redirect():2235] redirect: wrap_raw
26
+ 2024-06-18 12:16:15,630 INFO MainThread:828664 [wandb_run.py:_redirect():2300] Wrapping output streams.
27
+ 2024-06-18 12:16:15,630 INFO MainThread:828664 [wandb_run.py:_redirect():2325] Redirects installed.
28
+ 2024-06-18 12:16:15,638 INFO MainThread:828664 [wandb_init.py:init():838] run started, returning control to user process
MindEyeV2/src/wandb/run-20240618_121613-rr-test/run-rr-test.wandb ADDED
File without changes
MindEyeV2/src/wandb/run-20240618_123614-testing/files/config.yaml ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ wandb_version: 1
2
+
3
+ model_name:
4
+ desc: null
5
+ value: testing
6
+ global_batch_size:
7
+ desc: null
8
+ value: 8
9
+ batch_size:
10
+ desc: null
11
+ value: 8
12
+ num_epochs:
13
+ desc: null
14
+ value: 150
15
+ num_sessions:
16
+ desc: null
17
+ value: 40
18
+ num_params:
19
+ desc: null
20
+ value: 486928065
21
+ clip_scale:
22
+ desc: null
23
+ value: 1.0
24
+ prior_scale:
25
+ desc: null
26
+ value: 30.0
27
+ blur_scale:
28
+ desc: null
29
+ value: 0.5
30
+ use_image_aug:
31
+ desc: null
32
+ value: false
33
+ max_lr:
34
+ desc: null
35
+ value: 0.0003
36
+ mixup_pct:
37
+ desc: null
38
+ value: 0.33
39
+ num_samples_per_epoch:
40
+ desc: null
41
+ value: 30000
42
+ num_test:
43
+ desc: null
44
+ value: 3000
45
+ ckpt_interval:
46
+ desc: null
47
+ value: 999
48
+ ckpt_saving:
49
+ desc: null
50
+ value: false
51
+ seed:
52
+ desc: null
53
+ value: 42
54
+ distributed:
55
+ desc: null
56
+ value: false
57
+ num_devices:
58
+ desc: null
59
+ value: 1
60
+ world_size:
61
+ desc: null
62
+ value: 1
63
+ train_url:
64
+ desc: null
65
+ value: /weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/train/{0..39}.tar
66
+ test_url:
67
+ desc: null
68
+ value: /weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/new_test/0.tar
69
+ _wandb:
70
+ desc: null
71
+ value:
72
+ python_version: 3.11.9
73
+ cli_version: 0.17.1
74
+ framework: huggingface
75
+ huggingface_version: 4.37.2
76
+ is_jupyter_run: true
77
+ is_kaggle_kernel: false
78
+ start_time: 1718714174
79
+ t:
80
+ 1:
81
+ - 1
82
+ - 9
83
+ - 11
84
+ - 41
85
+ - 49
86
+ - 55
87
+ - 63
88
+ - 71
89
+ - 79
90
+ - 83
91
+ - 103
92
+ 2:
93
+ - 1
94
+ - 9
95
+ - 11
96
+ - 41
97
+ - 49
98
+ - 55
99
+ - 63
100
+ - 71
101
+ - 79
102
+ - 83
103
+ - 103
104
+ 3:
105
+ - 13
106
+ - 14
107
+ - 16
108
+ - 23
109
+ 4: 3.11.9
110
+ 5: 0.17.1
111
+ 6: 4.37.2
112
+ 8:
113
+ - 1
114
+ - 5
115
+ 13: linux-x86_64
MindEyeV2/src/wandb/run-20240618_123614-testing/files/diff.patch ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/src/Train.ipynb b/src/Train.ipynb
2
+ index 91922c8..396549d 100644
3
+ --- a/src/Train.ipynb
4
+ +++ b/src/Train.ipynb
5
+ @@ -99,7 +99,7 @@
6
+ "name": "stdout",
7
+ "output_type": "stream",
8
+ "text": [
9
+ - "PID of this process = 3001293\n",
10
+ + "PID of this process = 3520819\n",
11
+ "device: cuda\n",
12
+ "Distributed environment: DistributedType.NO\n",
13
+ "Num processes: 1\n",
14
+ @@ -1362,9 +1362,9 @@
15
+ ],
16
+ "metadata": {
17
+ "kernelspec": {
18
+ - "display_name": "mindeye",
19
+ + "display_name": "Python 3 (ipykernel)",
20
+ "language": "python",
21
+ - "name": "mindeye"
22
+ + "name": "python3"
23
+ },
24
+ "language_info": {
25
+ "codemirror_mode": {
26
+ diff --git a/src/accel.slurm b/src/accel.slurm
27
+ index 1c1dfbc..50097be 100644
28
+ --- a/src/accel.slurm
29
+ +++ b/src/accel.slurm
30
+ @@ -1,7 +1,7 @@
31
+ #!/bin/bash
32
+ -#SBATCH --account=topfmri
33
+ -#SBATCH --partition=a40x
34
+ -#SBATCH --job-name=eye
35
+ +#SBATCH --account=fmri
36
+ +#SBATCH --partition=p5
37
+ +#SBATCH --job-name=eyeRR
38
+ #SBATCH --nodes=1
39
+ #SBATCH --gres=gpu:1
40
+ #SBATCH --time=48:00:00 # total run time limit (HH:MM:SS)
41
+ @@ -12,11 +12,11 @@
42
+ #SBATCH --exclusive
43
+
44
+ # Make sure you activate your fmri environment created from src/setup.sh
45
+ -cd /weka/proj-fmri/paulscotti/MindEyeV2/src
46
+ -source fmri/bin/activate
47
+ +cd /weka/proj-fmri/ckadirt/MindEyeV2/src
48
+ +source /admin/home-ckadirt/fmri/bin/activate
49
+
50
+ # The following line converts your jupyter notebook into a python script runnable with Slurm
51
+ -jupyter nbconvert Train.ipynb --to python
52
+ +jupyter nbconvert TrainCluster.ipynb --to python
53
+
54
+ export NUM_GPUS=1 # Set to equal gres=gpu:#!
55
+ export BATCH_SIZE=21 # 21 for multisubject / 24 for singlesubject (orig. paper used 42 for multisubject / 24 for singlesubject)
56
+ @@ -26,16 +26,16 @@ export GLOBAL_BATCH_SIZE=$((BATCH_SIZE * NUM_GPUS))
57
+ export MASTER_PORT=$((RANDOM % (19000 - 11000 + 1) + 11000))
58
+ export HOSTNAMES=$(scontrol show hostnames "$SLURM_JOB_NODELIST")
59
+ export MASTER_ADDR=$(scontrol show hostnames "$SLURM_JOB_NODELIST" | head -n 1)
60
+ -export COUNT_NODE=$(scontrol show hostnames "$SLURM_JOB_NODELIST" | wc -l)
61
+ +export COUNT_NODE=1 #$(scontrol show hostnames "$SLURM_JOB_NODELIST" | wc -l)
62
+ echo MASTER_ADDR=${MASTER_ADDR}
63
+ echo MASTER_PORT=${MASTER_PORT}
64
+ echo WORLD_SIZE=${COUNT_NODE}
65
+
66
+ # multisubject pretraining
67
+ -model_name="multisubject_excludingsubj01_40sess"
68
+ +model_name="rr-test"
69
+ echo model_name=${model_name}
70
+ -accelerate launch --num_processes=$(($NUM_GPUS * $COUNT_NODE)) --num_machines=$COUNT_NODE --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --mixed_precision=fp16 Train.py --data_path=/weka/proj-fmri/shared/mindeyev2_dataset --cache_dir=/weka/proj-fmri/shared/cache --model_name=${model_name} --multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --use_prior --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
71
+ -
72
+ +# accelerate launch --num_processes=$(($NUM_GPUS * $COUNT_NODE)) --num_machines=$COUNT_NODE --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --mixed_precision=fp16 TrainCluster.py --data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=${model_name} --multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
73
+ +python TrainCluster.py --data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=${model_name} --multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
74
+ # singlesubject finetuning
75
+ #model_name="finetuned_subj01_40sess"
76
+ #echo model_name=${model_name}
77
+ diff --git a/src/recon_inference.ipynb b/src/recon_inference.ipynb
78
+ index 10d7e27..0593e7e 100644
79
+ --- a/src/recon_inference.ipynb
80
+ +++ b/src/recon_inference.ipynb
81
+ @@ -12,7 +12,6 @@
82
+ "name": "stdout",
83
+ "output_type": "stream",
84
+ "text": [
85
+ - "LOCAL RANK 0\n",
86
+ "device: cuda\n"
87
+ ]
88
+ }
89
+ @@ -60,7 +59,7 @@
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ - "execution_count": 33,
94
+ + "execution_count": 2,
95
+ "id": "e52985b1-95ff-487b-8b2d-cc1ad1c190b8",
96
+ "metadata": {
97
+ "tags": []
98
+ @@ -71,9 +70,7 @@
99
+ "output_type": "stream",
100
+ "text": [
101
+ "model_name: final_subj01_pretrained_40sess_24bs\n",
102
+ - "--data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/mindeyev2_dataset --model_name=final_subj01_pretrained_40sess_24bs --subj=1 --hidden_dim=4096 --n_blocks=4 --new_test\n",
103
+ - "The autoreload extension is already loaded. To reload it, use:\n",
104
+ - " %reload_ext autoreload\n"
105
+ + "--data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/mindeyev2_dataset --model_name=final_subj01_pretrained_40sess_24bs --subj=1 --hidden_dim=4096 --n_blocks=4 --new_test\n"
106
+ ]
107
+ }
108
+ ],
109
+ @@ -99,7 +96,7 @@
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ - "execution_count": 34,
114
+ + "execution_count": 3,
115
+ "id": "49e5dae4-606d-4dc6-b420-df9e4c14737e",
116
+ "metadata": {
117
+ "tags": []
118
+ @@ -157,7 +154,7 @@
119
+ },
120
+ {
121
+ "cell_type": "code",
122
+ - "execution_count": 35,
123
+ + "execution_count": 4,
124
+ "id": "64672583-9f00-46f5-8d4e-00e4c7068a1d",
125
+ "metadata": {
126
+ "tags": []
127
+ @@ -221,7 +218,7 @@
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ - "execution_count": 36,
132
+ + "execution_count": 5,
133
+ "id": "a3cbeea8-e95b-48d9-9bc2-91af260c93d1",
134
+ "metadata": {},
135
+ "outputs": [
136
+ @@ -254,39 +251,10 @@
137
+ },
138
+ {
139
+ "cell_type": "code",
140
+ - "execution_count": 38,
141
+ + "execution_count": null,
142
+ "id": "3afc4858-b6a6-4a52-9303-b4a50ea5cc0b",
143
+ "metadata": {},
144
+ - "outputs": [
145
+ - {
146
+ - "name": "stdout",
147
+ - "output_type": "stream",
148
+ - "text": [
149
+ - "param counts:\n",
150
+ - "83,653,863 total\n",
151
+ - "0 trainable\n",
152
+ - "param counts:\n",
153
+ - "64,409,600 total\n",
154
+ - "64,409,600 trainable\n",
155
+ - "param counts:\n",
156
+ - "1,903,020,028 total\n",
157
+ - "1,903,020,028 trainable\n",
158
+ - "param counts:\n",
159
+ - "1,967,429,628 total\n",
160
+ - "1,967,429,628 trainable\n",
161
+ - "param counts:\n",
162
+ - "259,865,216 total\n",
163
+ - "259,865,200 trainable\n",
164
+ - "param counts:\n",
165
+ - "2,227,294,844 total\n",
166
+ - "2,227,294,828 trainable\n",
167
+ - "\n",
168
+ - "---loading /weka/proj-fmri/paulscotti/MindEye2_git/train_logs/final_subj01_pretrained_40sess_24bs/last.pth ckpt---\n",
169
+ - "\n",
170
+ - "ckpt loaded!\n"
171
+ - ]
172
+ - }
173
+ - ],
174
+ + "outputs": [],
175
+ "source": [
176
+ "clip_img_embedder = FrozenOpenCLIPImageEmbedder(\n",
177
+ " arch=\"ViT-bigG-14\",\n",
178
+ @@ -393,7 +361,7 @@
179
+ },
180
+ {
181
+ "cell_type": "code",
182
+ - "execution_count": 30,
183
+ + "execution_count": null,
184
+ "id": "295824db-ab3d-450c-90fb-f656e48994ba",
185
+ "metadata": {
186
+ "tags": []
187
+ @@ -430,38 +398,10 @@
188
+ },
189
+ {
190
+ "cell_type": "code",
191
+ - "execution_count": 31,
192
+ + "execution_count": null,
193
+ "id": "f726f617-39f5-49e2-8d0c-d11d27d01c30",
194
+ "metadata": {},
195
+ - "outputs": [
196
+ - {
197
+ - "name": "stderr",
198
+ - "output_type": "stream",
199
+ - "text": [
200
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
201
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
202
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
203
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
204
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
205
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
206
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
207
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
208
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
209
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
210
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n"
211
+ - ]
212
+ - },
213
+ - {
214
+ - "name": "stdout",
215
+ - "output_type": "stream",
216
+ - "text": [
217
+ - "Initialized embedder #0: FrozenOpenCLIPImageEmbedder with 1909889025 params. Trainable: False\n",
218
+ - "Initialized embedder #1: ConcatTimestepEmbedderND with 0 params. Trainable: False\n",
219
+ - "Initialized embedder #2: ConcatTimestepEmbedderND with 0 params. Trainable: False\n",
220
+ - "vector_suffix torch.Size([1, 1024])\n"
221
+ - ]
222
+ - }
223
+ - ],
224
+ + "outputs": [],
225
+ "source": [
226
+ "# prep unCLIP\n",
227
+ "config = OmegaConf.load(\"generative_models/configs/unclip6.yaml\")\n",
228
+ @@ -715,9 +655,9 @@
229
+ ],
230
+ "metadata": {
231
+ "kernelspec": {
232
+ - "display_name": "mindeye",
233
+ + "display_name": "Python 3 (ipykernel)",
234
+ "language": "python",
235
+ - "name": "mindeye"
236
+ + "name": "python3"
237
+ },
238
+ "language_info": {
239
+ "codemirror_mode": {
MindEyeV2/src/wandb/run-20240618_123614-testing/files/output.log ADDED
The diff for this file is too large to render. See raw diff
 
MindEyeV2/src/wandb/run-20240618_123614-testing/files/requirements.txt ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Babel==2.15.0
2
+ CoCa-pytorch==0.1.0
3
+ GitPython==3.1.43
4
+ Jinja2==3.1.4
5
+ MarkupSafe==2.1.5
6
+ PyYAML==6.0.1
7
+ Pygments==2.18.0
8
+ QtPy==2.4.1
9
+ Send2Trash==1.8.3
10
+ absl-py==2.1.0
11
+ accelerate==0.24.1
12
+ aiohttp==3.9.5
13
+ aiosignal==1.3.1
14
+ annotated-types==0.7.0
15
+ antlr4-python3-runtime==4.9.3
16
+ anyio==4.4.0
17
+ argon2-cffi-bindings==21.2.0
18
+ argon2-cffi==23.1.0
19
+ arrow==1.3.0
20
+ asttokens==2.4.1
21
+ async-lru==2.0.4
22
+ attrs==23.2.0
23
+ beartype==0.18.5
24
+ beautifulsoup4==4.12.3
25
+ bleach==6.1.0
26
+ braceexpand==0.1.7
27
+ certifi==2024.6.2
28
+ cffi==1.16.0
29
+ charset-normalizer==3.3.2
30
+ click==8.1.7
31
+ clip-anytorch==2.6.0
32
+ clip==1.0
33
+ comm==0.2.2
34
+ contourpy==1.2.1
35
+ cycler==0.12.1
36
+ dalle2-pytorch==1.15.6
37
+ datasets==2.20.0
38
+ debugpy==1.8.1
39
+ decorator==5.1.1
40
+ deepspeed==0.13.1
41
+ defusedxml==0.7.1
42
+ diffusers==0.23.0
43
+ dill==0.3.8
44
+ docker-pycreds==0.4.0
45
+ einops==0.8.0
46
+ einx==0.3.0
47
+ ema-pytorch==0.5.0
48
+ embedding-reader==1.7.0
49
+ evaluate==0.4.1
50
+ executing==2.0.1
51
+ fastjsonschema==2.20.0
52
+ filelock==3.15.1
53
+ fonttools==4.53.0
54
+ fqdn==1.5.1
55
+ frozendict==2.4.4
56
+ frozenlist==1.4.1
57
+ fsspec==2024.5.0
58
+ ftfy==6.2.0
59
+ gitdb==4.0.11
60
+ h11==0.14.0
61
+ h5py==3.10.0
62
+ hjson==3.1.0
63
+ httpcore==1.0.5
64
+ httpx==0.27.0
65
+ huggingface-hub==0.23.4
66
+ idna==3.7
67
+ imageio==2.34.1
68
+ importlib_metadata==7.1.0
69
+ ipykernel==6.29.4
70
+ ipython==8.25.0
71
+ ipywidgets==8.1.3
72
+ isoduration==20.11.0
73
+ jedi==0.19.1
74
+ joblib==1.4.2
75
+ json5==0.9.25
76
+ jsonpointer==3.0.0
77
+ jsonschema-specifications==2023.12.1
78
+ jsonschema==4.22.0
79
+ jupyter-console==6.6.3
80
+ jupyter-events==0.10.0
81
+ jupyter-lsp==2.2.5
82
+ jupyter==1.0.0
83
+ jupyter_client==8.6.2
84
+ jupyter_core==5.7.2
85
+ jupyter_server==2.14.1
86
+ jupyter_server_terminals==0.5.3
87
+ jupyterlab==4.2.2
88
+ jupyterlab_nvdashboard==0.11.0
89
+ jupyterlab_pygments==0.3.0
90
+ jupyterlab_server==2.27.2
91
+ jupyterlab_widgets==3.0.11
92
+ kiwisolver==1.4.5
93
+ kornia==0.7.1
94
+ lazy_loader==0.4
95
+ lightning-utilities==0.11.2
96
+ matplotlib-inline==0.1.7
97
+ matplotlib==3.8.2
98
+ mistune==3.0.2
99
+ mpmath==1.3.0
100
+ multidict==6.0.5
101
+ multiprocess==0.70.16
102
+ nbclient==0.10.0
103
+ nbconvert==7.16.4
104
+ nbformat==5.10.4
105
+ nest-asyncio==1.6.0
106
+ networkx==3.3
107
+ ninja==1.11.1.1
108
+ nltk==3.8.1
109
+ notebook==7.2.1
110
+ notebook_shim==0.2.4
111
+ numpy==1.26.4
112
+ nvidia-cublas-cu12==12.1.3.1
113
+ nvidia-cuda-cupti-cu12==12.1.105
114
+ nvidia-cuda-nvrtc-cu12==12.1.105
115
+ nvidia-cuda-runtime-cu12==12.1.105
116
+ nvidia-cudnn-cu12==8.9.2.26
117
+ nvidia-cufft-cu12==11.0.2.54
118
+ nvidia-curand-cu12==10.3.2.106
119
+ nvidia-cusolver-cu12==11.4.5.107
120
+ nvidia-cusparse-cu12==12.1.0.106
121
+ nvidia-nccl-cu12==2.18.1
122
+ nvidia-nvjitlink-cu12==12.5.40
123
+ nvidia-nvtx-cu12==12.1.105
124
+ omegaconf==2.3.0
125
+ open-clip-torch==2.24.0
126
+ overrides==7.7.0
127
+ packaging==24.1
128
+ pandas==2.2.0
129
+ pandocfilters==1.5.1
130
+ parso==0.8.4
131
+ pexpect==4.9.0
132
+ pillow==10.3.0
133
+ pip==24.0
134
+ platformdirs==4.2.2
135
+ prometheus_client==0.20.0
136
+ prompt_toolkit==3.0.47
137
+ protobuf==5.27.1
138
+ psutil==5.9.8
139
+ ptyprocess==0.7.0
140
+ pure-eval==0.2.2
141
+ py-cpuinfo==9.0.0
142
+ pyarrow-hotfix==0.6
143
+ pyarrow==15.0.2
144
+ pycparser==2.22
145
+ pydantic==2.7.4
146
+ pydantic_core==2.18.4
147
+ pynvml==11.5.0
148
+ pyparsing==3.1.2
149
+ python-dateutil==2.9.0.post0
150
+ python-json-logger==2.0.7
151
+ pytorch-lightning==2.0.1
152
+ pytorch-warmup==0.1.1
153
+ pytz==2024.1
154
+ pyzmq==26.0.3
155
+ qtconsole==5.5.2
156
+ referencing==0.35.1
157
+ regex==2024.5.15
158
+ requests==2.32.3
159
+ resize-right==0.0.2
160
+ responses==0.18.0
161
+ rfc3339-validator==0.1.4
162
+ rfc3986-validator==0.1.1
163
+ rotary-embedding-torch==0.6.2
164
+ rouge_score==0.1.2
165
+ rpds-py==0.18.1
166
+ safetensors==0.4.3
167
+ scikit-image==0.22.0
168
+ scikit-learn==1.5.0
169
+ scipy==1.13.1
170
+ sentence-transformers==2.5.1
171
+ sentencepiece==0.2.0
172
+ sentry-sdk==2.5.1
173
+ setproctitle==1.3.3
174
+ setuptools==65.5.0
175
+ six==1.16.0
176
+ smmap==5.0.1
177
+ sniffio==1.3.1
178
+ soupsieve==2.5
179
+ stack-data==0.6.3
180
+ sympy==1.12.1
181
+ terminado==0.18.1
182
+ threadpoolctl==3.5.0
183
+ tifffile==2024.5.22
184
+ timm==1.0.3
185
+ tinycss2==1.3.0
186
+ tokenizers==0.15.2
187
+ torch-fidelity==0.3.0
188
+ torch==2.1.0
189
+ torchmetrics==1.3.0.post0
190
+ torchvision==0.16.0
191
+ tornado==6.4.1
192
+ tqdm==4.66.4
193
+ traitlets==5.14.3
194
+ transformers==4.37.2
195
+ triton==2.1.0
196
+ types-python-dateutil==2.9.0.20240316
197
+ typing_extensions==4.12.2
198
+ tzdata==2024.1
199
+ umap==0.1.1
200
+ uri-template==1.3.0
201
+ urllib3==2.2.1
202
+ vector-quantize-pytorch==1.14.24
203
+ wandb==0.17.1
204
+ wcwidth==0.2.13
205
+ webcolors==24.6.0
206
+ webdataset==0.2.73
207
+ webencodings==0.5.1
208
+ websocket-client==1.8.0
209
+ widgetsnbextension==4.0.11
210
+ x-clip==0.14.4
211
+ xformers==0.0.22.post7
212
+ xxhash==3.4.1
213
+ yarl==1.9.4
214
+ zipp==3.19.2
MindEyeV2/src/wandb/run-20240618_123614-testing/files/wandb-metadata.json ADDED
@@ -0,0 +1,1035 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "os": "Linux-5.15.0-1058-aws-x86_64-with-glibc2.31",
3
+ "python": "3.11.9",
4
+ "heartbeatAt": "2024-06-18T12:36:15.404626",
5
+ "startedAt": "2024-06-18T12:36:14.302258",
6
+ "docker": null,
7
+ "cuda": null,
8
+ "args": [],
9
+ "state": "running",
10
+ "program": "ckadirt/MindEyeV2/src/TrainCluster.ipynb",
11
+ "codePathLocal": null,
12
+ "root": "/weka/proj-fmri/ckadirt/MindEyeV2",
13
+ "git": {
14
+ "remote": "https://github.com/MedARC-AI/MindEyeV2.git",
15
+ "commit": "a3588f0fadc81bdb0cc3e15993c01f8dd64dc7fe"
16
+ },
17
+ "email": null,
18
+ "host": "ip-10-0-149-152",
19
+ "username": "ckadirt",
20
+ "executable": "/admin/home-ckadirt/fmri/bin/python3.11",
21
+ "cpu_count": 96,
22
+ "cpu_count_logical": 192,
23
+ "cpu_freq": {
24
+ "current": 2710.1276875,
25
+ "min": 0.0,
26
+ "max": 0.0
27
+ },
28
+ "cpu_freq_per_core": [
29
+ {
30
+ "current": 2925.786,
31
+ "min": 0.0,
32
+ "max": 0.0
33
+ },
34
+ {
35
+ "current": 2650.0,
36
+ "min": 0.0,
37
+ "max": 0.0
38
+ },
39
+ {
40
+ "current": 2650.0,
41
+ "min": 0.0,
42
+ "max": 0.0
43
+ },
44
+ {
45
+ "current": 2650.0,
46
+ "min": 0.0,
47
+ "max": 0.0
48
+ },
49
+ {
50
+ "current": 2650.0,
51
+ "min": 0.0,
52
+ "max": 0.0
53
+ },
54
+ {
55
+ "current": 2650.0,
56
+ "min": 0.0,
57
+ "max": 0.0
58
+ },
59
+ {
60
+ "current": 2650.0,
61
+ "min": 0.0,
62
+ "max": 0.0
63
+ },
64
+ {
65
+ "current": 2650.0,
66
+ "min": 0.0,
67
+ "max": 0.0
68
+ },
69
+ {
70
+ "current": 2650.0,
71
+ "min": 0.0,
72
+ "max": 0.0
73
+ },
74
+ {
75
+ "current": 2650.0,
76
+ "min": 0.0,
77
+ "max": 0.0
78
+ },
79
+ {
80
+ "current": 2650.0,
81
+ "min": 0.0,
82
+ "max": 0.0
83
+ },
84
+ {
85
+ "current": 2650.0,
86
+ "min": 0.0,
87
+ "max": 0.0
88
+ },
89
+ {
90
+ "current": 2650.0,
91
+ "min": 0.0,
92
+ "max": 0.0
93
+ },
94
+ {
95
+ "current": 2650.0,
96
+ "min": 0.0,
97
+ "max": 0.0
98
+ },
99
+ {
100
+ "current": 2650.0,
101
+ "min": 0.0,
102
+ "max": 0.0
103
+ },
104
+ {
105
+ "current": 2650.0,
106
+ "min": 0.0,
107
+ "max": 0.0
108
+ },
109
+ {
110
+ "current": 2650.0,
111
+ "min": 0.0,
112
+ "max": 0.0
113
+ },
114
+ {
115
+ "current": 2650.0,
116
+ "min": 0.0,
117
+ "max": 0.0
118
+ },
119
+ {
120
+ "current": 2650.0,
121
+ "min": 0.0,
122
+ "max": 0.0
123
+ },
124
+ {
125
+ "current": 2650.0,
126
+ "min": 0.0,
127
+ "max": 0.0
128
+ },
129
+ {
130
+ "current": 2650.0,
131
+ "min": 0.0,
132
+ "max": 0.0
133
+ },
134
+ {
135
+ "current": 2650.0,
136
+ "min": 0.0,
137
+ "max": 0.0
138
+ },
139
+ {
140
+ "current": 2650.0,
141
+ "min": 0.0,
142
+ "max": 0.0
143
+ },
144
+ {
145
+ "current": 2650.0,
146
+ "min": 0.0,
147
+ "max": 0.0
148
+ },
149
+ {
150
+ "current": 2650.0,
151
+ "min": 0.0,
152
+ "max": 0.0
153
+ },
154
+ {
155
+ "current": 2650.0,
156
+ "min": 0.0,
157
+ "max": 0.0
158
+ },
159
+ {
160
+ "current": 2650.0,
161
+ "min": 0.0,
162
+ "max": 0.0
163
+ },
164
+ {
165
+ "current": 2650.0,
166
+ "min": 0.0,
167
+ "max": 0.0
168
+ },
169
+ {
170
+ "current": 2650.0,
171
+ "min": 0.0,
172
+ "max": 0.0
173
+ },
174
+ {
175
+ "current": 2650.0,
176
+ "min": 0.0,
177
+ "max": 0.0
178
+ },
179
+ {
180
+ "current": 2650.0,
181
+ "min": 0.0,
182
+ "max": 0.0
183
+ },
184
+ {
185
+ "current": 2650.0,
186
+ "min": 0.0,
187
+ "max": 0.0
188
+ },
189
+ {
190
+ "current": 2650.0,
191
+ "min": 0.0,
192
+ "max": 0.0
193
+ },
194
+ {
195
+ "current": 2650.0,
196
+ "min": 0.0,
197
+ "max": 0.0
198
+ },
199
+ {
200
+ "current": 2650.0,
201
+ "min": 0.0,
202
+ "max": 0.0
203
+ },
204
+ {
205
+ "current": 2650.0,
206
+ "min": 0.0,
207
+ "max": 0.0
208
+ },
209
+ {
210
+ "current": 2650.0,
211
+ "min": 0.0,
212
+ "max": 0.0
213
+ },
214
+ {
215
+ "current": 2650.0,
216
+ "min": 0.0,
217
+ "max": 0.0
218
+ },
219
+ {
220
+ "current": 2650.0,
221
+ "min": 0.0,
222
+ "max": 0.0
223
+ },
224
+ {
225
+ "current": 2650.0,
226
+ "min": 0.0,
227
+ "max": 0.0
228
+ },
229
+ {
230
+ "current": 2650.0,
231
+ "min": 0.0,
232
+ "max": 0.0
233
+ },
234
+ {
235
+ "current": 2650.0,
236
+ "min": 0.0,
237
+ "max": 0.0
238
+ },
239
+ {
240
+ "current": 2650.0,
241
+ "min": 0.0,
242
+ "max": 0.0
243
+ },
244
+ {
245
+ "current": 2650.0,
246
+ "min": 0.0,
247
+ "max": 0.0
248
+ },
249
+ {
250
+ "current": 3596.327,
251
+ "min": 0.0,
252
+ "max": 0.0
253
+ },
254
+ {
255
+ "current": 3597.513,
256
+ "min": 0.0,
257
+ "max": 0.0
258
+ },
259
+ {
260
+ "current": 3599.095,
261
+ "min": 0.0,
262
+ "max": 0.0
263
+ },
264
+ {
265
+ "current": 3597.548,
266
+ "min": 0.0,
267
+ "max": 0.0
268
+ },
269
+ {
270
+ "current": 3598.825,
271
+ "min": 0.0,
272
+ "max": 0.0
273
+ },
274
+ {
275
+ "current": 3597.706,
276
+ "min": 0.0,
277
+ "max": 0.0
278
+ },
279
+ {
280
+ "current": 3599.237,
281
+ "min": 0.0,
282
+ "max": 0.0
283
+ },
284
+ {
285
+ "current": 3597.748,
286
+ "min": 0.0,
287
+ "max": 0.0
288
+ },
289
+ {
290
+ "current": 2650.0,
291
+ "min": 0.0,
292
+ "max": 0.0
293
+ },
294
+ {
295
+ "current": 2650.0,
296
+ "min": 0.0,
297
+ "max": 0.0
298
+ },
299
+ {
300
+ "current": 2650.0,
301
+ "min": 0.0,
302
+ "max": 0.0
303
+ },
304
+ {
305
+ "current": 2650.0,
306
+ "min": 0.0,
307
+ "max": 0.0
308
+ },
309
+ {
310
+ "current": 2650.0,
311
+ "min": 0.0,
312
+ "max": 0.0
313
+ },
314
+ {
315
+ "current": 2650.0,
316
+ "min": 0.0,
317
+ "max": 0.0
318
+ },
319
+ {
320
+ "current": 3587.835,
321
+ "min": 0.0,
322
+ "max": 0.0
323
+ },
324
+ {
325
+ "current": 3597.601,
326
+ "min": 0.0,
327
+ "max": 0.0
328
+ },
329
+ {
330
+ "current": 2650.0,
331
+ "min": 0.0,
332
+ "max": 0.0
333
+ },
334
+ {
335
+ "current": 2650.0,
336
+ "min": 0.0,
337
+ "max": 0.0
338
+ },
339
+ {
340
+ "current": 2650.0,
341
+ "min": 0.0,
342
+ "max": 0.0
343
+ },
344
+ {
345
+ "current": 2650.0,
346
+ "min": 0.0,
347
+ "max": 0.0
348
+ },
349
+ {
350
+ "current": 2650.0,
351
+ "min": 0.0,
352
+ "max": 0.0
353
+ },
354
+ {
355
+ "current": 2650.0,
356
+ "min": 0.0,
357
+ "max": 0.0
358
+ },
359
+ {
360
+ "current": 2650.0,
361
+ "min": 0.0,
362
+ "max": 0.0
363
+ },
364
+ {
365
+ "current": 2650.0,
366
+ "min": 0.0,
367
+ "max": 0.0
368
+ },
369
+ {
370
+ "current": 2650.0,
371
+ "min": 0.0,
372
+ "max": 0.0
373
+ },
374
+ {
375
+ "current": 2650.0,
376
+ "min": 0.0,
377
+ "max": 0.0
378
+ },
379
+ {
380
+ "current": 2650.0,
381
+ "min": 0.0,
382
+ "max": 0.0
383
+ },
384
+ {
385
+ "current": 2650.0,
386
+ "min": 0.0,
387
+ "max": 0.0
388
+ },
389
+ {
390
+ "current": 2650.0,
391
+ "min": 0.0,
392
+ "max": 0.0
393
+ },
394
+ {
395
+ "current": 2650.0,
396
+ "min": 0.0,
397
+ "max": 0.0
398
+ },
399
+ {
400
+ "current": 2650.0,
401
+ "min": 0.0,
402
+ "max": 0.0
403
+ },
404
+ {
405
+ "current": 2650.0,
406
+ "min": 0.0,
407
+ "max": 0.0
408
+ },
409
+ {
410
+ "current": 2650.0,
411
+ "min": 0.0,
412
+ "max": 0.0
413
+ },
414
+ {
415
+ "current": 2650.0,
416
+ "min": 0.0,
417
+ "max": 0.0
418
+ },
419
+ {
420
+ "current": 2650.0,
421
+ "min": 0.0,
422
+ "max": 0.0
423
+ },
424
+ {
425
+ "current": 2650.0,
426
+ "min": 0.0,
427
+ "max": 0.0
428
+ },
429
+ {
430
+ "current": 2650.0,
431
+ "min": 0.0,
432
+ "max": 0.0
433
+ },
434
+ {
435
+ "current": 2650.0,
436
+ "min": 0.0,
437
+ "max": 0.0
438
+ },
439
+ {
440
+ "current": 2650.0,
441
+ "min": 0.0,
442
+ "max": 0.0
443
+ },
444
+ {
445
+ "current": 2650.0,
446
+ "min": 0.0,
447
+ "max": 0.0
448
+ },
449
+ {
450
+ "current": 2650.0,
451
+ "min": 0.0,
452
+ "max": 0.0
453
+ },
454
+ {
455
+ "current": 2650.0,
456
+ "min": 0.0,
457
+ "max": 0.0
458
+ },
459
+ {
460
+ "current": 2650.0,
461
+ "min": 0.0,
462
+ "max": 0.0
463
+ },
464
+ {
465
+ "current": 2650.0,
466
+ "min": 0.0,
467
+ "max": 0.0
468
+ },
469
+ {
470
+ "current": 2650.0,
471
+ "min": 0.0,
472
+ "max": 0.0
473
+ },
474
+ {
475
+ "current": 2650.0,
476
+ "min": 0.0,
477
+ "max": 0.0
478
+ },
479
+ {
480
+ "current": 2650.0,
481
+ "min": 0.0,
482
+ "max": 0.0
483
+ },
484
+ {
485
+ "current": 2650.0,
486
+ "min": 0.0,
487
+ "max": 0.0
488
+ },
489
+ {
490
+ "current": 2650.0,
491
+ "min": 0.0,
492
+ "max": 0.0
493
+ },
494
+ {
495
+ "current": 2650.0,
496
+ "min": 0.0,
497
+ "max": 0.0
498
+ },
499
+ {
500
+ "current": 2650.0,
501
+ "min": 0.0,
502
+ "max": 0.0
503
+ },
504
+ {
505
+ "current": 2650.0,
506
+ "min": 0.0,
507
+ "max": 0.0
508
+ },
509
+ {
510
+ "current": 2650.0,
511
+ "min": 0.0,
512
+ "max": 0.0
513
+ },
514
+ {
515
+ "current": 2650.0,
516
+ "min": 0.0,
517
+ "max": 0.0
518
+ },
519
+ {
520
+ "current": 2650.0,
521
+ "min": 0.0,
522
+ "max": 0.0
523
+ },
524
+ {
525
+ "current": 2650.0,
526
+ "min": 0.0,
527
+ "max": 0.0
528
+ },
529
+ {
530
+ "current": 2650.0,
531
+ "min": 0.0,
532
+ "max": 0.0
533
+ },
534
+ {
535
+ "current": 2650.0,
536
+ "min": 0.0,
537
+ "max": 0.0
538
+ },
539
+ {
540
+ "current": 2650.0,
541
+ "min": 0.0,
542
+ "max": 0.0
543
+ },
544
+ {
545
+ "current": 2650.0,
546
+ "min": 0.0,
547
+ "max": 0.0
548
+ },
549
+ {
550
+ "current": 2650.0,
551
+ "min": 0.0,
552
+ "max": 0.0
553
+ },
554
+ {
555
+ "current": 2650.0,
556
+ "min": 0.0,
557
+ "max": 0.0
558
+ },
559
+ {
560
+ "current": 2650.0,
561
+ "min": 0.0,
562
+ "max": 0.0
563
+ },
564
+ {
565
+ "current": 2650.0,
566
+ "min": 0.0,
567
+ "max": 0.0
568
+ },
569
+ {
570
+ "current": 2650.0,
571
+ "min": 0.0,
572
+ "max": 0.0
573
+ },
574
+ {
575
+ "current": 2650.0,
576
+ "min": 0.0,
577
+ "max": 0.0
578
+ },
579
+ {
580
+ "current": 2650.0,
581
+ "min": 0.0,
582
+ "max": 0.0
583
+ },
584
+ {
585
+ "current": 2650.0,
586
+ "min": 0.0,
587
+ "max": 0.0
588
+ },
589
+ {
590
+ "current": 2650.0,
591
+ "min": 0.0,
592
+ "max": 0.0
593
+ },
594
+ {
595
+ "current": 2650.0,
596
+ "min": 0.0,
597
+ "max": 0.0
598
+ },
599
+ {
600
+ "current": 3595.424,
601
+ "min": 0.0,
602
+ "max": 0.0
603
+ },
604
+ {
605
+ "current": 2650.0,
606
+ "min": 0.0,
607
+ "max": 0.0
608
+ },
609
+ {
610
+ "current": 2650.0,
611
+ "min": 0.0,
612
+ "max": 0.0
613
+ },
614
+ {
615
+ "current": 2650.0,
616
+ "min": 0.0,
617
+ "max": 0.0
618
+ },
619
+ {
620
+ "current": 2650.0,
621
+ "min": 0.0,
622
+ "max": 0.0
623
+ },
624
+ {
625
+ "current": 2650.0,
626
+ "min": 0.0,
627
+ "max": 0.0
628
+ },
629
+ {
630
+ "current": 2650.0,
631
+ "min": 0.0,
632
+ "max": 0.0
633
+ },
634
+ {
635
+ "current": 2650.0,
636
+ "min": 0.0,
637
+ "max": 0.0
638
+ },
639
+ {
640
+ "current": 2650.0,
641
+ "min": 0.0,
642
+ "max": 0.0
643
+ },
644
+ {
645
+ "current": 2650.0,
646
+ "min": 0.0,
647
+ "max": 0.0
648
+ },
649
+ {
650
+ "current": 2650.0,
651
+ "min": 0.0,
652
+ "max": 0.0
653
+ },
654
+ {
655
+ "current": 2650.0,
656
+ "min": 0.0,
657
+ "max": 0.0
658
+ },
659
+ {
660
+ "current": 2650.0,
661
+ "min": 0.0,
662
+ "max": 0.0
663
+ },
664
+ {
665
+ "current": 2650.0,
666
+ "min": 0.0,
667
+ "max": 0.0
668
+ },
669
+ {
670
+ "current": 2650.0,
671
+ "min": 0.0,
672
+ "max": 0.0
673
+ },
674
+ {
675
+ "current": 2650.0,
676
+ "min": 0.0,
677
+ "max": 0.0
678
+ },
679
+ {
680
+ "current": 2650.0,
681
+ "min": 0.0,
682
+ "max": 0.0
683
+ },
684
+ {
685
+ "current": 2650.0,
686
+ "min": 0.0,
687
+ "max": 0.0
688
+ },
689
+ {
690
+ "current": 2650.0,
691
+ "min": 0.0,
692
+ "max": 0.0
693
+ },
694
+ {
695
+ "current": 2650.0,
696
+ "min": 0.0,
697
+ "max": 0.0
698
+ },
699
+ {
700
+ "current": 2650.0,
701
+ "min": 0.0,
702
+ "max": 0.0
703
+ },
704
+ {
705
+ "current": 2650.0,
706
+ "min": 0.0,
707
+ "max": 0.0
708
+ },
709
+ {
710
+ "current": 2650.0,
711
+ "min": 0.0,
712
+ "max": 0.0
713
+ },
714
+ {
715
+ "current": 2650.0,
716
+ "min": 0.0,
717
+ "max": 0.0
718
+ },
719
+ {
720
+ "current": 2650.0,
721
+ "min": 0.0,
722
+ "max": 0.0
723
+ },
724
+ {
725
+ "current": 2650.0,
726
+ "min": 0.0,
727
+ "max": 0.0
728
+ },
729
+ {
730
+ "current": 2650.0,
731
+ "min": 0.0,
732
+ "max": 0.0
733
+ },
734
+ {
735
+ "current": 2650.0,
736
+ "min": 0.0,
737
+ "max": 0.0
738
+ },
739
+ {
740
+ "current": 2650.0,
741
+ "min": 0.0,
742
+ "max": 0.0
743
+ },
744
+ {
745
+ "current": 2650.0,
746
+ "min": 0.0,
747
+ "max": 0.0
748
+ },
749
+ {
750
+ "current": 2650.0,
751
+ "min": 0.0,
752
+ "max": 0.0
753
+ },
754
+ {
755
+ "current": 2650.0,
756
+ "min": 0.0,
757
+ "max": 0.0
758
+ },
759
+ {
760
+ "current": 2650.0,
761
+ "min": 0.0,
762
+ "max": 0.0
763
+ },
764
+ {
765
+ "current": 2650.0,
766
+ "min": 0.0,
767
+ "max": 0.0
768
+ },
769
+ {
770
+ "current": 2650.0,
771
+ "min": 0.0,
772
+ "max": 0.0
773
+ },
774
+ {
775
+ "current": 2650.0,
776
+ "min": 0.0,
777
+ "max": 0.0
778
+ },
779
+ {
780
+ "current": 2650.0,
781
+ "min": 0.0,
782
+ "max": 0.0
783
+ },
784
+ {
785
+ "current": 2650.0,
786
+ "min": 0.0,
787
+ "max": 0.0
788
+ },
789
+ {
790
+ "current": 2650.0,
791
+ "min": 0.0,
792
+ "max": 0.0
793
+ },
794
+ {
795
+ "current": 2650.0,
796
+ "min": 0.0,
797
+ "max": 0.0
798
+ },
799
+ {
800
+ "current": 2650.0,
801
+ "min": 0.0,
802
+ "max": 0.0
803
+ },
804
+ {
805
+ "current": 2650.0,
806
+ "min": 0.0,
807
+ "max": 0.0
808
+ },
809
+ {
810
+ "current": 2650.0,
811
+ "min": 0.0,
812
+ "max": 0.0
813
+ },
814
+ {
815
+ "current": 2650.0,
816
+ "min": 0.0,
817
+ "max": 0.0
818
+ },
819
+ {
820
+ "current": 2650.0,
821
+ "min": 0.0,
822
+ "max": 0.0
823
+ },
824
+ {
825
+ "current": 2650.0,
826
+ "min": 0.0,
827
+ "max": 0.0
828
+ },
829
+ {
830
+ "current": 2650.0,
831
+ "min": 0.0,
832
+ "max": 0.0
833
+ },
834
+ {
835
+ "current": 2650.0,
836
+ "min": 0.0,
837
+ "max": 0.0
838
+ },
839
+ {
840
+ "current": 2650.0,
841
+ "min": 0.0,
842
+ "max": 0.0
843
+ },
844
+ {
845
+ "current": 2650.0,
846
+ "min": 0.0,
847
+ "max": 0.0
848
+ },
849
+ {
850
+ "current": 2650.0,
851
+ "min": 0.0,
852
+ "max": 0.0
853
+ },
854
+ {
855
+ "current": 2650.0,
856
+ "min": 0.0,
857
+ "max": 0.0
858
+ },
859
+ {
860
+ "current": 2650.0,
861
+ "min": 0.0,
862
+ "max": 0.0
863
+ },
864
+ {
865
+ "current": 2650.0,
866
+ "min": 0.0,
867
+ "max": 0.0
868
+ },
869
+ {
870
+ "current": 2650.0,
871
+ "min": 0.0,
872
+ "max": 0.0
873
+ },
874
+ {
875
+ "current": 2650.0,
876
+ "min": 0.0,
877
+ "max": 0.0
878
+ },
879
+ {
880
+ "current": 2650.0,
881
+ "min": 0.0,
882
+ "max": 0.0
883
+ },
884
+ {
885
+ "current": 2650.0,
886
+ "min": 0.0,
887
+ "max": 0.0
888
+ },
889
+ {
890
+ "current": 2650.0,
891
+ "min": 0.0,
892
+ "max": 0.0
893
+ },
894
+ {
895
+ "current": 2650.0,
896
+ "min": 0.0,
897
+ "max": 0.0
898
+ },
899
+ {
900
+ "current": 2650.0,
901
+ "min": 0.0,
902
+ "max": 0.0
903
+ },
904
+ {
905
+ "current": 2650.0,
906
+ "min": 0.0,
907
+ "max": 0.0
908
+ },
909
+ {
910
+ "current": 2650.0,
911
+ "min": 0.0,
912
+ "max": 0.0
913
+ },
914
+ {
915
+ "current": 2650.0,
916
+ "min": 0.0,
917
+ "max": 0.0
918
+ },
919
+ {
920
+ "current": 2650.0,
921
+ "min": 0.0,
922
+ "max": 0.0
923
+ },
924
+ {
925
+ "current": 2650.0,
926
+ "min": 0.0,
927
+ "max": 0.0
928
+ },
929
+ {
930
+ "current": 2650.0,
931
+ "min": 0.0,
932
+ "max": 0.0
933
+ },
934
+ {
935
+ "current": 3597.911,
936
+ "min": 0.0,
937
+ "max": 0.0
938
+ },
939
+ {
940
+ "current": 2650.0,
941
+ "min": 0.0,
942
+ "max": 0.0
943
+ },
944
+ {
945
+ "current": 2650.0,
946
+ "min": 0.0,
947
+ "max": 0.0
948
+ },
949
+ {
950
+ "current": 2650.0,
951
+ "min": 0.0,
952
+ "max": 0.0
953
+ },
954
+ {
955
+ "current": 2650.0,
956
+ "min": 0.0,
957
+ "max": 0.0
958
+ },
959
+ {
960
+ "current": 2650.0,
961
+ "min": 0.0,
962
+ "max": 0.0
963
+ },
964
+ {
965
+ "current": 2650.0,
966
+ "min": 0.0,
967
+ "max": 0.0
968
+ },
969
+ {
970
+ "current": 2650.0,
971
+ "min": 0.0,
972
+ "max": 0.0
973
+ },
974
+ {
975
+ "current": 2650.0,
976
+ "min": 0.0,
977
+ "max": 0.0
978
+ },
979
+ {
980
+ "current": 2650.0,
981
+ "min": 0.0,
982
+ "max": 0.0
983
+ },
984
+ {
985
+ "current": 2650.0,
986
+ "min": 0.0,
987
+ "max": 0.0
988
+ }
989
+ ],
990
+ "disk": {
991
+ "/": {
992
+ "total": 232.4169158935547,
993
+ "used": 181.67956161499023
994
+ }
995
+ },
996
+ "gpu": "NVIDIA H100 80GB HBM3",
997
+ "gpu_count": 8,
998
+ "gpu_devices": [
999
+ {
1000
+ "name": "NVIDIA H100 80GB HBM3",
1001
+ "memory_total": 85520809984
1002
+ },
1003
+ {
1004
+ "name": "NVIDIA H100 80GB HBM3",
1005
+ "memory_total": 85520809984
1006
+ },
1007
+ {
1008
+ "name": "NVIDIA H100 80GB HBM3",
1009
+ "memory_total": 85520809984
1010
+ },
1011
+ {
1012
+ "name": "NVIDIA H100 80GB HBM3",
1013
+ "memory_total": 85520809984
1014
+ },
1015
+ {
1016
+ "name": "NVIDIA H100 80GB HBM3",
1017
+ "memory_total": 85520809984
1018
+ },
1019
+ {
1020
+ "name": "NVIDIA H100 80GB HBM3",
1021
+ "memory_total": 85520809984
1022
+ },
1023
+ {
1024
+ "name": "NVIDIA H100 80GB HBM3",
1025
+ "memory_total": 85520809984
1026
+ },
1027
+ {
1028
+ "name": "NVIDIA H100 80GB HBM3",
1029
+ "memory_total": 85520809984
1030
+ }
1031
+ ],
1032
+ "memory": {
1033
+ "total": 1999.9625205993652
1034
+ }
1035
+ }
MindEyeV2/src/wandb/run-20240618_123614-testing/files/wandb-summary.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"train/loss": 149.35307167663575, "test/loss": 1460.2626953125, "train/lr": 0.0002978457718582204, "train/num_steps": 37500, "test/num_steps": 10, "train/fwd_pct_correct": 0.6664333333333333, "train/bwd_pct_correct": 0.6865, "test/test_fwd_pct_correct": 0.5600000023841858, "test/test_bwd_pct_correct": 0.5333333611488342, "train/loss_clip_total": 0.5423962022828559, "train/loss_blurry_total": 0.0, "train/loss_blurry_cont_total": 0.0, "test/loss_clip_total": 2.158545970916748, "train/blurry_pixcorr": 0.0, "test/blurry_pixcorr": 0.0, "train/recon_cossim": 0.0, "test/recon_cossim": 0.0, "train/recon_mse": 0.0, "test/recon_mse": 0.0, "train/loss_prior": 0.0, "test/loss_prior": 0.0, "train/loss_RR": 148.81067535298666, "test/loss_RR": 1458.1041259765625, "_timestamp": 1718717027.775746, "_runtime": 2853.353439092636, "_step": 9, "_wandb": {"runtime": 3000}}
MindEyeV2/src/wandb/run-20240618_123614-testing/logs/debug-internal.log ADDED
The diff for this file is too large to render. See raw diff
 
MindEyeV2/src/wandb/run-20240618_123614-testing/logs/debug.log ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2024-06-18 12:36:14,405 INFO MainThread:448378 [wandb_setup.py:_flush():76] Current SDK version is 0.17.1
2
+ 2024-06-18 12:36:14,406 INFO MainThread:448378 [wandb_setup.py:_flush():76] Configure stats pid to 448378
3
+ 2024-06-18 12:36:14,406 INFO MainThread:448378 [wandb_setup.py:_flush():76] Loading settings from /admin/home-ckadirt/.config/wandb/settings
4
+ 2024-06-18 12:36:14,406 INFO MainThread:448378 [wandb_setup.py:_flush():76] Loading settings from /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/settings
5
+ 2024-06-18 12:36:14,406 INFO MainThread:448378 [wandb_setup.py:_flush():76] Loading settings from environment variables: {}
6
+ 2024-06-18 12:36:14,406 INFO MainThread:448378 [wandb_setup.py:_flush():76] Inferring run settings from compute environment: {'program': '<python with no main file>'}
7
+ 2024-06-18 12:36:14,406 INFO MainThread:448378 [wandb_setup.py:_flush():76] Applying login settings: {'base_url': 'https://stability.wandb.io'}
8
+ 2024-06-18 12:36:14,406 INFO MainThread:448378 [wandb_setup.py:_flush():76] Applying login settings: {}
9
+ 2024-06-18 12:36:14,407 INFO MainThread:448378 [wandb_init.py:_log_setup():520] Logging user logs to /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_123614-testing/logs/debug.log
10
+ 2024-06-18 12:36:14,407 INFO MainThread:448378 [wandb_init.py:_log_setup():521] Logging internal logs to /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_123614-testing/logs/debug-internal.log
11
+ 2024-06-18 12:36:14,407 INFO MainThread:448378 [wandb_init.py:_jupyter_setup():466] configuring jupyter hooks <wandb.sdk.wandb_init._WandbInit object at 0x7f13c50a0390>
12
+ 2024-06-18 12:36:14,407 INFO MainThread:448378 [wandb_init.py:init():560] calling init triggers
13
+ 2024-06-18 12:36:14,407 INFO MainThread:448378 [wandb_init.py:init():567] wandb.init called with sweep_config: {}
14
+ config: {'model_name': 'testing', 'global_batch_size': 8, 'batch_size': 8, 'num_epochs': 150, 'num_sessions': 40, 'num_params': 486928065, 'clip_scale': 1.0, 'prior_scale': 30.0, 'blur_scale': 0.5, 'use_image_aug': False, 'max_lr': 0.0003, 'mixup_pct': 0.33, 'num_samples_per_epoch': 30000, 'num_test': 3000, 'ckpt_interval': 999, 'ckpt_saving': False, 'seed': 42, 'distributed': False, 'num_devices': 1, 'world_size': 1, 'train_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/train/{0..39}.tar', 'test_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/new_test/0.tar'}
15
+ 2024-06-18 12:36:14,407 INFO MainThread:448378 [wandb_init.py:init():610] starting backend
16
+ 2024-06-18 12:36:14,408 INFO MainThread:448378 [wandb_init.py:init():614] setting up manager
17
+ 2024-06-18 12:36:14,417 INFO MainThread:448378 [backend.py:_multiprocessing_setup():105] multiprocessing start_methods=fork,spawn,forkserver, using: spawn
18
+ 2024-06-18 12:36:14,421 INFO MainThread:448378 [wandb_init.py:init():622] backend started and connected
19
+ 2024-06-18 12:36:14,444 INFO MainThread:448378 [wandb_run.py:_label_probe_notebook():1334] probe notebook
20
+ 2024-06-18 12:36:14,445 INFO MainThread:448378 [wandb_run.py:_label_probe_notebook():1344] Unable to probe notebook: 'NoneType' object has no attribute 'get'
21
+ 2024-06-18 12:36:14,445 INFO MainThread:448378 [wandb_init.py:init():711] updated telemetry
22
+ 2024-06-18 12:36:14,557 INFO MainThread:448378 [wandb_init.py:init():744] communicating run to backend with 90.0 second timeout
23
+ 2024-06-18 12:36:15,149 INFO MainThread:448378 [wandb_run.py:_on_init():2402] communicating current version
24
+ 2024-06-18 12:36:15,199 INFO MainThread:448378 [wandb_run.py:_on_init():2411] got version response upgrade_message: "wandb version 0.17.2 is available! To upgrade, please run:\n $ pip install wandb --upgrade"
25
+
26
+ 2024-06-18 12:36:15,200 INFO MainThread:448378 [wandb_init.py:init():795] starting run threads in backend
27
+ 2024-06-18 12:36:16,480 INFO MainThread:448378 [wandb_run.py:_console_start():2380] atexit reg
28
+ 2024-06-18 12:36:16,480 INFO MainThread:448378 [wandb_run.py:_redirect():2235] redirect: wrap_raw
29
+ 2024-06-18 12:36:16,480 INFO MainThread:448378 [wandb_run.py:_redirect():2300] Wrapping output streams.
30
+ 2024-06-18 12:36:16,480 INFO MainThread:448378 [wandb_run.py:_redirect():2325] Redirects installed.
31
+ 2024-06-18 12:36:16,484 INFO MainThread:448378 [wandb_init.py:init():838] run started, returning control to user process
32
+ 2024-06-18 12:36:16,489 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
33
+ 2024-06-18 12:36:16,490 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
34
+ 2024-06-18 12:36:16,562 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
35
+ 2024-06-18 12:36:16,563 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
36
+ 2024-06-18 12:36:16,563 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
37
+ 2024-06-18 12:36:16,646 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
38
+ 2024-06-18 12:36:16,653 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
39
+ 2024-06-18 12:36:16,654 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
40
+ 2024-06-18 12:36:16,746 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
41
+ 2024-06-18 12:36:16,917 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
42
+ 2024-06-18 12:36:16,917 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
43
+ 2024-06-18 12:36:17,011 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
44
+ 2024-06-18 12:36:17,012 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
45
+ 2024-06-18 12:36:17,013 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
46
+ 2024-06-18 12:36:17,101 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
47
+ 2024-06-18 13:24:59,287 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
48
+ 2024-06-18 13:24:59,288 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
49
+ 2024-06-18 13:25:23,444 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
50
+ 2024-06-18 13:25:57,202 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
51
+ 2024-06-18 13:25:57,203 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
52
+ 2024-06-18 13:26:25,695 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
53
+ 2024-06-18 13:26:55,886 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
54
+ 2024-06-18 13:26:55,887 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
55
+ 2024-06-18 13:28:40,735 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
56
+ 2024-06-18 13:28:40,757 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
57
+ 2024-06-18 13:28:40,758 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
58
+ 2024-06-18 13:28:49,551 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
59
+ 2024-06-18 13:28:49,553 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
60
+ 2024-06-18 13:28:49,553 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
61
+ 2024-06-18 13:28:58,554 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
62
+ 2024-06-18 13:28:58,558 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
63
+ 2024-06-18 13:28:58,559 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
64
+ 2024-06-18 13:29:01,816 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
65
+ 2024-06-18 13:29:01,823 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
66
+ 2024-06-18 13:29:01,824 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
67
+ 2024-06-18 13:29:05,134 INFO MainThread:448378 [wandb_init.py:_resume_backend():436] resuming backend
68
+ 2024-06-18 13:29:05,136 INFO MainThread:448378 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster.ipynb
69
+ 2024-06-18 13:29:05,136 INFO MainThread:448378 [wandb_init.py:_pause_backend():431] pausing backend
MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/config.yaml ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ wandb_version: 1
2
+
3
+ model_name:
4
+ desc: null
5
+ value: testing-tt2
6
+ global_batch_size:
7
+ desc: null
8
+ value: 16
9
+ batch_size:
10
+ desc: null
11
+ value: 16
12
+ num_epochs:
13
+ desc: null
14
+ value: 150
15
+ num_sessions:
16
+ desc: null
17
+ value: 40
18
+ num_params:
19
+ desc: null
20
+ value: 486928065
21
+ clip_scale:
22
+ desc: null
23
+ value: 1.0
24
+ prior_scale:
25
+ desc: null
26
+ value: 30.0
27
+ blur_scale:
28
+ desc: null
29
+ value: 0.5
30
+ use_image_aug:
31
+ desc: null
32
+ value: false
33
+ max_lr:
34
+ desc: null
35
+ value: 3.0e-05
36
+ mixup_pct:
37
+ desc: null
38
+ value: 0.33
39
+ num_samples_per_epoch:
40
+ desc: null
41
+ value: 30000
42
+ num_test:
43
+ desc: null
44
+ value: 3000
45
+ ckpt_interval:
46
+ desc: null
47
+ value: 999
48
+ ckpt_saving:
49
+ desc: null
50
+ value: false
51
+ seed:
52
+ desc: null
53
+ value: 42
54
+ distributed:
55
+ desc: null
56
+ value: false
57
+ num_devices:
58
+ desc: null
59
+ value: 1
60
+ world_size:
61
+ desc: null
62
+ value: 1
63
+ train_url:
64
+ desc: null
65
+ value: /weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/train/{0..39}.tar
66
+ test_url:
67
+ desc: null
68
+ value: /weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/new_test/0.tar
69
+ _wandb:
70
+ desc: null
71
+ value:
72
+ python_version: 3.11.9
73
+ cli_version: 0.17.1
74
+ framework: huggingface
75
+ huggingface_version: 4.37.2
76
+ is_jupyter_run: true
77
+ is_kaggle_kernel: false
78
+ start_time: 1718729436
79
+ t:
80
+ 1:
81
+ - 1
82
+ - 9
83
+ - 11
84
+ - 41
85
+ - 49
86
+ - 55
87
+ - 63
88
+ - 71
89
+ - 79
90
+ - 83
91
+ - 103
92
+ 2:
93
+ - 1
94
+ - 9
95
+ - 11
96
+ - 41
97
+ - 49
98
+ - 55
99
+ - 63
100
+ - 71
101
+ - 79
102
+ - 83
103
+ - 103
104
+ 3:
105
+ - 13
106
+ - 14
107
+ - 16
108
+ - 23
109
+ 4: 3.11.9
110
+ 5: 0.17.1
111
+ 6: 4.37.2
112
+ 8:
113
+ - 1
114
+ - 5
115
+ 13: linux-x86_64
MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/diff.patch ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/src/Train.ipynb b/src/Train.ipynb
2
+ index 91922c8..396549d 100644
3
+ --- a/src/Train.ipynb
4
+ +++ b/src/Train.ipynb
5
+ @@ -99,7 +99,7 @@
6
+ "name": "stdout",
7
+ "output_type": "stream",
8
+ "text": [
9
+ - "PID of this process = 3001293\n",
10
+ + "PID of this process = 3520819\n",
11
+ "device: cuda\n",
12
+ "Distributed environment: DistributedType.NO\n",
13
+ "Num processes: 1\n",
14
+ @@ -1362,9 +1362,9 @@
15
+ ],
16
+ "metadata": {
17
+ "kernelspec": {
18
+ - "display_name": "mindeye",
19
+ + "display_name": "Python 3 (ipykernel)",
20
+ "language": "python",
21
+ - "name": "mindeye"
22
+ + "name": "python3"
23
+ },
24
+ "language_info": {
25
+ "codemirror_mode": {
26
+ diff --git a/src/accel.slurm b/src/accel.slurm
27
+ index 1c1dfbc..f0b347f 100644
28
+ --- a/src/accel.slurm
29
+ +++ b/src/accel.slurm
30
+ @@ -1,7 +1,8 @@
31
+ #!/bin/bash
32
+ -#SBATCH --account=topfmri
33
+ -#SBATCH --partition=a40x
34
+ -#SBATCH --job-name=eye
35
+ +#SBATCH --account=fmri
36
+ +#SBATCH --qos=normal
37
+ +#SBATCH --partition=p5
38
+ +#SBATCH --job-name=eyeRR
39
+ #SBATCH --nodes=1
40
+ #SBATCH --gres=gpu:1
41
+ #SBATCH --time=48:00:00 # total run time limit (HH:MM:SS)
42
+ @@ -12,11 +13,11 @@
43
+ #SBATCH --exclusive
44
+
45
+ # Make sure you activate your fmri environment created from src/setup.sh
46
+ -cd /weka/proj-fmri/paulscotti/MindEyeV2/src
47
+ -source fmri/bin/activate
48
+ +cd /weka/proj-fmri/ckadirt/MindEyeV2/src
49
+ +source /admin/home-ckadirt/fmri/bin/activate
50
+
51
+ # The following line converts your jupyter notebook into a python script runnable with Slurm
52
+ -jupyter nbconvert Train.ipynb --to python
53
+ +jupyter nbconvert TrainCluster-Copy2.ipynb --to python
54
+
55
+ export NUM_GPUS=1 # Set to equal gres=gpu:#!
56
+ export BATCH_SIZE=21 # 21 for multisubject / 24 for singlesubject (orig. paper used 42 for multisubject / 24 for singlesubject)
57
+ @@ -26,16 +27,16 @@ export GLOBAL_BATCH_SIZE=$((BATCH_SIZE * NUM_GPUS))
58
+ export MASTER_PORT=$((RANDOM % (19000 - 11000 + 1) + 11000))
59
+ export HOSTNAMES=$(scontrol show hostnames "$SLURM_JOB_NODELIST")
60
+ export MASTER_ADDR=$(scontrol show hostnames "$SLURM_JOB_NODELIST" | head -n 1)
61
+ -export COUNT_NODE=$(scontrol show hostnames "$SLURM_JOB_NODELIST" | wc -l)
62
+ +export COUNT_NODE=1 #$(scontrol show hostnames "$SLURM_JOB_NODELIST" | wc -l)
63
+ echo MASTER_ADDR=${MASTER_ADDR}
64
+ echo MASTER_PORT=${MASTER_PORT}
65
+ echo WORLD_SIZE=${COUNT_NODE}
66
+
67
+ # multisubject pretraining
68
+ -model_name="multisubject_excludingsubj01_40sess"
69
+ +model_name="rr-test-top"
70
+ echo model_name=${model_name}
71
+ -accelerate launch --num_processes=$(($NUM_GPUS * $COUNT_NODE)) --num_machines=$COUNT_NODE --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --mixed_precision=fp16 Train.py --data_path=/weka/proj-fmri/shared/mindeyev2_dataset --cache_dir=/weka/proj-fmri/shared/cache --model_name=${model_name} --multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --use_prior --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
72
+ -
73
+ +# accelerate launch --num_processes=$(($NUM_GPUS * $COUNT_NODE)) --num_machines=$COUNT_NODE --main_process_ip=$MASTER_ADDR --main_process_port=$MASTER_PORT --mixed_precision=fp16 TrainCluster.py --data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=${model_name} --multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-4 --mixup_pct=.33 --num_epochs=150 --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
74
+ +python TrainCluster-Copy2.py --data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/cache --model_name=${model_name} --no-multi_subject --subj=1 --batch_size=${BATCH_SIZE} --max_lr=3e-5 --mixup_pct=.33 --num_epochs=150 --prior_scale=30 --clip_scale=1 --no-blurry_recon --blur_scale=.5 --no-use_image_aug --n_blocks=4 --hidden_dim=1024 --num_sessions=40 --ckpt_interval=999 --ckpt_saving --wandb_log
75
+ # singlesubject finetuning
76
+ #model_name="finetuned_subj01_40sess"
77
+ #echo model_name=${model_name}
78
+ diff --git a/src/recon_inference.ipynb b/src/recon_inference.ipynb
79
+ index 10d7e27..0593e7e 100644
80
+ --- a/src/recon_inference.ipynb
81
+ +++ b/src/recon_inference.ipynb
82
+ @@ -12,7 +12,6 @@
83
+ "name": "stdout",
84
+ "output_type": "stream",
85
+ "text": [
86
+ - "LOCAL RANK 0\n",
87
+ "device: cuda\n"
88
+ ]
89
+ }
90
+ @@ -60,7 +59,7 @@
91
+ },
92
+ {
93
+ "cell_type": "code",
94
+ - "execution_count": 33,
95
+ + "execution_count": 2,
96
+ "id": "e52985b1-95ff-487b-8b2d-cc1ad1c190b8",
97
+ "metadata": {
98
+ "tags": []
99
+ @@ -71,9 +70,7 @@
100
+ "output_type": "stream",
101
+ "text": [
102
+ "model_name: final_subj01_pretrained_40sess_24bs\n",
103
+ - "--data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/mindeyev2_dataset --model_name=final_subj01_pretrained_40sess_24bs --subj=1 --hidden_dim=4096 --n_blocks=4 --new_test\n",
104
+ - "The autoreload extension is already loaded. To reload it, use:\n",
105
+ - " %reload_ext autoreload\n"
106
+ + "--data_path=/weka/proj-medarc/shared/mindeyev2_dataset --cache_dir=/weka/proj-medarc/shared/mindeyev2_dataset --model_name=final_subj01_pretrained_40sess_24bs --subj=1 --hidden_dim=4096 --n_blocks=4 --new_test\n"
107
+ ]
108
+ }
109
+ ],
110
+ @@ -99,7 +96,7 @@
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ - "execution_count": 34,
115
+ + "execution_count": 3,
116
+ "id": "49e5dae4-606d-4dc6-b420-df9e4c14737e",
117
+ "metadata": {
118
+ "tags": []
119
+ @@ -157,7 +154,7 @@
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ - "execution_count": 35,
124
+ + "execution_count": 4,
125
+ "id": "64672583-9f00-46f5-8d4e-00e4c7068a1d",
126
+ "metadata": {
127
+ "tags": []
128
+ @@ -221,7 +218,7 @@
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ - "execution_count": 36,
133
+ + "execution_count": 5,
134
+ "id": "a3cbeea8-e95b-48d9-9bc2-91af260c93d1",
135
+ "metadata": {},
136
+ "outputs": [
137
+ @@ -254,39 +251,10 @@
138
+ },
139
+ {
140
+ "cell_type": "code",
141
+ - "execution_count": 38,
142
+ + "execution_count": null,
143
+ "id": "3afc4858-b6a6-4a52-9303-b4a50ea5cc0b",
144
+ "metadata": {},
145
+ - "outputs": [
146
+ - {
147
+ - "name": "stdout",
148
+ - "output_type": "stream",
149
+ - "text": [
150
+ - "param counts:\n",
151
+ - "83,653,863 total\n",
152
+ - "0 trainable\n",
153
+ - "param counts:\n",
154
+ - "64,409,600 total\n",
155
+ - "64,409,600 trainable\n",
156
+ - "param counts:\n",
157
+ - "1,903,020,028 total\n",
158
+ - "1,903,020,028 trainable\n",
159
+ - "param counts:\n",
160
+ - "1,967,429,628 total\n",
161
+ - "1,967,429,628 trainable\n",
162
+ - "param counts:\n",
163
+ - "259,865,216 total\n",
164
+ - "259,865,200 trainable\n",
165
+ - "param counts:\n",
166
+ - "2,227,294,844 total\n",
167
+ - "2,227,294,828 trainable\n",
168
+ - "\n",
169
+ - "---loading /weka/proj-fmri/paulscotti/MindEye2_git/train_logs/final_subj01_pretrained_40sess_24bs/last.pth ckpt---\n",
170
+ - "\n",
171
+ - "ckpt loaded!\n"
172
+ - ]
173
+ - }
174
+ - ],
175
+ + "outputs": [],
176
+ "source": [
177
+ "clip_img_embedder = FrozenOpenCLIPImageEmbedder(\n",
178
+ " arch=\"ViT-bigG-14\",\n",
179
+ @@ -393,7 +361,7 @@
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ - "execution_count": 30,
184
+ + "execution_count": null,
185
+ "id": "295824db-ab3d-450c-90fb-f656e48994ba",
186
+ "metadata": {
187
+ "tags": []
188
+ @@ -430,38 +398,10 @@
189
+ },
190
+ {
191
+ "cell_type": "code",
192
+ - "execution_count": 31,
193
+ + "execution_count": null,
194
+ "id": "f726f617-39f5-49e2-8d0c-d11d27d01c30",
195
+ "metadata": {},
196
+ - "outputs": [
197
+ - {
198
+ - "name": "stderr",
199
+ - "output_type": "stream",
200
+ - "text": [
201
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
202
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
203
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
204
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
205
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
206
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
207
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
208
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 10. Setting context_dim to [1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664, 1664] now.\n",
209
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
210
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n",
211
+ - "WARNING:sgm.modules.attention:SpatialTransformer: Found context dims [1664] of depth 1, which does not match the specified 'depth' of 2. Setting context_dim to [1664, 1664] now.\n"
212
+ - ]
213
+ - },
214
+ - {
215
+ - "name": "stdout",
216
+ - "output_type": "stream",
217
+ - "text": [
218
+ - "Initialized embedder #0: FrozenOpenCLIPImageEmbedder with 1909889025 params. Trainable: False\n",
219
+ - "Initialized embedder #1: ConcatTimestepEmbedderND with 0 params. Trainable: False\n",
220
+ - "Initialized embedder #2: ConcatTimestepEmbedderND with 0 params. Trainable: False\n",
221
+ - "vector_suffix torch.Size([1, 1024])\n"
222
+ - ]
223
+ - }
224
+ - ],
225
+ + "outputs": [],
226
+ "source": [
227
+ "# prep unCLIP\n",
228
+ "config = OmegaConf.load(\"generative_models/configs/unclip6.yaml\")\n",
229
+ @@ -715,9 +655,9 @@
230
+ ],
231
+ "metadata": {
232
+ "kernelspec": {
233
+ - "display_name": "mindeye",
234
+ + "display_name": "Python 3 (ipykernel)",
235
+ "language": "python",
236
+ - "name": "mindeye"
237
+ + "name": "python3"
238
+ },
239
+ "language_info": {
240
+ "codemirror_mode": {
MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 1875
2
+ testing-tt2 starting with epoch 0 / 150
3
+ 0%| | 0/150 [00:00<?, ?it/s]
4
+ loss_RR 2.82318115234375
5
+ loss_RR 2.54290771484375
6
+ loss_RR 2.6309814453125
7
+ loss_RR 2.68603515625
8
+ loss_RR 2.663818359375
9
+ loss_RR 2.65960693359375
10
+ loss_RR 2.68072509765625
11
+ loss_RR 2.656005859375
12
+ loss_RR 2.9378662109375
13
+ loss_RR 3.2581787109375
14
+ loss_RR 2.9754638671875
15
+ loss_RR 2.8961181640625
16
+ loss_RR 2.99554443359375
17
+ loss_RR 2.87652587890625
18
+
19
+ 0%| | 0/150 [08:49<?, ?it/s]
MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/requirements.txt ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Babel==2.15.0
2
+ CoCa-pytorch==0.1.0
3
+ GitPython==3.1.43
4
+ Jinja2==3.1.4
5
+ MarkupSafe==2.1.5
6
+ PyYAML==6.0.1
7
+ Pygments==2.18.0
8
+ QtPy==2.4.1
9
+ Send2Trash==1.8.3
10
+ absl-py==2.1.0
11
+ accelerate==0.24.1
12
+ aiohttp==3.9.5
13
+ aiosignal==1.3.1
14
+ annotated-types==0.7.0
15
+ antlr4-python3-runtime==4.9.3
16
+ anyio==4.4.0
17
+ argon2-cffi-bindings==21.2.0
18
+ argon2-cffi==23.1.0
19
+ arrow==1.3.0
20
+ asttokens==2.4.1
21
+ async-lru==2.0.4
22
+ attrs==23.2.0
23
+ beartype==0.18.5
24
+ beautifulsoup4==4.12.3
25
+ bleach==6.1.0
26
+ braceexpand==0.1.7
27
+ certifi==2024.6.2
28
+ cffi==1.16.0
29
+ charset-normalizer==3.3.2
30
+ click==8.1.7
31
+ clip-anytorch==2.6.0
32
+ clip==1.0
33
+ comm==0.2.2
34
+ contourpy==1.2.1
35
+ cycler==0.12.1
36
+ dalle2-pytorch==1.15.6
37
+ datasets==2.20.0
38
+ debugpy==1.8.1
39
+ decorator==5.1.1
40
+ deepspeed==0.13.1
41
+ defusedxml==0.7.1
42
+ diffusers==0.23.0
43
+ dill==0.3.8
44
+ docker-pycreds==0.4.0
45
+ einops==0.8.0
46
+ einx==0.3.0
47
+ ema-pytorch==0.5.0
48
+ embedding-reader==1.7.0
49
+ evaluate==0.4.1
50
+ executing==2.0.1
51
+ fastjsonschema==2.20.0
52
+ filelock==3.15.1
53
+ fonttools==4.53.0
54
+ fqdn==1.5.1
55
+ frozendict==2.4.4
56
+ frozenlist==1.4.1
57
+ fsspec==2024.5.0
58
+ ftfy==6.2.0
59
+ gitdb==4.0.11
60
+ h11==0.14.0
61
+ h5py==3.10.0
62
+ hjson==3.1.0
63
+ httpcore==1.0.5
64
+ httpx==0.27.0
65
+ huggingface-hub==0.23.4
66
+ idna==3.7
67
+ imageio==2.34.1
68
+ importlib_metadata==7.1.0
69
+ ipykernel==6.29.4
70
+ ipython==8.25.0
71
+ ipywidgets==8.1.3
72
+ isoduration==20.11.0
73
+ jedi==0.19.1
74
+ joblib==1.4.2
75
+ json5==0.9.25
76
+ jsonpointer==3.0.0
77
+ jsonschema-specifications==2023.12.1
78
+ jsonschema==4.22.0
79
+ jupyter-console==6.6.3
80
+ jupyter-events==0.10.0
81
+ jupyter-lsp==2.2.5
82
+ jupyter==1.0.0
83
+ jupyter_client==8.6.2
84
+ jupyter_core==5.7.2
85
+ jupyter_server==2.14.1
86
+ jupyter_server_terminals==0.5.3
87
+ jupyterlab==4.2.2
88
+ jupyterlab_nvdashboard==0.11.0
89
+ jupyterlab_pygments==0.3.0
90
+ jupyterlab_server==2.27.2
91
+ jupyterlab_widgets==3.0.11
92
+ kiwisolver==1.4.5
93
+ kornia==0.7.1
94
+ lazy_loader==0.4
95
+ lightning-utilities==0.11.2
96
+ matplotlib-inline==0.1.7
97
+ matplotlib==3.8.2
98
+ mistune==3.0.2
99
+ mpmath==1.3.0
100
+ multidict==6.0.5
101
+ multiprocess==0.70.16
102
+ nbclient==0.10.0
103
+ nbconvert==7.16.4
104
+ nbformat==5.10.4
105
+ nest-asyncio==1.6.0
106
+ networkx==3.3
107
+ ninja==1.11.1.1
108
+ nltk==3.8.1
109
+ notebook==7.2.1
110
+ notebook_shim==0.2.4
111
+ numpy==1.26.4
112
+ nvidia-cublas-cu12==12.1.3.1
113
+ nvidia-cuda-cupti-cu12==12.1.105
114
+ nvidia-cuda-nvrtc-cu12==12.1.105
115
+ nvidia-cuda-runtime-cu12==12.1.105
116
+ nvidia-cudnn-cu12==8.9.2.26
117
+ nvidia-cufft-cu12==11.0.2.54
118
+ nvidia-curand-cu12==10.3.2.106
119
+ nvidia-cusolver-cu12==11.4.5.107
120
+ nvidia-cusparse-cu12==12.1.0.106
121
+ nvidia-nccl-cu12==2.18.1
122
+ nvidia-nvjitlink-cu12==12.5.40
123
+ nvidia-nvtx-cu12==12.1.105
124
+ omegaconf==2.3.0
125
+ open-clip-torch==2.24.0
126
+ overrides==7.7.0
127
+ packaging==24.1
128
+ pandas==2.2.0
129
+ pandocfilters==1.5.1
130
+ parso==0.8.4
131
+ pexpect==4.9.0
132
+ pillow==10.3.0
133
+ pip==24.0
134
+ platformdirs==4.2.2
135
+ prometheus_client==0.20.0
136
+ prompt_toolkit==3.0.47
137
+ protobuf==5.27.1
138
+ psutil==5.9.8
139
+ ptyprocess==0.7.0
140
+ pure-eval==0.2.2
141
+ py-cpuinfo==9.0.0
142
+ pyarrow-hotfix==0.6
143
+ pyarrow==15.0.2
144
+ pycparser==2.22
145
+ pydantic==2.7.4
146
+ pydantic_core==2.18.4
147
+ pynvml==11.5.0
148
+ pyparsing==3.1.2
149
+ python-dateutil==2.9.0.post0
150
+ python-json-logger==2.0.7
151
+ pytorch-lightning==2.0.1
152
+ pytorch-warmup==0.1.1
153
+ pytz==2024.1
154
+ pyzmq==26.0.3
155
+ qtconsole==5.5.2
156
+ referencing==0.35.1
157
+ regex==2024.5.15
158
+ requests==2.32.3
159
+ resize-right==0.0.2
160
+ responses==0.18.0
161
+ rfc3339-validator==0.1.4
162
+ rfc3986-validator==0.1.1
163
+ rotary-embedding-torch==0.6.2
164
+ rouge_score==0.1.2
165
+ rpds-py==0.18.1
166
+ safetensors==0.4.3
167
+ scikit-image==0.22.0
168
+ scikit-learn==1.5.0
169
+ scipy==1.13.1
170
+ sentence-transformers==2.5.1
171
+ sentencepiece==0.2.0
172
+ sentry-sdk==2.5.1
173
+ setproctitle==1.3.3
174
+ setuptools==65.5.0
175
+ six==1.16.0
176
+ smmap==5.0.1
177
+ sniffio==1.3.1
178
+ soupsieve==2.5
179
+ stack-data==0.6.3
180
+ sympy==1.12.1
181
+ terminado==0.18.1
182
+ threadpoolctl==3.5.0
183
+ tifffile==2024.5.22
184
+ timm==1.0.3
185
+ tinycss2==1.3.0
186
+ tokenizers==0.15.2
187
+ torch-fidelity==0.3.0
188
+ torch==2.1.0
189
+ torchmetrics==1.3.0.post0
190
+ torchvision==0.16.0
191
+ tornado==6.4.1
192
+ tqdm==4.66.4
193
+ traitlets==5.14.3
194
+ transformers==4.37.2
195
+ triton==2.1.0
196
+ types-python-dateutil==2.9.0.20240316
197
+ typing_extensions==4.12.2
198
+ tzdata==2024.1
199
+ umap==0.1.1
200
+ uri-template==1.3.0
201
+ urllib3==2.2.1
202
+ vector-quantize-pytorch==1.14.24
203
+ wandb==0.17.1
204
+ wcwidth==0.2.13
205
+ webcolors==24.6.0
206
+ webdataset==0.2.73
207
+ webencodings==0.5.1
208
+ websocket-client==1.8.0
209
+ widgetsnbextension==4.0.11
210
+ x-clip==0.14.4
211
+ xformers==0.0.22.post7
212
+ xxhash==3.4.1
213
+ yarl==1.9.4
214
+ zipp==3.19.2
MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/wandb-metadata.json ADDED
@@ -0,0 +1,1035 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "os": "Linux-5.15.0-1058-aws-x86_64-with-glibc2.31",
3
+ "python": "3.11.9",
4
+ "heartbeatAt": "2024-06-18T16:50:37.724201",
5
+ "startedAt": "2024-06-18T16:50:36.657596",
6
+ "docker": null,
7
+ "cuda": null,
8
+ "args": [],
9
+ "state": "running",
10
+ "program": "ckadirt/MindEyeV2/src/TrainCluster-Copy2.ipynb",
11
+ "codePathLocal": null,
12
+ "root": "/weka/proj-fmri/ckadirt/MindEyeV2",
13
+ "git": {
14
+ "remote": "https://github.com/MedARC-AI/MindEyeV2.git",
15
+ "commit": "a3588f0fadc81bdb0cc3e15993c01f8dd64dc7fe"
16
+ },
17
+ "email": null,
18
+ "host": "ip-10-0-159-181",
19
+ "username": "ckadirt",
20
+ "executable": "/admin/home-ckadirt/fmri/bin/python3.11",
21
+ "cpu_count": 96,
22
+ "cpu_count_logical": 192,
23
+ "cpu_freq": {
24
+ "current": 2737.5654166666754,
25
+ "min": 0.0,
26
+ "max": 0.0
27
+ },
28
+ "cpu_freq_per_core": [
29
+ {
30
+ "current": 2649.998,
31
+ "min": 0.0,
32
+ "max": 0.0
33
+ },
34
+ {
35
+ "current": 2649.998,
36
+ "min": 0.0,
37
+ "max": 0.0
38
+ },
39
+ {
40
+ "current": 2649.998,
41
+ "min": 0.0,
42
+ "max": 0.0
43
+ },
44
+ {
45
+ "current": 3599.552,
46
+ "min": 0.0,
47
+ "max": 0.0
48
+ },
49
+ {
50
+ "current": 2649.998,
51
+ "min": 0.0,
52
+ "max": 0.0
53
+ },
54
+ {
55
+ "current": 2649.998,
56
+ "min": 0.0,
57
+ "max": 0.0
58
+ },
59
+ {
60
+ "current": 3571.159,
61
+ "min": 0.0,
62
+ "max": 0.0
63
+ },
64
+ {
65
+ "current": 2649.998,
66
+ "min": 0.0,
67
+ "max": 0.0
68
+ },
69
+ {
70
+ "current": 2649.998,
71
+ "min": 0.0,
72
+ "max": 0.0
73
+ },
74
+ {
75
+ "current": 3597.82,
76
+ "min": 0.0,
77
+ "max": 0.0
78
+ },
79
+ {
80
+ "current": 2649.998,
81
+ "min": 0.0,
82
+ "max": 0.0
83
+ },
84
+ {
85
+ "current": 2649.998,
86
+ "min": 0.0,
87
+ "max": 0.0
88
+ },
89
+ {
90
+ "current": 2649.998,
91
+ "min": 0.0,
92
+ "max": 0.0
93
+ },
94
+ {
95
+ "current": 2649.998,
96
+ "min": 0.0,
97
+ "max": 0.0
98
+ },
99
+ {
100
+ "current": 2649.998,
101
+ "min": 0.0,
102
+ "max": 0.0
103
+ },
104
+ {
105
+ "current": 2649.998,
106
+ "min": 0.0,
107
+ "max": 0.0
108
+ },
109
+ {
110
+ "current": 2649.998,
111
+ "min": 0.0,
112
+ "max": 0.0
113
+ },
114
+ {
115
+ "current": 2649.998,
116
+ "min": 0.0,
117
+ "max": 0.0
118
+ },
119
+ {
120
+ "current": 2649.998,
121
+ "min": 0.0,
122
+ "max": 0.0
123
+ },
124
+ {
125
+ "current": 2649.998,
126
+ "min": 0.0,
127
+ "max": 0.0
128
+ },
129
+ {
130
+ "current": 2649.998,
131
+ "min": 0.0,
132
+ "max": 0.0
133
+ },
134
+ {
135
+ "current": 2649.998,
136
+ "min": 0.0,
137
+ "max": 0.0
138
+ },
139
+ {
140
+ "current": 2649.998,
141
+ "min": 0.0,
142
+ "max": 0.0
143
+ },
144
+ {
145
+ "current": 2649.998,
146
+ "min": 0.0,
147
+ "max": 0.0
148
+ },
149
+ {
150
+ "current": 2649.998,
151
+ "min": 0.0,
152
+ "max": 0.0
153
+ },
154
+ {
155
+ "current": 2649.998,
156
+ "min": 0.0,
157
+ "max": 0.0
158
+ },
159
+ {
160
+ "current": 2649.998,
161
+ "min": 0.0,
162
+ "max": 0.0
163
+ },
164
+ {
165
+ "current": 2649.998,
166
+ "min": 0.0,
167
+ "max": 0.0
168
+ },
169
+ {
170
+ "current": 2649.998,
171
+ "min": 0.0,
172
+ "max": 0.0
173
+ },
174
+ {
175
+ "current": 2649.998,
176
+ "min": 0.0,
177
+ "max": 0.0
178
+ },
179
+ {
180
+ "current": 2649.998,
181
+ "min": 0.0,
182
+ "max": 0.0
183
+ },
184
+ {
185
+ "current": 2649.998,
186
+ "min": 0.0,
187
+ "max": 0.0
188
+ },
189
+ {
190
+ "current": 2649.998,
191
+ "min": 0.0,
192
+ "max": 0.0
193
+ },
194
+ {
195
+ "current": 2649.998,
196
+ "min": 0.0,
197
+ "max": 0.0
198
+ },
199
+ {
200
+ "current": 2649.998,
201
+ "min": 0.0,
202
+ "max": 0.0
203
+ },
204
+ {
205
+ "current": 2649.998,
206
+ "min": 0.0,
207
+ "max": 0.0
208
+ },
209
+ {
210
+ "current": 2649.998,
211
+ "min": 0.0,
212
+ "max": 0.0
213
+ },
214
+ {
215
+ "current": 2649.998,
216
+ "min": 0.0,
217
+ "max": 0.0
218
+ },
219
+ {
220
+ "current": 2649.998,
221
+ "min": 0.0,
222
+ "max": 0.0
223
+ },
224
+ {
225
+ "current": 2649.998,
226
+ "min": 0.0,
227
+ "max": 0.0
228
+ },
229
+ {
230
+ "current": 2649.998,
231
+ "min": 0.0,
232
+ "max": 0.0
233
+ },
234
+ {
235
+ "current": 2649.998,
236
+ "min": 0.0,
237
+ "max": 0.0
238
+ },
239
+ {
240
+ "current": 2649.998,
241
+ "min": 0.0,
242
+ "max": 0.0
243
+ },
244
+ {
245
+ "current": 2649.998,
246
+ "min": 0.0,
247
+ "max": 0.0
248
+ },
249
+ {
250
+ "current": 3599.455,
251
+ "min": 0.0,
252
+ "max": 0.0
253
+ },
254
+ {
255
+ "current": 3598.843,
256
+ "min": 0.0,
257
+ "max": 0.0
258
+ },
259
+ {
260
+ "current": 3598.67,
261
+ "min": 0.0,
262
+ "max": 0.0
263
+ },
264
+ {
265
+ "current": 3599.596,
266
+ "min": 0.0,
267
+ "max": 0.0
268
+ },
269
+ {
270
+ "current": 3597.56,
271
+ "min": 0.0,
272
+ "max": 0.0
273
+ },
274
+ {
275
+ "current": 3597.635,
276
+ "min": 0.0,
277
+ "max": 0.0
278
+ },
279
+ {
280
+ "current": 3597.882,
281
+ "min": 0.0,
282
+ "max": 0.0
283
+ },
284
+ {
285
+ "current": 3597.88,
286
+ "min": 0.0,
287
+ "max": 0.0
288
+ },
289
+ {
290
+ "current": 2649.998,
291
+ "min": 0.0,
292
+ "max": 0.0
293
+ },
294
+ {
295
+ "current": 2649.998,
296
+ "min": 0.0,
297
+ "max": 0.0
298
+ },
299
+ {
300
+ "current": 2649.998,
301
+ "min": 0.0,
302
+ "max": 0.0
303
+ },
304
+ {
305
+ "current": 2649.998,
306
+ "min": 0.0,
307
+ "max": 0.0
308
+ },
309
+ {
310
+ "current": 2649.998,
311
+ "min": 0.0,
312
+ "max": 0.0
313
+ },
314
+ {
315
+ "current": 3504.795,
316
+ "min": 0.0,
317
+ "max": 0.0
318
+ },
319
+ {
320
+ "current": 3548.68,
321
+ "min": 0.0,
322
+ "max": 0.0
323
+ },
324
+ {
325
+ "current": 2649.998,
326
+ "min": 0.0,
327
+ "max": 0.0
328
+ },
329
+ {
330
+ "current": 2649.998,
331
+ "min": 0.0,
332
+ "max": 0.0
333
+ },
334
+ {
335
+ "current": 2649.998,
336
+ "min": 0.0,
337
+ "max": 0.0
338
+ },
339
+ {
340
+ "current": 2649.998,
341
+ "min": 0.0,
342
+ "max": 0.0
343
+ },
344
+ {
345
+ "current": 2649.998,
346
+ "min": 0.0,
347
+ "max": 0.0
348
+ },
349
+ {
350
+ "current": 2649.998,
351
+ "min": 0.0,
352
+ "max": 0.0
353
+ },
354
+ {
355
+ "current": 2649.998,
356
+ "min": 0.0,
357
+ "max": 0.0
358
+ },
359
+ {
360
+ "current": 2649.998,
361
+ "min": 0.0,
362
+ "max": 0.0
363
+ },
364
+ {
365
+ "current": 2649.998,
366
+ "min": 0.0,
367
+ "max": 0.0
368
+ },
369
+ {
370
+ "current": 2649.998,
371
+ "min": 0.0,
372
+ "max": 0.0
373
+ },
374
+ {
375
+ "current": 2649.998,
376
+ "min": 0.0,
377
+ "max": 0.0
378
+ },
379
+ {
380
+ "current": 2649.998,
381
+ "min": 0.0,
382
+ "max": 0.0
383
+ },
384
+ {
385
+ "current": 2649.998,
386
+ "min": 0.0,
387
+ "max": 0.0
388
+ },
389
+ {
390
+ "current": 2649.998,
391
+ "min": 0.0,
392
+ "max": 0.0
393
+ },
394
+ {
395
+ "current": 2649.998,
396
+ "min": 0.0,
397
+ "max": 0.0
398
+ },
399
+ {
400
+ "current": 2649.998,
401
+ "min": 0.0,
402
+ "max": 0.0
403
+ },
404
+ {
405
+ "current": 2649.998,
406
+ "min": 0.0,
407
+ "max": 0.0
408
+ },
409
+ {
410
+ "current": 2649.998,
411
+ "min": 0.0,
412
+ "max": 0.0
413
+ },
414
+ {
415
+ "current": 2649.998,
416
+ "min": 0.0,
417
+ "max": 0.0
418
+ },
419
+ {
420
+ "current": 2649.998,
421
+ "min": 0.0,
422
+ "max": 0.0
423
+ },
424
+ {
425
+ "current": 2649.998,
426
+ "min": 0.0,
427
+ "max": 0.0
428
+ },
429
+ {
430
+ "current": 2649.998,
431
+ "min": 0.0,
432
+ "max": 0.0
433
+ },
434
+ {
435
+ "current": 2649.998,
436
+ "min": 0.0,
437
+ "max": 0.0
438
+ },
439
+ {
440
+ "current": 2649.998,
441
+ "min": 0.0,
442
+ "max": 0.0
443
+ },
444
+ {
445
+ "current": 2649.998,
446
+ "min": 0.0,
447
+ "max": 0.0
448
+ },
449
+ {
450
+ "current": 2649.998,
451
+ "min": 0.0,
452
+ "max": 0.0
453
+ },
454
+ {
455
+ "current": 2649.998,
456
+ "min": 0.0,
457
+ "max": 0.0
458
+ },
459
+ {
460
+ "current": 2649.998,
461
+ "min": 0.0,
462
+ "max": 0.0
463
+ },
464
+ {
465
+ "current": 2649.998,
466
+ "min": 0.0,
467
+ "max": 0.0
468
+ },
469
+ {
470
+ "current": 2649.998,
471
+ "min": 0.0,
472
+ "max": 0.0
473
+ },
474
+ {
475
+ "current": 2649.998,
476
+ "min": 0.0,
477
+ "max": 0.0
478
+ },
479
+ {
480
+ "current": 2649.998,
481
+ "min": 0.0,
482
+ "max": 0.0
483
+ },
484
+ {
485
+ "current": 2649.998,
486
+ "min": 0.0,
487
+ "max": 0.0
488
+ },
489
+ {
490
+ "current": 2649.998,
491
+ "min": 0.0,
492
+ "max": 0.0
493
+ },
494
+ {
495
+ "current": 2649.998,
496
+ "min": 0.0,
497
+ "max": 0.0
498
+ },
499
+ {
500
+ "current": 2649.998,
501
+ "min": 0.0,
502
+ "max": 0.0
503
+ },
504
+ {
505
+ "current": 2649.998,
506
+ "min": 0.0,
507
+ "max": 0.0
508
+ },
509
+ {
510
+ "current": 2649.998,
511
+ "min": 0.0,
512
+ "max": 0.0
513
+ },
514
+ {
515
+ "current": 2649.998,
516
+ "min": 0.0,
517
+ "max": 0.0
518
+ },
519
+ {
520
+ "current": 2649.998,
521
+ "min": 0.0,
522
+ "max": 0.0
523
+ },
524
+ {
525
+ "current": 2649.998,
526
+ "min": 0.0,
527
+ "max": 0.0
528
+ },
529
+ {
530
+ "current": 2649.998,
531
+ "min": 0.0,
532
+ "max": 0.0
533
+ },
534
+ {
535
+ "current": 2649.998,
536
+ "min": 0.0,
537
+ "max": 0.0
538
+ },
539
+ {
540
+ "current": 2649.998,
541
+ "min": 0.0,
542
+ "max": 0.0
543
+ },
544
+ {
545
+ "current": 2649.998,
546
+ "min": 0.0,
547
+ "max": 0.0
548
+ },
549
+ {
550
+ "current": 2649.998,
551
+ "min": 0.0,
552
+ "max": 0.0
553
+ },
554
+ {
555
+ "current": 2649.998,
556
+ "min": 0.0,
557
+ "max": 0.0
558
+ },
559
+ {
560
+ "current": 2649.998,
561
+ "min": 0.0,
562
+ "max": 0.0
563
+ },
564
+ {
565
+ "current": 2649.998,
566
+ "min": 0.0,
567
+ "max": 0.0
568
+ },
569
+ {
570
+ "current": 2649.998,
571
+ "min": 0.0,
572
+ "max": 0.0
573
+ },
574
+ {
575
+ "current": 2649.998,
576
+ "min": 0.0,
577
+ "max": 0.0
578
+ },
579
+ {
580
+ "current": 2649.998,
581
+ "min": 0.0,
582
+ "max": 0.0
583
+ },
584
+ {
585
+ "current": 2649.998,
586
+ "min": 0.0,
587
+ "max": 0.0
588
+ },
589
+ {
590
+ "current": 2649.998,
591
+ "min": 0.0,
592
+ "max": 0.0
593
+ },
594
+ {
595
+ "current": 2649.998,
596
+ "min": 0.0,
597
+ "max": 0.0
598
+ },
599
+ {
600
+ "current": 2649.998,
601
+ "min": 0.0,
602
+ "max": 0.0
603
+ },
604
+ {
605
+ "current": 2649.998,
606
+ "min": 0.0,
607
+ "max": 0.0
608
+ },
609
+ {
610
+ "current": 2649.998,
611
+ "min": 0.0,
612
+ "max": 0.0
613
+ },
614
+ {
615
+ "current": 2649.998,
616
+ "min": 0.0,
617
+ "max": 0.0
618
+ },
619
+ {
620
+ "current": 2649.998,
621
+ "min": 0.0,
622
+ "max": 0.0
623
+ },
624
+ {
625
+ "current": 2649.998,
626
+ "min": 0.0,
627
+ "max": 0.0
628
+ },
629
+ {
630
+ "current": 2649.998,
631
+ "min": 0.0,
632
+ "max": 0.0
633
+ },
634
+ {
635
+ "current": 2649.998,
636
+ "min": 0.0,
637
+ "max": 0.0
638
+ },
639
+ {
640
+ "current": 2649.998,
641
+ "min": 0.0,
642
+ "max": 0.0
643
+ },
644
+ {
645
+ "current": 2649.998,
646
+ "min": 0.0,
647
+ "max": 0.0
648
+ },
649
+ {
650
+ "current": 2649.998,
651
+ "min": 0.0,
652
+ "max": 0.0
653
+ },
654
+ {
655
+ "current": 2649.998,
656
+ "min": 0.0,
657
+ "max": 0.0
658
+ },
659
+ {
660
+ "current": 2649.998,
661
+ "min": 0.0,
662
+ "max": 0.0
663
+ },
664
+ {
665
+ "current": 2649.998,
666
+ "min": 0.0,
667
+ "max": 0.0
668
+ },
669
+ {
670
+ "current": 2649.998,
671
+ "min": 0.0,
672
+ "max": 0.0
673
+ },
674
+ {
675
+ "current": 2649.998,
676
+ "min": 0.0,
677
+ "max": 0.0
678
+ },
679
+ {
680
+ "current": 2649.998,
681
+ "min": 0.0,
682
+ "max": 0.0
683
+ },
684
+ {
685
+ "current": 2649.998,
686
+ "min": 0.0,
687
+ "max": 0.0
688
+ },
689
+ {
690
+ "current": 2649.998,
691
+ "min": 0.0,
692
+ "max": 0.0
693
+ },
694
+ {
695
+ "current": 2649.998,
696
+ "min": 0.0,
697
+ "max": 0.0
698
+ },
699
+ {
700
+ "current": 2649.998,
701
+ "min": 0.0,
702
+ "max": 0.0
703
+ },
704
+ {
705
+ "current": 2649.998,
706
+ "min": 0.0,
707
+ "max": 0.0
708
+ },
709
+ {
710
+ "current": 2649.998,
711
+ "min": 0.0,
712
+ "max": 0.0
713
+ },
714
+ {
715
+ "current": 2649.998,
716
+ "min": 0.0,
717
+ "max": 0.0
718
+ },
719
+ {
720
+ "current": 2649.998,
721
+ "min": 0.0,
722
+ "max": 0.0
723
+ },
724
+ {
725
+ "current": 2649.998,
726
+ "min": 0.0,
727
+ "max": 0.0
728
+ },
729
+ {
730
+ "current": 3597.822,
731
+ "min": 0.0,
732
+ "max": 0.0
733
+ },
734
+ {
735
+ "current": 2649.998,
736
+ "min": 0.0,
737
+ "max": 0.0
738
+ },
739
+ {
740
+ "current": 2649.998,
741
+ "min": 0.0,
742
+ "max": 0.0
743
+ },
744
+ {
745
+ "current": 2649.998,
746
+ "min": 0.0,
747
+ "max": 0.0
748
+ },
749
+ {
750
+ "current": 2649.998,
751
+ "min": 0.0,
752
+ "max": 0.0
753
+ },
754
+ {
755
+ "current": 2649.998,
756
+ "min": 0.0,
757
+ "max": 0.0
758
+ },
759
+ {
760
+ "current": 2649.998,
761
+ "min": 0.0,
762
+ "max": 0.0
763
+ },
764
+ {
765
+ "current": 2649.998,
766
+ "min": 0.0,
767
+ "max": 0.0
768
+ },
769
+ {
770
+ "current": 2649.998,
771
+ "min": 0.0,
772
+ "max": 0.0
773
+ },
774
+ {
775
+ "current": 2649.998,
776
+ "min": 0.0,
777
+ "max": 0.0
778
+ },
779
+ {
780
+ "current": 2649.998,
781
+ "min": 0.0,
782
+ "max": 0.0
783
+ },
784
+ {
785
+ "current": 2649.998,
786
+ "min": 0.0,
787
+ "max": 0.0
788
+ },
789
+ {
790
+ "current": 2649.998,
791
+ "min": 0.0,
792
+ "max": 0.0
793
+ },
794
+ {
795
+ "current": 2649.998,
796
+ "min": 0.0,
797
+ "max": 0.0
798
+ },
799
+ {
800
+ "current": 2649.998,
801
+ "min": 0.0,
802
+ "max": 0.0
803
+ },
804
+ {
805
+ "current": 2649.998,
806
+ "min": 0.0,
807
+ "max": 0.0
808
+ },
809
+ {
810
+ "current": 2649.998,
811
+ "min": 0.0,
812
+ "max": 0.0
813
+ },
814
+ {
815
+ "current": 3593.276,
816
+ "min": 0.0,
817
+ "max": 0.0
818
+ },
819
+ {
820
+ "current": 2649.998,
821
+ "min": 0.0,
822
+ "max": 0.0
823
+ },
824
+ {
825
+ "current": 2649.998,
826
+ "min": 0.0,
827
+ "max": 0.0
828
+ },
829
+ {
830
+ "current": 2649.998,
831
+ "min": 0.0,
832
+ "max": 0.0
833
+ },
834
+ {
835
+ "current": 2649.998,
836
+ "min": 0.0,
837
+ "max": 0.0
838
+ },
839
+ {
840
+ "current": 2649.998,
841
+ "min": 0.0,
842
+ "max": 0.0
843
+ },
844
+ {
845
+ "current": 2649.998,
846
+ "min": 0.0,
847
+ "max": 0.0
848
+ },
849
+ {
850
+ "current": 2649.998,
851
+ "min": 0.0,
852
+ "max": 0.0
853
+ },
854
+ {
855
+ "current": 2649.998,
856
+ "min": 0.0,
857
+ "max": 0.0
858
+ },
859
+ {
860
+ "current": 2649.998,
861
+ "min": 0.0,
862
+ "max": 0.0
863
+ },
864
+ {
865
+ "current": 2649.998,
866
+ "min": 0.0,
867
+ "max": 0.0
868
+ },
869
+ {
870
+ "current": 2649.998,
871
+ "min": 0.0,
872
+ "max": 0.0
873
+ },
874
+ {
875
+ "current": 2649.998,
876
+ "min": 0.0,
877
+ "max": 0.0
878
+ },
879
+ {
880
+ "current": 2649.998,
881
+ "min": 0.0,
882
+ "max": 0.0
883
+ },
884
+ {
885
+ "current": 2649.998,
886
+ "min": 0.0,
887
+ "max": 0.0
888
+ },
889
+ {
890
+ "current": 2649.998,
891
+ "min": 0.0,
892
+ "max": 0.0
893
+ },
894
+ {
895
+ "current": 2649.998,
896
+ "min": 0.0,
897
+ "max": 0.0
898
+ },
899
+ {
900
+ "current": 2649.998,
901
+ "min": 0.0,
902
+ "max": 0.0
903
+ },
904
+ {
905
+ "current": 2649.998,
906
+ "min": 0.0,
907
+ "max": 0.0
908
+ },
909
+ {
910
+ "current": 3596.593,
911
+ "min": 0.0,
912
+ "max": 0.0
913
+ },
914
+ {
915
+ "current": 2649.998,
916
+ "min": 0.0,
917
+ "max": 0.0
918
+ },
919
+ {
920
+ "current": 3596.334,
921
+ "min": 0.0,
922
+ "max": 0.0
923
+ },
924
+ {
925
+ "current": 2649.998,
926
+ "min": 0.0,
927
+ "max": 0.0
928
+ },
929
+ {
930
+ "current": 2649.998,
931
+ "min": 0.0,
932
+ "max": 0.0
933
+ },
934
+ {
935
+ "current": 2649.998,
936
+ "min": 0.0,
937
+ "max": 0.0
938
+ },
939
+ {
940
+ "current": 2649.998,
941
+ "min": 0.0,
942
+ "max": 0.0
943
+ },
944
+ {
945
+ "current": 2649.998,
946
+ "min": 0.0,
947
+ "max": 0.0
948
+ },
949
+ {
950
+ "current": 2649.998,
951
+ "min": 0.0,
952
+ "max": 0.0
953
+ },
954
+ {
955
+ "current": 2649.998,
956
+ "min": 0.0,
957
+ "max": 0.0
958
+ },
959
+ {
960
+ "current": 2649.998,
961
+ "min": 0.0,
962
+ "max": 0.0
963
+ },
964
+ {
965
+ "current": 2649.998,
966
+ "min": 0.0,
967
+ "max": 0.0
968
+ },
969
+ {
970
+ "current": 2649.998,
971
+ "min": 0.0,
972
+ "max": 0.0
973
+ },
974
+ {
975
+ "current": 2649.998,
976
+ "min": 0.0,
977
+ "max": 0.0
978
+ },
979
+ {
980
+ "current": 2649.998,
981
+ "min": 0.0,
982
+ "max": 0.0
983
+ },
984
+ {
985
+ "current": 2649.998,
986
+ "min": 0.0,
987
+ "max": 0.0
988
+ }
989
+ ],
990
+ "disk": {
991
+ "/": {
992
+ "total": 232.4169158935547,
993
+ "used": 182.96668243408203
994
+ }
995
+ },
996
+ "gpu": "NVIDIA H100 80GB HBM3",
997
+ "gpu_count": 8,
998
+ "gpu_devices": [
999
+ {
1000
+ "name": "NVIDIA H100 80GB HBM3",
1001
+ "memory_total": 85520809984
1002
+ },
1003
+ {
1004
+ "name": "NVIDIA H100 80GB HBM3",
1005
+ "memory_total": 85520809984
1006
+ },
1007
+ {
1008
+ "name": "NVIDIA H100 80GB HBM3",
1009
+ "memory_total": 85520809984
1010
+ },
1011
+ {
1012
+ "name": "NVIDIA H100 80GB HBM3",
1013
+ "memory_total": 85520809984
1014
+ },
1015
+ {
1016
+ "name": "NVIDIA H100 80GB HBM3",
1017
+ "memory_total": 85520809984
1018
+ },
1019
+ {
1020
+ "name": "NVIDIA H100 80GB HBM3",
1021
+ "memory_total": 85520809984
1022
+ },
1023
+ {
1024
+ "name": "NVIDIA H100 80GB HBM3",
1025
+ "memory_total": 85520809984
1026
+ },
1027
+ {
1028
+ "name": "NVIDIA H100 80GB HBM3",
1029
+ "memory_total": 85520809984
1030
+ }
1031
+ ],
1032
+ "memory": {
1033
+ "total": 1999.962516784668
1034
+ }
1035
+ }
MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/wandb-summary.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"_wandb": {"runtime": 533}}
MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/logs/debug-internal.log ADDED
@@ -0,0 +1,432 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2024-06-18 16:50:36,801 INFO StreamThr :3360594 [internal.py:wandb_internal():85] W&B internal server running at pid: 3360594, started at: 2024-06-18 16:50:36.796840
2
+ 2024-06-18 16:50:36,801 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status
3
+ 2024-06-18 16:50:36,825 INFO WriterThread:3360594 [datastore.py:open_for_write():87] open: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/run-testing-tt2.wandb
4
+ 2024-06-18 16:50:36,829 DEBUG SenderThread:3360594 [sender.py:send():379] send: header
5
+ 2024-06-18 16:50:36,897 DEBUG SenderThread:3360594 [sender.py:send():379] send: run
6
+ 2024-06-18 16:50:36,913 INFO SenderThread:3360594 [sender.py:_setup_resume():749] checking resume status for None/mindeye_semantic_cluster/testing-tt2
7
+ 2024-06-18 16:50:37,461 INFO SenderThread:3360594 [dir_watcher.py:__init__():211] watching files in: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files
8
+ 2024-06-18 16:50:37,462 INFO SenderThread:3360594 [sender.py:_start_run_threads():1188] run started: testing-tt2 with start time 1718729436.80175
9
+ 2024-06-18 16:50:37,497 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: check_version
10
+ 2024-06-18 16:50:37,497 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: check_version
11
+ 2024-06-18 16:50:37,575 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: run_start
12
+ 2024-06-18 16:50:37,659 DEBUG HandlerThread:3360594 [system_info.py:__init__():26] System info init
13
+ 2024-06-18 16:50:37,659 DEBUG HandlerThread:3360594 [system_info.py:__init__():41] System info init done
14
+ 2024-06-18 16:50:37,659 INFO HandlerThread:3360594 [system_monitor.py:start():194] Starting system monitor
15
+ 2024-06-18 16:50:37,659 INFO SystemMonitor:3360594 [system_monitor.py:_start():158] Starting system asset monitoring threads
16
+ 2024-06-18 16:50:37,659 INFO HandlerThread:3360594 [system_monitor.py:probe():214] Collecting system info
17
+ 2024-06-18 16:50:37,660 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started cpu monitoring
18
+ 2024-06-18 16:50:37,660 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started disk monitoring
19
+ 2024-06-18 16:50:37,661 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started gpu monitoring
20
+ 2024-06-18 16:50:37,661 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started memory monitoring
21
+ 2024-06-18 16:50:37,661 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started network monitoring
22
+ 2024-06-18 16:50:37,724 DEBUG HandlerThread:3360594 [system_info.py:probe():152] Probing system
23
+ 2024-06-18 16:50:37,761 DEBUG HandlerThread:3360594 [system_info.py:_probe_git():137] Probing git
24
+ 2024-06-18 16:50:37,785 DEBUG HandlerThread:3360594 [system_info.py:_probe_git():145] Probing git done
25
+ 2024-06-18 16:50:37,785 DEBUG HandlerThread:3360594 [system_info.py:probe():200] Probing system done
26
+ 2024-06-18 16:50:37,785 DEBUG HandlerThread:3360594 [system_monitor.py:probe():223] {'os': 'Linux-5.15.0-1058-aws-x86_64-with-glibc2.31', 'python': '3.11.9', 'heartbeatAt': '2024-06-18T16:50:37.724201', 'startedAt': '2024-06-18T16:50:36.657596', 'docker': None, 'cuda': None, 'args': (), 'state': 'running', 'program': 'ckadirt/MindEyeV2/src/TrainCluster-Copy2.ipynb', 'codePathLocal': None, 'root': '/weka/proj-fmri/ckadirt/MindEyeV2', 'git': {'remote': 'https://github.com/MedARC-AI/MindEyeV2.git', 'commit': 'a3588f0fadc81bdb0cc3e15993c01f8dd64dc7fe'}, 'email': None, 'host': 'ip-10-0-159-181', 'username': 'ckadirt', 'executable': '/admin/home-ckadirt/fmri/bin/python3.11', 'cpu_count': 96, 'cpu_count_logical': 192, 'cpu_freq': {'current': 2737.5654166666754, 'min': 0.0, 'max': 0.0}, 'cpu_freq_per_core': [{'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3599.552, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3571.159, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3597.82, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3599.455, 'min': 0.0, 'max': 0.0}, {'current': 3598.843, 'min': 0.0, 'max': 0.0}, {'current': 3598.67, 'min': 0.0, 'max': 0.0}, {'current': 3599.596, 'min': 0.0, 'max': 0.0}, {'current': 3597.56, 'min': 0.0, 'max': 0.0}, {'current': 3597.635, 'min': 0.0, 'max': 0.0}, {'current': 3597.882, 'min': 0.0, 'max': 0.0}, {'current': 3597.88, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3504.795, 'min': 0.0, 'max': 0.0}, {'current': 3548.68, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3597.822, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3593.276, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3596.593, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 3596.334, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}, {'current': 2649.998, 'min': 0.0, 'max': 0.0}], 'disk': {'/': {'total': 232.4169158935547, 'used': 182.96668243408203}}, 'gpu': 'NVIDIA H100 80GB HBM3', 'gpu_count': 8, 'gpu_devices': [{'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}, {'name': 'NVIDIA H100 80GB HBM3', 'memory_total': 85520809984}], 'memory': {'total': 1999.962516784668}}
27
+ 2024-06-18 16:50:37,785 INFO HandlerThread:3360594 [system_monitor.py:probe():224] Finished collecting system info
28
+ 2024-06-18 16:50:37,785 INFO HandlerThread:3360594 [system_monitor.py:probe():227] Publishing system info
29
+ 2024-06-18 16:50:37,786 DEBUG HandlerThread:3360594 [system_info.py:_save_code():44] Saving code
30
+ 2024-06-18 16:50:37,786 WARNING HandlerThread:3360594 [system_info.py:_save_code():46] unable to save code -- program entry not found
31
+ 2024-06-18 16:50:37,786 DEBUG HandlerThread:3360594 [system_info.py:_save_patches():84] Saving git patches
32
+ 2024-06-18 16:50:38,466 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/diff.patch
33
+ 2024-06-18 16:50:38,528 DEBUG HandlerThread:3360594 [system_info.py:_save_patches():126] Saving git patches done
34
+ 2024-06-18 16:50:38,539 INFO HandlerThread:3360594 [system_monitor.py:probe():229] Finished publishing system info
35
+ 2024-06-18 16:50:38,551 DEBUG SenderThread:3360594 [sender.py:send():379] send: files
36
+ 2024-06-18 16:50:38,551 INFO SenderThread:3360594 [sender.py:_save_file():1454] saving file wandb-metadata.json with policy now
37
+ 2024-06-18 16:50:38,551 INFO SenderThread:3360594 [sender.py:_save_file():1454] saving file diff.patch with policy now
38
+ 2024-06-18 16:50:39,061 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: python_packages
39
+ 2024-06-18 16:50:39,061 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: python_packages
40
+ 2024-06-18 16:50:39,062 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
41
+ 2024-06-18 16:50:39,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: internal_messages
42
+ 2024-06-18 16:50:39,071 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
43
+ 2024-06-18 16:50:39,073 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: pause
44
+ 2024-06-18 16:50:39,073 INFO HandlerThread:3360594 [handler.py:handle_request_pause():724] stopping system metrics thread
45
+ 2024-06-18 16:50:39,073 INFO HandlerThread:3360594 [system_monitor.py:finish():203] Stopping system monitor
46
+ 2024-06-18 16:50:39,073 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():172] Starting system metrics aggregation loop
47
+ 2024-06-18 16:50:39,074 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():179] Finished system metrics aggregation loop
48
+ 2024-06-18 16:50:39,074 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined cpu monitor
49
+ 2024-06-18 16:50:39,074 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():183] Publishing last batch of metrics
50
+ 2024-06-18 16:50:39,074 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined disk monitor
51
+ 2024-06-18 16:50:39,088 INFO wandb-upload_0:3360594 [upload_job.py:push():130] Uploaded file /tmp/tmp1uqtk8vuwandb/mfd8w0e8-wandb-metadata.json
52
+ 2024-06-18 16:50:39,247 DEBUG SenderThread:3360594 [sender.py:send():379] send: telemetry
53
+ 2024-06-18 16:50:39,298 INFO wandb-upload_1:3360594 [upload_job.py:push():130] Uploaded file /tmp/tmp1uqtk8vuwandb/z6tbxjy6-diff.patch
54
+ 2024-06-18 16:50:39,471 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/wandb-metadata.json
55
+ 2024-06-18 16:50:39,471 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/requirements.txt
56
+ 2024-06-18 16:50:41,255 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined gpu monitor
57
+ 2024-06-18 16:50:41,255 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined memory monitor
58
+ 2024-06-18 16:50:41,255 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined network monitor
59
+ 2024-06-18 16:50:41,256 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: resume
60
+ 2024-06-18 16:50:41,256 INFO HandlerThread:3360594 [handler.py:handle_request_resume():715] starting system metrics thread
61
+ 2024-06-18 16:50:41,256 INFO HandlerThread:3360594 [system_monitor.py:start():194] Starting system monitor
62
+ 2024-06-18 16:50:41,256 INFO SystemMonitor:3360594 [system_monitor.py:_start():158] Starting system asset monitoring threads
63
+ 2024-06-18 16:50:41,256 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
64
+ 2024-06-18 16:50:41,256 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: pause
65
+ 2024-06-18 16:50:41,257 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started cpu monitoring
66
+ 2024-06-18 16:50:41,258 INFO HandlerThread:3360594 [handler.py:handle_request_pause():724] stopping system metrics thread
67
+ 2024-06-18 16:50:41,258 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started disk monitoring
68
+ 2024-06-18 16:50:41,259 INFO HandlerThread:3360594 [system_monitor.py:finish():203] Stopping system monitor
69
+ 2024-06-18 16:50:41,259 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started gpu monitoring
70
+ 2024-06-18 16:50:41,259 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():172] Starting system metrics aggregation loop
71
+ 2024-06-18 16:50:41,259 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():179] Finished system metrics aggregation loop
72
+ 2024-06-18 16:50:41,259 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():183] Publishing last batch of metrics
73
+ 2024-06-18 16:50:41,261 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined cpu monitor
74
+ 2024-06-18 16:50:41,263 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined disk monitor
75
+ 2024-06-18 16:50:43,215 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined gpu monitor
76
+ 2024-06-18 16:50:43,215 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: resume
77
+ 2024-06-18 16:50:43,215 INFO HandlerThread:3360594 [handler.py:handle_request_resume():715] starting system metrics thread
78
+ 2024-06-18 16:50:43,215 INFO HandlerThread:3360594 [system_monitor.py:start():194] Starting system monitor
79
+ 2024-06-18 16:50:43,216 INFO SystemMonitor:3360594 [system_monitor.py:_start():158] Starting system asset monitoring threads
80
+ 2024-06-18 16:50:43,216 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: pause
81
+ 2024-06-18 16:50:43,216 INFO HandlerThread:3360594 [handler.py:handle_request_pause():724] stopping system metrics thread
82
+ 2024-06-18 16:50:43,216 INFO HandlerThread:3360594 [system_monitor.py:finish():203] Stopping system monitor
83
+ 2024-06-18 16:50:43,216 WARNING HandlerThread:3360594 [interfaces.py:finish():205] Failed to finish cpu monitoring: cannot join thread before it is started
84
+ 2024-06-18 16:50:43,216 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started cpu monitoring
85
+ 2024-06-18 16:50:43,216 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():172] Starting system metrics aggregation loop
86
+ 2024-06-18 16:50:43,216 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():179] Finished system metrics aggregation loop
87
+ 2024-06-18 16:50:43,216 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():183] Publishing last batch of metrics
88
+ 2024-06-18 16:50:43,218 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: resume
89
+ 2024-06-18 16:50:43,218 INFO HandlerThread:3360594 [handler.py:handle_request_resume():715] starting system metrics thread
90
+ 2024-06-18 16:50:43,218 INFO HandlerThread:3360594 [system_monitor.py:start():194] Starting system monitor
91
+ 2024-06-18 16:50:43,218 INFO SystemMonitor:3360594 [system_monitor.py:_start():158] Starting system asset monitoring threads
92
+ 2024-06-18 16:50:43,218 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: pause
93
+ 2024-06-18 16:50:43,218 INFO HandlerThread:3360594 [handler.py:handle_request_pause():724] stopping system metrics thread
94
+ 2024-06-18 16:50:43,218 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started cpu monitoring
95
+ 2024-06-18 16:50:43,219 INFO HandlerThread:3360594 [system_monitor.py:finish():203] Stopping system monitor
96
+ 2024-06-18 16:50:43,219 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started disk monitoring
97
+ 2024-06-18 16:50:43,219 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():172] Starting system metrics aggregation loop
98
+ 2024-06-18 16:50:43,219 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():179] Finished system metrics aggregation loop
99
+ 2024-06-18 16:50:43,219 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():183] Publishing last batch of metrics
100
+ 2024-06-18 16:50:43,222 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined cpu monitor
101
+ 2024-06-18 16:50:43,223 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined disk monitor
102
+ 2024-06-18 16:50:43,223 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: resume
103
+ 2024-06-18 16:50:43,223 INFO HandlerThread:3360594 [handler.py:handle_request_resume():715] starting system metrics thread
104
+ 2024-06-18 16:50:43,223 INFO HandlerThread:3360594 [system_monitor.py:start():194] Starting system monitor
105
+ 2024-06-18 16:50:43,223 INFO SystemMonitor:3360594 [system_monitor.py:_start():158] Starting system asset monitoring threads
106
+ 2024-06-18 16:50:43,223 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: pause
107
+ 2024-06-18 16:50:43,223 INFO HandlerThread:3360594 [handler.py:handle_request_pause():724] stopping system metrics thread
108
+ 2024-06-18 16:50:43,223 INFO HandlerThread:3360594 [system_monitor.py:finish():203] Stopping system monitor
109
+ 2024-06-18 16:50:43,223 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started cpu monitoring
110
+ 2024-06-18 16:50:43,231 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined cpu monitor
111
+ 2024-06-18 16:50:43,231 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():172] Starting system metrics aggregation loop
112
+ 2024-06-18 16:50:43,237 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():179] Finished system metrics aggregation loop
113
+ 2024-06-18 16:50:43,237 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():183] Publishing last batch of metrics
114
+ 2024-06-18 16:50:43,243 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: resume
115
+ 2024-06-18 16:50:43,243 INFO HandlerThread:3360594 [handler.py:handle_request_resume():715] starting system metrics thread
116
+ 2024-06-18 16:50:43,243 INFO HandlerThread:3360594 [system_monitor.py:start():194] Starting system monitor
117
+ 2024-06-18 16:50:43,248 INFO SystemMonitor:3360594 [system_monitor.py:_start():158] Starting system asset monitoring threads
118
+ 2024-06-18 16:50:43,248 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: internal_messages
119
+ 2024-06-18 16:50:43,254 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
120
+ 2024-06-18 16:50:43,260 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started cpu monitoring
121
+ 2024-06-18 16:50:43,260 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
122
+ 2024-06-18 16:50:43,261 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
123
+ 2024-06-18 16:50:43,263 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
124
+ 2024-06-18 16:50:43,263 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started disk monitoring
125
+ 2024-06-18 16:50:43,276 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started gpu monitoring
126
+ 2024-06-18 16:50:43,277 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started memory monitoring
127
+ 2024-06-18 16:50:43,278 INFO SystemMonitor:3360594 [interfaces.py:start():188] Started network monitoring
128
+ 2024-06-18 16:50:43,522 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
129
+ 2024-06-18 16:50:45,550 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
130
+ 2024-06-18 16:50:48,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
131
+ 2024-06-18 16:50:53,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
132
+ 2024-06-18 16:50:54,062 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
133
+ 2024-06-18 16:50:54,062 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
134
+ 2024-06-18 16:50:58,239 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
135
+ 2024-06-18 16:51:04,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
136
+ 2024-06-18 16:51:09,062 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
137
+ 2024-06-18 16:51:09,062 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
138
+ 2024-06-18 16:51:09,276 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
139
+ 2024-06-18 16:51:09,961 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/config.yaml
140
+ 2024-06-18 16:51:15,064 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
141
+ 2024-06-18 16:51:20,064 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
142
+ 2024-06-18 16:51:24,062 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
143
+ 2024-06-18 16:51:24,062 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
144
+ 2024-06-18 16:51:25,240 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
145
+ 2024-06-18 16:51:31,065 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
146
+ 2024-06-18 16:51:36,065 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
147
+ 2024-06-18 16:51:39,062 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
148
+ 2024-06-18 16:51:39,062 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
149
+ 2024-06-18 16:51:41,240 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
150
+ 2024-06-18 16:51:43,278 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():172] Starting system metrics aggregation loop
151
+ 2024-06-18 16:51:43,280 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
152
+ 2024-06-18 16:51:47,065 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
153
+ 2024-06-18 16:51:52,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
154
+ 2024-06-18 16:51:54,062 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
155
+ 2024-06-18 16:51:54,062 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
156
+ 2024-06-18 16:51:57,241 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
157
+ 2024-06-18 16:52:03,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
158
+ 2024-06-18 16:52:08,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
159
+ 2024-06-18 16:52:09,062 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
160
+ 2024-06-18 16:52:09,063 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
161
+ 2024-06-18 16:52:13,241 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
162
+ 2024-06-18 16:52:13,298 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
163
+ 2024-06-18 16:52:19,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
164
+ 2024-06-18 16:52:24,062 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
165
+ 2024-06-18 16:52:24,063 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
166
+ 2024-06-18 16:52:24,240 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
167
+ 2024-06-18 16:52:30,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
168
+ 2024-06-18 16:52:35,068 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
169
+ 2024-06-18 16:52:39,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
170
+ 2024-06-18 16:52:39,063 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
171
+ 2024-06-18 16:52:40,241 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
172
+ 2024-06-18 16:52:43,283 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
173
+ 2024-06-18 16:52:46,067 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
174
+ 2024-06-18 16:52:52,067 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
175
+ 2024-06-18 16:52:54,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
176
+ 2024-06-18 16:52:54,063 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
177
+ 2024-06-18 16:52:57,240 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
178
+ 2024-06-18 16:53:03,068 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
179
+ 2024-06-18 16:53:09,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
180
+ 2024-06-18 16:53:09,063 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
181
+ 2024-06-18 16:53:09,241 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
182
+ 2024-06-18 16:53:13,285 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
183
+ 2024-06-18 16:53:15,068 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
184
+ 2024-06-18 16:53:21,068 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
185
+ 2024-06-18 16:53:24,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
186
+ 2024-06-18 16:53:24,063 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
187
+ 2024-06-18 16:53:26,241 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
188
+ 2024-06-18 16:53:32,068 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
189
+ 2024-06-18 16:53:37,068 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
190
+ 2024-06-18 16:53:39,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
191
+ 2024-06-18 16:53:39,063 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
192
+ 2024-06-18 16:53:42,241 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
193
+ 2024-06-18 16:53:43,289 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
194
+ 2024-06-18 16:53:48,068 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
195
+ 2024-06-18 16:53:53,070 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
196
+ 2024-06-18 16:53:54,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
197
+ 2024-06-18 16:53:54,063 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
198
+ 2024-06-18 16:53:58,241 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
199
+ 2024-06-18 16:54:04,069 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
200
+ 2024-06-18 16:54:09,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
201
+ 2024-06-18 16:54:09,063 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
202
+ 2024-06-18 16:54:09,240 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
203
+ 2024-06-18 16:54:13,293 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
204
+ 2024-06-18 16:54:15,069 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
205
+ 2024-06-18 16:54:20,069 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
206
+ 2024-06-18 16:54:24,063 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
207
+ 2024-06-18 16:54:24,064 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
208
+ 2024-06-18 16:54:25,241 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
209
+ 2024-06-18 16:54:31,069 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
210
+ 2024-06-18 16:54:36,070 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
211
+ 2024-06-18 16:54:39,064 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
212
+ 2024-06-18 16:54:39,064 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
213
+ 2024-06-18 16:54:41,342 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
214
+ 2024-06-18 16:54:43,292 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
215
+ 2024-06-18 16:54:47,070 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
216
+ 2024-06-18 16:54:52,070 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
217
+ 2024-06-18 16:54:54,064 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
218
+ 2024-06-18 16:54:54,064 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
219
+ 2024-06-18 16:54:57,241 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
220
+ 2024-06-18 16:55:03,075 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
221
+ 2024-06-18 16:55:09,064 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
222
+ 2024-06-18 16:55:09,064 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
223
+ 2024-06-18 16:55:09,254 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
224
+ 2024-06-18 16:55:13,294 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
225
+ 2024-06-18 16:55:14,062 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
226
+ 2024-06-18 16:55:15,070 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
227
+ 2024-06-18 16:55:16,149 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
228
+ 2024-06-18 16:55:20,070 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
229
+ 2024-06-18 16:55:24,064 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
230
+ 2024-06-18 16:55:24,064 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
231
+ 2024-06-18 16:55:25,242 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
232
+ 2024-06-18 16:55:29,380 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
233
+ 2024-06-18 16:55:31,071 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
234
+ 2024-06-18 16:55:35,464 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
235
+ 2024-06-18 16:55:36,071 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
236
+ 2024-06-18 16:55:39,064 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
237
+ 2024-06-18 16:55:39,065 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
238
+ 2024-06-18 16:55:41,242 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
239
+ 2024-06-18 16:55:43,295 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
240
+ 2024-06-18 16:55:43,606 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
241
+ 2024-06-18 16:55:47,071 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
242
+ 2024-06-18 16:55:52,140 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
243
+ 2024-06-18 16:55:53,773 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
244
+ 2024-06-18 16:55:54,064 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
245
+ 2024-06-18 16:55:54,064 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
246
+ 2024-06-18 16:55:55,798 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
247
+ 2024-06-18 16:55:57,242 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
248
+ 2024-06-18 16:56:03,072 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
249
+ 2024-06-18 16:56:05,966 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
250
+ 2024-06-18 16:56:08,396 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
251
+ 2024-06-18 16:56:09,064 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
252
+ 2024-06-18 16:56:09,065 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
253
+ 2024-06-18 16:56:13,299 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
254
+ 2024-06-18 16:56:14,071 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
255
+ 2024-06-18 16:56:19,072 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
256
+ 2024-06-18 16:56:24,065 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
257
+ 2024-06-18 16:56:24,065 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
258
+ 2024-06-18 16:56:24,242 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
259
+ 2024-06-18 16:56:30,072 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
260
+ 2024-06-18 16:56:33,425 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
261
+ 2024-06-18 16:56:36,072 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
262
+ 2024-06-18 16:56:39,065 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
263
+ 2024-06-18 16:56:39,065 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
264
+ 2024-06-18 16:56:41,243 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
265
+ 2024-06-18 16:56:43,298 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
266
+ 2024-06-18 16:56:46,588 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
267
+ 2024-06-18 16:56:47,652 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
268
+ 2024-06-18 16:56:52,072 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
269
+ 2024-06-18 16:56:54,065 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
270
+ 2024-06-18 16:56:54,065 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
271
+ 2024-06-18 16:56:57,242 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
272
+ 2024-06-18 16:57:03,073 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
273
+ 2024-06-18 16:57:09,065 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
274
+ 2024-06-18 16:57:09,065 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
275
+ 2024-06-18 16:57:09,242 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
276
+ 2024-06-18 16:57:13,300 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
277
+ 2024-06-18 16:57:15,073 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
278
+ 2024-06-18 16:57:20,844 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
279
+ 2024-06-18 16:57:22,223 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
280
+ 2024-06-18 16:57:24,065 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
281
+ 2024-06-18 16:57:24,066 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
282
+ 2024-06-18 16:57:26,243 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
283
+ 2024-06-18 16:57:29,350 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
284
+ 2024-06-18 16:57:32,073 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
285
+ 2024-06-18 16:57:38,073 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
286
+ 2024-06-18 16:57:39,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
287
+ 2024-06-18 16:57:39,066 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
288
+ 2024-06-18 16:57:43,270 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
289
+ 2024-06-18 16:57:43,301 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
290
+ 2024-06-18 16:57:47,630 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
291
+ 2024-06-18 16:57:48,728 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
292
+ 2024-06-18 16:57:53,734 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
293
+ 2024-06-18 16:57:54,056 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
294
+ 2024-06-18 16:57:54,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
295
+ 2024-06-18 16:57:54,066 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
296
+ 2024-06-18 16:57:59,073 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
297
+ 2024-06-18 16:58:04,074 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
298
+ 2024-06-18 16:58:09,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
299
+ 2024-06-18 16:58:09,066 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
300
+ 2024-06-18 16:58:09,168 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
301
+ 2024-06-18 16:58:13,305 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
302
+ 2024-06-18 16:58:15,074 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
303
+ 2024-06-18 16:58:20,074 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
304
+ 2024-06-18 16:58:24,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
305
+ 2024-06-18 16:58:24,066 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
306
+ 2024-06-18 16:58:25,245 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
307
+ 2024-06-18 16:58:31,075 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
308
+ 2024-06-18 16:58:37,075 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
309
+ 2024-06-18 16:58:39,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
310
+ 2024-06-18 16:58:39,066 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
311
+ 2024-06-18 16:58:42,244 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
312
+ 2024-06-18 16:58:43,306 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
313
+ 2024-06-18 16:58:48,075 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
314
+ 2024-06-18 16:58:53,078 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
315
+ 2024-06-18 16:58:54,066 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
316
+ 2024-06-18 16:58:54,067 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
317
+ 2024-06-18 16:58:58,244 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
318
+ 2024-06-18 16:59:04,079 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
319
+ 2024-06-18 16:59:09,067 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
320
+ 2024-06-18 16:59:09,068 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
321
+ 2024-06-18 16:59:09,246 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
322
+ 2024-06-18 16:59:13,307 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
323
+ 2024-06-18 16:59:15,079 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
324
+ 2024-06-18 16:59:21,079 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
325
+ 2024-06-18 16:59:24,067 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: stop_status
326
+ 2024-06-18 16:59:24,067 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: stop_status
327
+ 2024-06-18 16:59:26,244 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
328
+ 2024-06-18 16:59:29,491 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: pause
329
+ 2024-06-18 16:59:29,491 INFO HandlerThread:3360594 [handler.py:handle_request_pause():724] stopping system metrics thread
330
+ 2024-06-18 16:59:29,492 INFO HandlerThread:3360594 [system_monitor.py:finish():203] Stopping system monitor
331
+ 2024-06-18 16:59:29,492 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():179] Finished system metrics aggregation loop
332
+ 2024-06-18 16:59:29,492 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined cpu monitor
333
+ 2024-06-18 16:59:29,493 DEBUG SystemMonitor:3360594 [system_monitor.py:_start():183] Publishing last batch of metrics
334
+ 2024-06-18 16:59:29,493 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined disk monitor
335
+ 2024-06-18 16:59:30,299 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
336
+ 2024-06-18 16:59:31,533 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined gpu monitor
337
+ 2024-06-18 16:59:31,533 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined memory monitor
338
+ 2024-06-18 16:59:31,533 INFO HandlerThread:3360594 [interfaces.py:finish():200] Joined network monitor
339
+ 2024-06-18 16:59:31,533 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: poll_exit
340
+ 2024-06-18 16:59:31,534 DEBUG SenderThread:3360594 [sender.py:send():379] send: stats
341
+ 2024-06-18 16:59:31,534 DEBUG SenderThread:3360594 [sender.py:send():379] send: exit
342
+ 2024-06-18 16:59:31,534 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
343
+ 2024-06-18 16:59:31,534 INFO SenderThread:3360594 [sender.py:send_exit():586] handling exit code: 0
344
+ 2024-06-18 16:59:31,535 INFO SenderThread:3360594 [sender.py:send_exit():588] handling runtime: 533
345
+ 2024-06-18 16:59:31,539 INFO SenderThread:3360594 [sender.py:_save_file():1454] saving file wandb-summary.json with policy end
346
+ 2024-06-18 16:59:31,539 INFO SenderThread:3360594 [sender.py:send_exit():594] send defer
347
+ 2024-06-18 16:59:31,539 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: poll_exit
348
+ 2024-06-18 16:59:31,539 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: defer
349
+ 2024-06-18 16:59:31,540 INFO HandlerThread:3360594 [handler.py:handle_request_defer():184] handle defer: 0
350
+ 2024-06-18 16:59:31,540 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: defer
351
+ 2024-06-18 16:59:31,540 INFO SenderThread:3360594 [sender.py:send_request_defer():610] handle sender defer: 0
352
+ 2024-06-18 16:59:31,540 INFO SenderThread:3360594 [sender.py:transition_state():614] send defer: 1
353
+ 2024-06-18 16:59:31,540 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: defer
354
+ 2024-06-18 16:59:31,540 INFO HandlerThread:3360594 [handler.py:handle_request_defer():184] handle defer: 1
355
+ 2024-06-18 16:59:31,540 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: defer
356
+ 2024-06-18 16:59:31,540 INFO SenderThread:3360594 [sender.py:send_request_defer():610] handle sender defer: 1
357
+ 2024-06-18 16:59:31,540 INFO SenderThread:3360594 [sender.py:transition_state():614] send defer: 2
358
+ 2024-06-18 16:59:31,540 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: defer
359
+ 2024-06-18 16:59:31,540 INFO HandlerThread:3360594 [handler.py:handle_request_defer():184] handle defer: 2
360
+ 2024-06-18 16:59:31,540 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: defer
361
+ 2024-06-18 16:59:31,540 INFO SenderThread:3360594 [sender.py:send_request_defer():610] handle sender defer: 2
362
+ 2024-06-18 16:59:31,540 INFO SenderThread:3360594 [sender.py:transition_state():614] send defer: 3
363
+ 2024-06-18 16:59:31,540 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: defer
364
+ 2024-06-18 16:59:31,540 INFO HandlerThread:3360594 [handler.py:handle_request_defer():184] handle defer: 3
365
+ 2024-06-18 16:59:31,540 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: defer
366
+ 2024-06-18 16:59:31,540 INFO SenderThread:3360594 [sender.py:send_request_defer():610] handle sender defer: 3
367
+ 2024-06-18 16:59:31,540 INFO SenderThread:3360594 [sender.py:transition_state():614] send defer: 4
368
+ 2024-06-18 16:59:31,540 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: defer
369
+ 2024-06-18 16:59:31,541 INFO HandlerThread:3360594 [handler.py:handle_request_defer():184] handle defer: 4
370
+ 2024-06-18 16:59:31,541 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: defer
371
+ 2024-06-18 16:59:31,541 INFO SenderThread:3360594 [sender.py:send_request_defer():610] handle sender defer: 4
372
+ 2024-06-18 16:59:31,541 INFO SenderThread:3360594 [sender.py:transition_state():614] send defer: 5
373
+ 2024-06-18 16:59:31,541 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: defer
374
+ 2024-06-18 16:59:31,541 INFO HandlerThread:3360594 [handler.py:handle_request_defer():184] handle defer: 5
375
+ 2024-06-18 16:59:31,541 DEBUG SenderThread:3360594 [sender.py:send():379] send: summary
376
+ 2024-06-18 16:59:31,552 INFO SenderThread:3360594 [sender.py:_save_file():1454] saving file wandb-summary.json with policy end
377
+ 2024-06-18 16:59:31,552 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: defer
378
+ 2024-06-18 16:59:31,552 INFO SenderThread:3360594 [sender.py:send_request_defer():610] handle sender defer: 5
379
+ 2024-06-18 16:59:31,552 INFO SenderThread:3360594 [sender.py:transition_state():614] send defer: 6
380
+ 2024-06-18 16:59:31,552 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: defer
381
+ 2024-06-18 16:59:31,552 INFO HandlerThread:3360594 [handler.py:handle_request_defer():184] handle defer: 6
382
+ 2024-06-18 16:59:31,552 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: defer
383
+ 2024-06-18 16:59:31,552 INFO SenderThread:3360594 [sender.py:send_request_defer():610] handle sender defer: 6
384
+ 2024-06-18 16:59:31,552 INFO SenderThread:3360594 [sender.py:transition_state():614] send defer: 7
385
+ 2024-06-18 16:59:31,552 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: status_report
386
+ 2024-06-18 16:59:31,552 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: defer
387
+ 2024-06-18 16:59:31,552 INFO HandlerThread:3360594 [handler.py:handle_request_defer():184] handle defer: 7
388
+ 2024-06-18 16:59:31,552 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: defer
389
+ 2024-06-18 16:59:31,552 INFO SenderThread:3360594 [sender.py:send_request_defer():610] handle sender defer: 7
390
+ 2024-06-18 16:59:32,325 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_created():271] file/dir created: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/wandb-summary.json
391
+ 2024-06-18 16:59:32,499 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: poll_exit
392
+ 2024-06-18 16:59:33,598 INFO SenderThread:3360594 [sender.py:transition_state():614] send defer: 8
393
+ 2024-06-18 16:59:33,598 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: poll_exit
394
+ 2024-06-18 16:59:33,598 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: defer
395
+ 2024-06-18 16:59:33,599 INFO HandlerThread:3360594 [handler.py:handle_request_defer():184] handle defer: 8
396
+ 2024-06-18 16:59:33,599 DEBUG SenderThread:3360594 [sender.py:send_request():406] send_request: defer
397
+ 2024-06-18 16:59:33,599 INFO SenderThread:3360594 [sender.py:send_request_defer():610] handle sender defer: 8
398
+ 2024-06-18 16:59:33,599 INFO SenderThread:3360594 [job_builder.py:build():440] Attempting to build job artifact
399
+ 2024-06-18 16:59:33,602 INFO SenderThread:3360594 [job_builder.py:_get_source_type():569] is repo sourced job
400
+ 2024-06-18 16:59:33,602 INFO SenderThread:3360594 [job_builder.py:_get_program_relpath():587] run is notebook based run
401
+ 2024-06-18 16:59:33,629 INFO SenderThread:3360594 [job_builder.py:build():545] adding wandb-job metadata file
402
+ 2024-06-18 16:59:33,659 INFO SenderThread:3360594 [sender.py:transition_state():614] send defer: 9
403
+ 2024-06-18 16:59:33,659 DEBUG SenderThread:3360594 [sender.py:send():379] send: artifact
404
+ 2024-06-18 16:59:33,659 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: defer
405
+ 2024-06-18 16:59:33,661 INFO HandlerThread:3360594 [handler.py:handle_request_defer():184] handle defer: 9
406
+ 2024-06-18 16:59:33,856 WARNING StreamThr :3360594 [internal.py:is_dead():413] Internal process exiting, parent pid 3353055 disappeared
407
+ 2024-06-18 16:59:33,856 ERROR StreamThr :3360594 [internal.py:wandb_internal():151] Internal process shutdown.
408
+ 2024-06-18 16:59:34,349 INFO Thread-12 :3360594 [dir_watcher.py:_on_file_modified():288] file/dir modified: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
409
+ 2024-06-18 16:59:34,474 INFO wandb-upload_0:3360594 [upload_job.py:push():88] Uploaded file /admin/home-ckadirt/.local/share/wandb/artifacts/staging/tmpwylhto1m
410
+ 2024-06-18 16:59:34,497 INFO wandb-upload_1:3360594 [upload_job.py:push():88] Uploaded file /tmp/tmpg9bai4xg/wandb-job.json
411
+ 2024-06-18 16:59:34,500 DEBUG HandlerThread:3360594 [handler.py:handle_request():158] handle_request: poll_exit
412
+ 2024-06-18 16:59:34,500 INFO HandlerThread:3360594 [handler.py:finish():882] shutting down handler
413
+ 2024-06-18 16:59:34,500 INFO WriterThread:3360594 [datastore.py:close():296] close: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/run-testing-tt2.wandb
414
+ 2024-06-18 16:59:34,579 INFO wandb-upload_2:3360594 [upload_job.py:push():88] Uploaded file /admin/home-ckadirt/.local/share/wandb/artifacts/staging/tmpf2z3dfgr
415
+ 2024-06-18 16:59:35,132 INFO SenderThread:3360594 [sender.py:send_artifact():1530] sent artifact job-https___github.com_MedARC-AI_MindEyeV2.git_ckadirt_MindEyeV2_src_TrainCluster-Copy2.ipynb - {'id': 'QXJ0aWZhY3Q6ODczNzEy', 'state': 'PENDING', 'artifactSequence': {'id': 'QXJ0aWZhY3RDb2xsZWN0aW9uOjQ2NzQw', 'latestArtifact': None}}
416
+ 2024-06-18 16:59:35,132 INFO SenderThread:3360594 [sender.py:finish():1608] shutting down sender
417
+ 2024-06-18 16:59:35,132 INFO SenderThread:3360594 [dir_watcher.py:finish():358] shutting down directory watcher
418
+ 2024-06-18 16:59:35,363 INFO SenderThread:3360594 [dir_watcher.py:finish():388] scan: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files
419
+ 2024-06-18 16:59:35,365 INFO SenderThread:3360594 [dir_watcher.py:finish():402] scan save: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/config.yaml config.yaml
420
+ 2024-06-18 16:59:35,365 INFO SenderThread:3360594 [dir_watcher.py:finish():402] scan save: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log output.log
421
+ 2024-06-18 16:59:35,365 INFO SenderThread:3360594 [dir_watcher.py:finish():402] scan save: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/wandb-summary.json wandb-summary.json
422
+ 2024-06-18 16:59:35,366 INFO SenderThread:3360594 [dir_watcher.py:finish():402] scan save: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/wandb-metadata.json wandb-metadata.json
423
+ 2024-06-18 16:59:35,368 INFO SenderThread:3360594 [dir_watcher.py:finish():402] scan save: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/diff.patch diff.patch
424
+ 2024-06-18 16:59:35,368 INFO SenderThread:3360594 [dir_watcher.py:finish():402] scan save: /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/requirements.txt requirements.txt
425
+ 2024-06-18 16:59:35,369 INFO SenderThread:3360594 [file_pusher.py:finish():169] shutting down file pusher
426
+ 2024-06-18 16:59:35,369 INFO SenderThread:3360594 [file_pusher.py:join():175] waiting for file pusher
427
+ 2024-06-18 16:59:35,541 INFO wandb-upload_0:3360594 [upload_job.py:push():130] Uploaded file /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/config.yaml
428
+ 2024-06-18 16:59:35,722 INFO wandb-upload_1:3360594 [upload_job.py:push():130] Uploaded file /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/wandb-summary.json
429
+ 2024-06-18 16:59:35,731 INFO wandb-upload_2:3360594 [upload_job.py:push():130] Uploaded file /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/output.log
430
+ 2024-06-18 16:59:35,756 INFO wandb-upload_3:3360594 [upload_job.py:push():130] Uploaded file /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/files/requirements.txt
431
+ 2024-06-18 16:59:36,370 INFO SenderThread:3360594 [file_stream.py:finish():601] file stream finish called
432
+ 2024-06-18 16:59:36,602 INFO SenderThread:3360594 [file_stream.py:finish():605] file stream finish is done
MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/logs/debug.log ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2024-06-18 16:50:36,773 INFO MainThread:3353055 [wandb_setup.py:_flush():76] Current SDK version is 0.17.1
2
+ 2024-06-18 16:50:36,773 INFO MainThread:3353055 [wandb_setup.py:_flush():76] Configure stats pid to 3353055
3
+ 2024-06-18 16:50:36,773 INFO MainThread:3353055 [wandb_setup.py:_flush():76] Loading settings from /admin/home-ckadirt/.config/wandb/settings
4
+ 2024-06-18 16:50:36,773 INFO MainThread:3353055 [wandb_setup.py:_flush():76] Loading settings from /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/settings
5
+ 2024-06-18 16:50:36,773 INFO MainThread:3353055 [wandb_setup.py:_flush():76] Loading settings from environment variables: {}
6
+ 2024-06-18 16:50:36,773 INFO MainThread:3353055 [wandb_setup.py:_flush():76] Inferring run settings from compute environment: {'program': '<python with no main file>'}
7
+ 2024-06-18 16:50:36,773 INFO MainThread:3353055 [wandb_setup.py:_flush():76] Applying login settings: {'base_url': 'https://stability.wandb.io'}
8
+ 2024-06-18 16:50:36,773 INFO MainThread:3353055 [wandb_setup.py:_flush():76] Applying login settings: {}
9
+ 2024-06-18 16:50:36,774 INFO MainThread:3353055 [wandb_init.py:_log_setup():520] Logging user logs to /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/logs/debug.log
10
+ 2024-06-18 16:50:36,774 INFO MainThread:3353055 [wandb_init.py:_log_setup():521] Logging internal logs to /weka/proj-fmri/ckadirt/MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/logs/debug-internal.log
11
+ 2024-06-18 16:50:36,774 INFO MainThread:3353055 [wandb_init.py:_jupyter_setup():466] configuring jupyter hooks <wandb.sdk.wandb_init._WandbInit object at 0x7f4377427f10>
12
+ 2024-06-18 16:50:36,775 INFO MainThread:3353055 [wandb_init.py:init():560] calling init triggers
13
+ 2024-06-18 16:50:36,775 INFO MainThread:3353055 [wandb_init.py:init():567] wandb.init called with sweep_config: {}
14
+ config: {'model_name': 'testing-tt2', 'global_batch_size': 16, 'batch_size': 16, 'num_epochs': 150, 'num_sessions': 40, 'num_params': 486928065, 'clip_scale': 1.0, 'prior_scale': 30.0, 'blur_scale': 0.5, 'use_image_aug': False, 'max_lr': 3e-05, 'mixup_pct': 0.33, 'num_samples_per_epoch': 30000, 'num_test': 3000, 'ckpt_interval': 999, 'ckpt_saving': False, 'seed': 42, 'distributed': False, 'num_devices': 1, 'world_size': 1, 'train_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/train/{0..39}.tar', 'test_url': '/weka/proj-medarc/shared/mindeyev2_dataset/wds/subj01/new_test/0.tar'}
15
+ 2024-06-18 16:50:36,775 INFO MainThread:3353055 [wandb_init.py:init():610] starting backend
16
+ 2024-06-18 16:50:36,775 INFO MainThread:3353055 [wandb_init.py:init():614] setting up manager
17
+ 2024-06-18 16:50:36,796 INFO MainThread:3353055 [backend.py:_multiprocessing_setup():105] multiprocessing start_methods=fork,spawn,forkserver, using: spawn
18
+ 2024-06-18 16:50:36,800 INFO MainThread:3353055 [wandb_init.py:init():622] backend started and connected
19
+ 2024-06-18 16:50:36,824 INFO MainThread:3353055 [wandb_run.py:_label_probe_notebook():1334] probe notebook
20
+ 2024-06-18 16:50:36,825 INFO MainThread:3353055 [wandb_run.py:_label_probe_notebook():1344] Unable to probe notebook: 'NoneType' object has no attribute 'get'
21
+ 2024-06-18 16:50:36,825 INFO MainThread:3353055 [wandb_init.py:init():711] updated telemetry
22
+ 2024-06-18 16:50:36,896 INFO MainThread:3353055 [wandb_init.py:init():744] communicating run to backend with 90.0 second timeout
23
+ 2024-06-18 16:50:37,496 INFO MainThread:3353055 [wandb_run.py:_on_init():2402] communicating current version
24
+ 2024-06-18 16:50:37,558 INFO MainThread:3353055 [wandb_run.py:_on_init():2411] got version response upgrade_message: "wandb version 0.17.2 is available! To upgrade, please run:\n $ pip install wandb --upgrade"
25
+
26
+ 2024-06-18 16:50:37,558 INFO MainThread:3353055 [wandb_init.py:init():795] starting run threads in backend
27
+ 2024-06-18 16:50:39,062 INFO MainThread:3353055 [wandb_run.py:_console_start():2380] atexit reg
28
+ 2024-06-18 16:50:39,062 INFO MainThread:3353055 [wandb_run.py:_redirect():2235] redirect: wrap_raw
29
+ 2024-06-18 16:50:39,062 INFO MainThread:3353055 [wandb_run.py:_redirect():2300] Wrapping output streams.
30
+ 2024-06-18 16:50:39,062 INFO MainThread:3353055 [wandb_run.py:_redirect():2325] Redirects installed.
31
+ 2024-06-18 16:50:39,068 INFO MainThread:3353055 [wandb_init.py:init():838] run started, returning control to user process
32
+ 2024-06-18 16:50:39,072 INFO MainThread:3353055 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster-Copy2.ipynb
33
+ 2024-06-18 16:50:39,073 INFO MainThread:3353055 [wandb_init.py:_pause_backend():431] pausing backend
34
+ 2024-06-18 16:50:39,157 INFO MainThread:3353055 [wandb_init.py:_resume_backend():436] resuming backend
35
+ 2024-06-18 16:50:39,158 INFO MainThread:3353055 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster-Copy2.ipynb
36
+ 2024-06-18 16:50:39,159 INFO MainThread:3353055 [wandb_init.py:_pause_backend():431] pausing backend
37
+ 2024-06-18 16:50:39,237 INFO MainThread:3353055 [wandb_init.py:_resume_backend():436] resuming backend
38
+ 2024-06-18 16:50:39,249 INFO MainThread:3353055 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster-Copy2.ipynb
39
+ 2024-06-18 16:50:39,253 INFO MainThread:3353055 [wandb_init.py:_pause_backend():431] pausing backend
40
+ 2024-06-18 16:50:39,338 INFO MainThread:3353055 [wandb_init.py:_resume_backend():436] resuming backend
41
+ 2024-06-18 16:50:39,509 INFO MainThread:3353055 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster-Copy2.ipynb
42
+ 2024-06-18 16:50:39,509 INFO MainThread:3353055 [wandb_init.py:_pause_backend():431] pausing backend
43
+ 2024-06-18 16:50:39,592 INFO MainThread:3353055 [wandb_init.py:_resume_backend():436] resuming backend
44
+ 2024-06-18 16:50:39,593 INFO MainThread:3353055 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster-Copy2.ipynb
45
+ 2024-06-18 16:50:39,594 INFO MainThread:3353055 [wandb_init.py:_pause_backend():431] pausing backend
46
+ 2024-06-18 16:50:39,686 INFO MainThread:3353055 [wandb_init.py:_resume_backend():436] resuming backend
47
+ 2024-06-18 16:59:29,490 INFO MainThread:3353055 [jupyter.py:_save_ipynb():383] looking for notebook: ckadirt/MindEyeV2/src/TrainCluster-Copy2.ipynb
48
+ 2024-06-18 16:59:29,491 INFO MainThread:3353055 [wandb_init.py:_pause_backend():431] pausing backend
MindEyeV2/src/wandb/run-20240618_165036-testing-tt2/run-testing-tt2.wandb ADDED
Binary file (161 kB). View file