SamChen567 commited on
Commit
c3b18fc
Β·
verified Β·
1 Parent(s): 847201d

Add model card

Browse files
Files changed (1) hide show
  1. README.md +115 -0
README.md ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ base_model: DAMO-NLP-SG/VideoLLaMA3-7B
4
+ tags:
5
+ - video
6
+ - token-compression
7
+ - videollama3
8
+ ---
9
+
10
+ # phase1_qbase_internvid (native-res, video-only, 2 epochs)
11
+
12
+ Phase 1 of the qbase video-token compressor curriculum: a learned-query compressor
13
+ ("qbase") inserted between the frozen SigLIP-NaViT vision encoder and the frozen
14
+ Qwen2-7B LLM of VideoLLaMA3-7B, trained with caption cross-entropy.
15
+
16
+ > **This repo was re-used.** The repo name previously referred to an older Phase-1 run
17
+ > (16384-token video budget, 40 % still images, 3 epochs / 3,441 steps); no weights from
18
+ > that run were ever uploaded here. Everything in this repo is the run described below.
19
+
20
+ This checkpoint needs the custom code in the training repository (`videollama3/model`,
21
+ `Videollama3Qwen2ForCausalLM` with `token_compressor`); it does not load with stock
22
+ `transformers` alone.
23
+
24
+ ## What is trained
25
+
26
+ | module | status |
27
+ |---|---|
28
+ | vision encoder (SigLIP-NaViT) | frozen |
29
+ | `token_compressor` (qbase, 170M) | trained |
30
+ | `mm_projector` (mlp2x_gelu, 17M) | trained |
31
+ | `<\|compression_start\|>` / `<\|compression_end\|>` embedding rows | trained (all other rows frozen) |
32
+ | LLM (Qwen2-7B) + `lm_head` | frozen |
33
+
34
+ Warm start: `SamChen567/compressor_pretrain_video_norm` (qbase + projector + the two embedding rows).
35
+
36
+ ## Compressor
37
+
38
+ - `transformer_decoder_flat`: 8 layers, 8 heads, hidden 1152, **K = 64** learned queries
39
+ (+ sin/cos position encoding); cross-attention onto the segment's encoder tokens with
40
+ (t, h, w) RoPE.
41
+ - **Adaptive segmentation** (non-learned): `N = ⌊T/4βŒ‹ + 1` segments per video, a forced
42
+ cut every 8 frames, remaining cuts at the largest consecutive-frame cosine distance of
43
+ the per-frame mean encoder feature. Each segment is 1–8 frames. Deterministic top-k
44
+ (`segment_sample_tau = 0`).
45
+ - **Option A** (`match_encoder_scale`): output rescaled to the encoder tokens' per-dim
46
+ mean/std, then a learnable per-channel Ξ³/Ξ².
47
+ - **Option B** (`distr_loss_weight = 0.05`): CORAL-style distribution-match auxiliary loss
48
+ (see the note on its effective weight below).
49
+
50
+ ## Input layout seen by the LLM
51
+
52
+ Each segment carries its own time range (`segment_time_marks = True`); the per-frame
53
+ `Time X.0s:` text of the uncompressed template is removed:
54
+
55
+ ```
56
+ <|im_start|>user
57
+ Time:0s-3s:<|compression_start|>[64]<|compression_end|>Time:4s-4s:<|compression_start|>[64]<|compression_end|> ...
58
+ {prompt}<|im_end|>
59
+ <|im_start|>assistant
60
+ {caption}<|im_end|>
61
+ ```
62
+
63
+ Seconds are integers (first / last frame of the segment). Example: a 120 s clip at
64
+ 1 fps β†’ 31 segments β†’ 1,984 compressed tokens (vs. 35,880 uncompressed at 640Γ—360).
65
+ Checkpoints trained before 2026-10-12 used one whole-video range instead; build the
66
+ layout from this checkpoint's `config.json`.
67
+
68
+ ## Data
69
+
70
+ - InternVid clips **< 180 s**, 264,186 samples, **video only** (no still images).
71
+ - Captions re-generated by **Qwen3-VL-8B-Instruct at 1 fps, native resolution**, with
72
+ several prompt styles (`baseline_default`, `scene_shift`, `motion_scene`, ...).
73
+ - One turn per sample: `<video>\n{prompt}` β†’ caption. Loss on the assistant caption only.
74
+
75
+ ## Vision geometry
76
+
77
+ - fps = 1, `max_frames = 180`.
78
+ - Native resolution: per-video budget 53,820 merged tokens (180 Γ— 299), per-frame cap
79
+ 2048, per-frame floor 64. 640Γ—360 β†’ 299 tokens/frame (patch 14, merge 2).
80
+
81
+ ## Training
82
+
83
+ | | |
84
+ |---|---|
85
+ | epochs / steps | 2 / 1,376 |
86
+ | global batch | 384 (2 per device Γ— 8 GPUs Γ— 24 grad-acc, flattened B = 1 sequences) |
87
+ | LR | qbase 2e-5, projector 5e-6; 10 % warmup, cosine; weight decay 0 |
88
+ | precision / parallel | bf16, DeepSpeed ZeRO-1, gradient checkpointing |
89
+ | wall time | 11.5 h |
90
+
91
+ The exact launcher is included as `launcher.sh` (env overrides used for this run:
92
+ `EPOCHS=2 COMPRESSOR_LR=2e-5 PER_DEVICE_BATCH=2`, data
93
+ `anno_data/internvid_qwen3vl_lt180.json`). The full loss curve is in `trainer_state.json`.
94
+
95
+ ### Loss
96
+
97
+ | steps | logged loss | β‰ˆ per-token CE (Γ—8, see note) |
98
+ |---|---|---|
99
+ | 1–25 | 0.2312 | 1.85 |
100
+ | 664–688 (end of epoch 1) | 0.1790 | 1.43 |
101
+ | 689–713 (start of epoch 2) | 0.1779 | 1.42 |
102
+ | 1352–1376 (end) | 0.1733 | 1.39 |
103
+
104
+ No NaN, no skipped samples; grad norm stayed in 0.15–0.33. These are training losses
105
+ only β€” no held-out evaluation is reported here.
106
+
107
+ ### Notes on loss scaling (known quirk of the training code)
108
+
109
+ - The custom `compute_loss` divides the CE sum by the token count **gathered across all
110
+ 8 GPUs** but does not multiply back by the number of processes, so the **logged loss is
111
+ β‰ˆ per-token CE / 8**. AdamW is nearly scale-invariant, so this mostly affects the
112
+ readout; with these small gradients `max_grad_norm = 1.0` never clips.
113
+ - The Option-B term is divided only by grad-accum steps, not by 8, so **relative to CE its
114
+ effective weight is β‰ˆ 0.05 Γ— 8 = 0.4**, not the configured 0.05. Earlier Phase-1/2 runs
115
+ from the same code share this behaviour.