Skip to content

Vjepa#13

Merged
aparnabg merged 7 commits into
mainfrom
vjepa
Jul 9, 2026
Merged

Vjepa#13
aparnabg merged 7 commits into
mainfrom
vjepa

Conversation

@aparnabg

@aparnabg aparnabg commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@aparnabg aparnabg self-assigned this Jul 9, 2026
@aparnabg
aparnabg merged commit 4581410 into main Jul 9, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces V-JEPA2 model variants, feature extraction, and probe training scripts for clip-level and frame-level action recognition, along with SLURM submission scripts and unit tests. The code review highlights several critical issues that need to be addressed: potential silent feature-to-metadata misalignments and dimension mismatch crashes due to improper exception handling; dimension mismatches where EMBED_DIM is set to 1408 instead of 1024 for ViT-H features; CPU compatibility failures caused by unconditional torch.float16 loading and .half() casting; potential crashes if bbox_map is empty; and portability issues from hardcoded absolute user paths in SLURM scripts.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +122 to +124
except Exception as e:
print(f" Error at batch {batch_idx}: {e}")
errors.append(batch_idx)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

If a batch fails during feature extraction, catching the exception and continuing without appending to all_features or all_labels will cause the saved features to be shorter than the metadata list in dataset_meta.json. This leads to a silent misalignment (shift) between the features and their corresponding video paths during training and evaluation. It is safer to raise the exception and fail fast.

Suggested change
except Exception as e:
print(f" Error at batch {batch_idx}: {e}")
errors.append(batch_idx)
except Exception as e:
print(f" Error at batch {batch_idx}: {e}")
raise e

Comment on lines +125 to +127
except Exception as e:
print(f" Error at batch {batch_idx}: {e}", flush=True)
errors.append(batch_idx)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

If a batch fails during feature extraction, catching the exception and continuing without appending to all_features or all_labels will cause the saved features to be shorter than the metadata list in dataset_meta.json. This leads to a silent misalignment (shift) between the features and their corresponding video paths during training and evaluation. It is safer to raise the exception and fail fast.

Suggested change
except Exception as e:
print(f" Error at batch {batch_idx}: {e}", flush=True)
errors.append(batch_idx)
except Exception as e:
print(f" Error at batch {batch_idx}: {e}")
raise e

Comment on lines +424 to +427
except Exception as e:
print(f" batch {i} error: {e}")
all_feats.append(torch.zeros(clips.shape[0], 1, EMBED_DIM))
all_labels.append(labels)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If a batch fails during feature extraction, appending a dummy tensor of shape [B, 1, EMBED_DIM] will cause torch.cat(all_feats, 0) to crash with a RuntimeError because the token dimension (dimension 1) will mismatch with successful batches (which have shape [B, N_tokens, EMBED_DIM]). It is safer to raise the exception and fail fast.

Suggested change
except Exception as e:
print(f" batch {i} error: {e}")
all_feats.append(torch.zeros(clips.shape[0], 1, EMBED_DIM))
all_labels.append(labels)
except Exception as e:
print(f" batch {i} error: {e}")
raise e

SPLITS_CSV = "/home/aparnabg/orcd/scratch/latest_split_csv_new.csv"
OUTPUT_BASE = "/orcd/data/satra/002/projects/SAILS/vjepa_features/models_output_seeds/vjepa/framelevel_onest/"

EMBED_DIM = 1408

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The loaded full video features are 1024-dimensional (as indicated by the comments and the ViT-H feature shape), but EMBED_DIM is set to 1408. Initializing the AttentiveProbe with embed_dim=1408 while passing 1024-dimensional features will cause a RuntimeError in nn.MultiheadAttention due to dimension mismatch. Please update EMBED_DIM to 1024.

Suggested change
EMBED_DIM = 1408
EMBED_DIM = 1024

SPLITS_CSV = "/home/aparnabg/orcd/scratch/latest_split_csv_new.csv"
OUTPUT_BASE = "/orcd/data/satra/002/projects/SAILS/vjepa_features/models_output_seeds/vjepa/framelevel_hierarchical/"

