Skip to content

T2 - #2

Open
anilmartha wants to merge 21 commits into
mainfrom
t2
Open

T2#2
anilmartha wants to merge 21 commits into
mainfrom
t2

Conversation

@anilmartha

Copy link
Copy Markdown
Owner

No description provided.

amdrajeevp1 and others added 21 commits March 24, 2026 17:53
Adds text decoder export support for OpenGVLab/VideoChat-Flash-Qwen2_5-7B_InternVideo2-1B.

Architecture: VideoChatFlashQwenForCausalLM is a VLM whose language backbone is
standard Qwen2.5-7B (flat config, standard weight keys, 2D RoPE, rope_theta=1e6,
28L / 28h / 4kv / hidden=3584). The model does NOT use MRoPE, so the builder
inherits QwenModel directly rather than Qwen25VLTextModel.

Changes:
- src/python/py/models/builders/qwen.py: Add VideoChatFlashQwenModel subclass
  of QwenModel. Sets exclude_embeds=True (text decoder receives inputs_embeds
  from the embedding merger) and model_type="videochat_flash_qwen".
- src/python/py/models/builders/__init__.py: Export VideoChatFlashQwenModel.
- src/python/py/models/builder.py: Map "VideoChatFlashQwenForCausalLM"
  architecture string to VideoChatFlashQwenModel with exclude_embeds=True.
- src/models/model_type.h: Register "videochat_flash_qwen" in IsVLM() (size 6->7).
- examples/python/videochat-flash/builder.py: New example export script.
  Phase 1 (this PR): text decoder only. Vision encoder (InternVideo2-1B)
  and embedding merger export are Phase 2 (scaffolded as TODOs).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…inference support

- builder.py (example): use local OGA builder via sys.path; fix create_model
  args when no local input dir; move prepare_model() inside Phase-2 block
  (trust_remote_code=False is safe for config-only loads)
- builder.py (core): add VCF config bypass using hf_hub_download + Qwen2Config
  to avoid av/cv2/decord/imageio imports triggered by AutoConfig; set
  config._name_or_path so load_weights() resolves the model correctly; make
  exclude_embeds opt-in (guard with 'not in extra_options') so standalone
  (input_ids) export also works
- qwen.py: add make_genai_config() override that writes a temp Qwen2Config
  and patches genai_config.json type back to videochat_flash_qwen; add
  load_weights() override using Qwen2ForCausalLM.from_pretrained() directly

Validated: text-only inference with vcf-oga-fp32-standalone/ produces
correct answers (Paris, 56, ONNX Runtime description) using append_tokens()
API on the exported Qwen2.5-7B backbone.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
examples/python/videochat-flash/run.py:
  - Text-only inference for the exported OGA model
  - Uses HF AutoTokenizer (og.Tokenizer fails for TokenizersBackend models)
  - Feeds tokens via generator.append_tokens(np.int32 array)
  - --batch flag runs 4 built-in QA prompts for quick validation
  - --prompt / --max-length for custom single-prompt runs
  - Notes in docstring on genai_config.json type patch workaround for
    installed OGA binaries that predate videochat_flash_qwen support

Validated: all 4 batch prompts produce correct answers on vcf-oga-fp32-standalone.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…xt-only mode

Root cause of teammate's inference failure:
1. builder.py set type=videochat_flash_qwen even in --text-only mode. OGA loads
   this via MultiModalLanguageModel which requires vision.onnx + embedding.onnx
   (not present in text-only export) → 'File doesn't exist' error on og.Model().
2. exclude_embeds defaulted to true → decoder expected inputs_embeds, but
   run.py feeds token IDs via append_tokens() → 'input not found' error.

Fix:
- builder.py export_text_model(): pass exclude_embeds=false in text-only mode
  (decoder uses input_ids for standalone inference).
- builder.py update_genai_config(): set type=qwen2 in text-only mode so OGA
  loads the model as a plain decoder (LM backbone is identical to Qwen2.5-7B).
  type=videochat_flash_qwen is reserved for Phase 2 full VLM pipeline.
- run.py: simplify docstring now that no manual patching is needed.

Validated with compiled OGA build (onnxruntime-genai conda env, Python 3.11):
all 4 batch prompts produce correct answers without any manual config changes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Documents Phase 1 (text decoder, done) and Phase 2 (vision + embedding, TODO):
- Architecture overview: InternVideo2-1B ViT → mm_projector → embedding merger → Qwen2.5-7B
- Phase 1 summary: what was implemented, design decisions, usage instructions
- Phase 2 roadmap: vision.onnx export (39-block ViT + MLP projector), embedding.onnx
  (embed_tokens + image-pad replacement), genai_config.json wiring, video preprocessing,
  and optional in-LLM HiCo compression (llm_compress_layer_list)
- Key challenges: 3D spatiotemporal attention ONNX compat, ToMe token merging ops,
  dynamic temporal position embeddings
- File map and reference links

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- builder.py: introduce _has_vcf_architecture() helper that handles
  architectures as a list, a bare string, or absent/unknown type, then
  use it in both the local-dir and HF-hub code paths (Copilot comment #2)

- config.h: correct misleading comment on num_visual_tokens — remove the
  false "0 = compute from image_grid_thw" claim; the field must be > 0
  for videochat_flash_qwen (Copilot comment #3)

- videochat_flash_processor.cpp: add clarifying comment to empty catch
  block — exception is expected when only the language decoder session is
  loaded (Copilot comment microsoft#4)

- builders/__init__.py: move VideoChatFlashQwenModel to its correct
  alphabetical position in __all__ (after SmolLM3Model, before
  WhisperModel) per kunal-vaishnavi comment microsoft#6

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
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.

3 participants