EMBED_DIM = 1408

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The loaded full video features are 1024-dimensional (as indicated by the comments and the ViT-H feature shape), but EMBED_DIM is set to 1408. Initializing the HierarchicalProbe with embed_dim=1408 while passing 1024-dimensional features will cause a RuntimeError in nn.MultiheadAttention due to dimension mismatch. Please update EMBED_DIM to 1024.

Suggested change
EMBED_DIM = 1408
EMBED_DIM = 1024

Comment on lines +205 to +207
self.encoder = AutoModel.from_pretrained(
MODEL_NAME, torch_dtype=torch.float16, attn_implementation="sdpa",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Loading the model with torch_dtype=torch.float16 unconditionally will cause a RuntimeError on CPU (when GPU is not available) because CPU does not support most float16 operations in PyTorch. Please set the dtype dynamically based on CUDA availability.

        dtype = torch.float16 if torch.cuda.is_available() else torch.float32
        self.encoder = AutoModel.from_pretrained(
            MODEL_NAME, torch_dtype=dtype, attn_implementation="sdpa",
        )

def _step(self, batch, stage):
inputs, labels = batch
# Cast float inputs to half to match encoder
inputs = {k: (v.half() if v.is_floating_point() else v) for k, v in inputs.items()}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Manually casting inputs to .half() will crash on CPU when running in float32 mode. It is safer to cast the inputs dynamically to the encoder's dtype.

Suggested change
inputs = {k: (v.half() if v.is_floating_point() else v) for k, v in inputs.items()}
inputs = {k: (v.to(self.encoder.dtype) if v.is_floating_point() else v) for k, v in inputs.items()}

Comment on lines +155 to +159
encoder = AutoModel.from_pretrained(
HF_MODEL_NAME,
torch_dtype=torch.float16,
attn_implementation="sdpa",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Loading the model with torch_dtype=torch.float16 unconditionally will cause a RuntimeError on CPU (when GPU is not available) because CPU does not support most float16 operations in PyTorch. Please set the dtype dynamically based on CUDA availability.

Suggested change
encoder = AutoModel.from_pretrained(
HF_MODEL_NAME,
torch_dtype=torch.float16,
attn_implementation="sdpa",
)
dtype = torch.float16 if torch.cuda.is_available() else torch.float32
encoder = AutoModel.from_pretrained(
HF_MODEL_NAME,
torch_dtype=dtype,
attn_implementation="sdpa",
)

Comment on lines +157 to +161
processor = AutoVideoProcessor.from_pretrained(HF_MODEL_NAME)
encoder = AutoModel.from_pretrained(
HF_MODEL_NAME,
torch_dtype=torch.float16,
attn_implementation="sdpa",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Loading the model with torch_dtype=torch.float16 unconditionally will cause a RuntimeError on CPU (when GPU is not available) because CPU does not support most float16 operations in PyTorch. Please set the dtype dynamically based on CUDA availability.

Suggested change
processor = AutoVideoProcessor.from_pretrained(HF_MODEL_NAME)
encoder = AutoModel.from_pretrained(
HF_MODEL_NAME,
torch_dtype=torch.float16,
attn_implementation="sdpa",
dtype = torch.float16 if torch.cuda.is_available() else torch.float32
encoder = AutoModel.from_pretrained(
HF_MODEL_NAME,
torch_dtype=dtype,
attn_implementation="sdpa",
)

#!/bin/bash
# Usage: bash submit_all.sh

SCRIPT_DIR="/home/aparnabg/orcd/scratch/all_project_files/action_sota_models/vjepa_crop"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The script contains a hardcoded absolute path pointing to a specific user's home directory (/home/aparnabg/...). This makes the script non-portable and unusable by other users or in other environments. Consider making the base directory configurable via an environment variable or command-line argument.

Suggested change
SCRIPT_DIR="/home/aparnabg/orcd/scratch/all_project_files/action_sota_models/vjepa_crop"
SCRIPT_DIR="${ACTION_SOTA_MODELS_DIR:-/home/aparnabg/orcd/scratch/all_project_files/action_sota_models/vjepa_crop}"

@aparnabg
aparnabg deleted the vjepa branch July 9, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant