-
Notifications
You must be signed in to change notification settings - Fork 41
feat(timm_repvgg): add timm RepVGG image-classification family #1153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhenshanx-nv
wants to merge
1
commit into
NVIDIA:main
Choose a base branch
from
zhenshanx-nv:zhenshanx-nv/support_timm_repvgg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| "sam3", | ||
| "segformer", | ||
| "timesfm", | ||
| "timm_repvgg", | ||
| "timm_resnet", | ||
| "timm_vgg", | ||
| "timm_vit", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
python/tensorrt_model_connect/families/timm_repvgg/MODEL.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| id = "timm_repvgg" | ||
| plugin = "timm_repvgg" | ||
| module = "plugin" | ||
| python_profile_specs = [ | ||
| "timm_repvgg_reference|families/timm_repvgg/python_profile_requirements/timm_repvgg_reference.lock.txt|families/timm_repvgg/python_profile_verify.py|true", | ||
| ] | ||
| default_execution_profiles = [ | ||
| "reference|timm_repvgg_reference", | ||
| ] | ||
| aliases = [ | ||
| "timm_repvgg", | ||
| "repvgg", | ||
| "repvgg_a2", | ||
| ] | ||
| prefixes = [ | ||
| "timm_repvgg", | ||
| "repvgg", | ||
| ] |
6 changes: 6 additions & 0 deletions
6
python/tensorrt_model_connect/families/timm_repvgg/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from .plugin import plugin | ||
|
|
||
| __all__ = ["plugin"] |
239 changes: 239 additions & 0 deletions
239
python/tensorrt_model_connect/families/timm_repvgg/config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """ModelConfig — parse HF config.json into a typed dataclass.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from dataclasses import dataclass, field | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| @dataclass | ||
| class ModelConfig: | ||
| """Parsed model architecture from HF config.json.""" | ||
|
|
||
| model_type: str = "" | ||
| architectures: list[str] = field(default_factory=list) | ||
| vocab_size: int = 0 | ||
| hidden_size: int = 0 | ||
| intermediate_size: int = 0 | ||
| num_hidden_layers: int = 0 | ||
| num_attention_heads: int = 1 | ||
| num_key_value_heads: int = 1 | ||
| rms_norm_eps: float = 1e-5 | ||
| rope_theta: float = 10000.0 | ||
| bos_token_id: int = -1 | ||
| eos_token_id: int = -1 | ||
| pad_token_id: int = -1 | ||
| tie_word_embeddings: bool = False | ||
| max_position_embeddings: int = 8192 | ||
| hidden_act: str = "" | ||
|
|
||
| # Explicit head_dim from config.json (0 = not set, fall back to computed). | ||
| _head_dim: int = 0 | ||
|
|
||
| # Raw JSON dict for family-specific fields | ||
| raw: dict = field(default_factory=dict, repr=False) | ||
|
|
||
| @property | ||
| def head_dim(self) -> int: | ||
| if self._head_dim > 0: | ||
| return self._head_dim | ||
| if self.num_attention_heads <= 0: | ||
| return 0 | ||
| return self.hidden_size // self.num_attention_heads | ||
|
|
||
| @property | ||
| def attention_size(self) -> int: | ||
| return self.num_attention_heads * self.head_dim | ||
|
|
||
| @staticmethod | ||
| def from_json(text: str) -> ModelConfig: | ||
| d = json.loads(text) | ||
|
|
||
| # Some multimodal configs nest decoder fields under "text_config". | ||
| # Merge text_config into top level so standard key lookup works. | ||
| # Preserve top-level model_type and architectures (these identify the | ||
| # top-level model, not the nested decoder). | ||
| original_raw = d | ||
| text_config = d.get("text_config") | ||
| if text_config and isinstance(text_config, dict): | ||
| top_model_type = d.get("model_type") | ||
| top_architectures = d.get("architectures") | ||
| merged = {**d, **text_config} | ||
| if top_model_type: | ||
| merged["model_type"] = top_model_type | ||
| if top_architectures: | ||
| merged["architectures"] = top_architectures | ||
| d = merged | ||
|
|
||
| # Some multimodal configs nest the language decoder config under | ||
| # "language_config". Merge into top level like text_config. | ||
| if not d.get("hidden_size"): | ||
| lang_config = d.get("language_config") | ||
| if isinstance(lang_config, dict): | ||
| top_model_type = d.get("model_type") | ||
| top_architectures = d.get("architectures") | ||
| top_vision_config = d.get("vision_config") | ||
| merged = {**d, **lang_config} | ||
| if top_model_type: | ||
| merged["model_type"] = top_model_type | ||
| if top_architectures: | ||
| merged["architectures"] = top_architectures | ||
| if top_vision_config: | ||
| merged["vision_config"] = top_vision_config | ||
| d = merged | ||
|
|
||
| # Some multimodal configs nest LLM config under "llm_config". | ||
| # Merge into top level like text_config, preserving top-level | ||
| # model_type, architectures, and vision_config. | ||
| if not d.get("hidden_size"): | ||
| llm_config = d.get("llm_config") | ||
| if isinstance(llm_config, dict): | ||
| top_model_type = d.get("model_type") | ||
| top_architectures = d.get("architectures") | ||
| top_vision_config = d.get("vision_config") | ||
| merged = {**d, **llm_config} | ||
| if top_model_type: | ||
| merged["model_type"] = top_model_type | ||
| if top_architectures: | ||
| merged["architectures"] = top_architectures | ||
| if top_vision_config: | ||
| merged["vision_config"] = top_vision_config | ||
| d = merged | ||
|
|
||
| # Some multimodal audio/text configs nest the primary decoder config | ||
| # under thinker_config.text_config. If top-level hidden_size is | ||
| # still missing after the text_config merge above, look there. | ||
| if not d.get("hidden_size"): | ||
| thinker_cfg = d.get("thinker_config") | ||
| if isinstance(thinker_cfg, dict): | ||
| thinker_text = thinker_cfg.get("text_config") | ||
| if isinstance(thinker_text, dict): | ||
| top_model_type = d.get("model_type") | ||
| top_architectures = d.get("architectures") | ||
| merged = {**d, **thinker_text} | ||
| if top_model_type: | ||
| merged["model_type"] = top_model_type | ||
| if top_architectures: | ||
| merged["architectures"] = top_architectures | ||
| # Also propagate vision_config from thinker_config | ||
| # so VL pipelines can find it. | ||
| if "vision_config" not in merged and "vision_config" in thinker_cfg: | ||
| merged["vision_config"] = thinker_cfg["vision_config"] | ||
| d = merged | ||
|
|
||
| # Handle non-standard config key names: | ||
| # GPT-2: n_embd, n_head, n_layer, n_inner | ||
| # XGLM/Bloom: d_model, attention_heads, num_layers, ffn_dim | ||
| # DistilBERT: dim, n_heads, n_layers, hidden_dim | ||
| hidden_size = ( | ||
| d.get("hidden_size", 0) | ||
| or d.get("n_embd", 0) | ||
| or d.get("d_model", 0) | ||
| or d.get("n_embed", 0) | ||
| or d.get("dim", 0) | ||
| ) | ||
| num_heads = ( | ||
| d.get("num_attention_heads", 0) | ||
| or d.get("n_head", 0) | ||
| or d.get("attention_heads", 0) | ||
| or d.get("num_heads", 0) | ||
| or d.get("n_heads", 0) | ||
| or d.get("decoder_attention_heads", 0) | ||
| or 1 | ||
| ) | ||
| num_layers = ( | ||
| d.get("num_hidden_layers", 0) | ||
| or d.get("n_layer", 0) | ||
| or d.get("num_layers", 0) | ||
| or d.get("n_layers", 0) | ||
| ) | ||
| intermediate = ( | ||
| d.get("intermediate_size", 0) | ||
| or d.get("n_inner", 0) | ||
| or d.get("ffn_dim", 0) | ||
| or d.get("hidden_dim", 0) | ||
| or hidden_size * 4 | ||
| ) | ||
|
|
||
| # Norm epsilon: try rms_norm_eps, then layer_norm_epsilon, then | ||
| # layer_norm_eps, then norm_epsilon, then norm_eps. | ||
| eps = ( | ||
| d.get("rms_norm_eps") | ||
| or d.get("layer_norm_epsilon") | ||
| or d.get("layer_norm_eps") | ||
| or d.get("norm_epsilon") | ||
| or d.get("norm_eps") | ||
| or 1e-5 | ||
| ) | ||
|
|
||
| # rope_theta: check top-level first, then rope_parameters dict | ||
| # (some model configs store it there), | ||
| # then rope_scaling dict. | ||
| rope_theta = d.get("rope_theta", None) | ||
| if rope_theta is None: | ||
| rope_params = d.get("rope_parameters") | ||
| if isinstance(rope_params, dict): | ||
| rope_theta = rope_params.get("rope_theta", 10000.0) | ||
| else: | ||
| rope_scaling = d.get("rope_scaling") | ||
| if isinstance(rope_scaling, dict): | ||
| rope_theta = rope_scaling.get("rope_theta", 10000.0) | ||
| else: | ||
| rope_theta = 10000.0 | ||
| rope_theta = float(rope_theta) | ||
|
|
||
| architecture = d.get("architecture", "") | ||
| architectures = d.get("architectures", []) | ||
| if not architectures and architecture: | ||
| architectures = [architecture] | ||
|
|
||
| return ModelConfig( | ||
| model_type=d.get("model_type", "") or architecture, | ||
| architectures=architectures, | ||
| vocab_size=d.get("vocab_size", 0), | ||
| hidden_size=hidden_size or d.get("num_features", 0), | ||
| intermediate_size=intermediate, | ||
| num_hidden_layers=num_layers, | ||
| num_attention_heads=num_heads, | ||
| num_key_value_heads=d.get("num_key_value_heads", num_heads), | ||
| rms_norm_eps=eps, | ||
| rope_theta=rope_theta, | ||
| bos_token_id=d.get("bos_token_id", -1) or -1, | ||
| eos_token_id=d.get("eos_token_id", -1) or -1, | ||
| pad_token_id=d.get("pad_token_id", -1) or -1, | ||
| tie_word_embeddings=d.get("tie_word_embeddings", False), | ||
| max_position_embeddings=d.get("max_position_embeddings", d.get("n_positions", 8192)), | ||
| hidden_act=d.get("hidden_act", "") or d.get("activation_function", ""), | ||
| _head_dim=d.get("head_dim", 0), | ||
| raw=original_raw, | ||
| ) | ||
|
|
||
| @classmethod | ||
| def create_tiny(cls, model_type: str, **overrides) -> "ModelConfig": | ||
| """Create a minimal ModelConfig for testing (2 layers, hidden=16, vocab=32).""" | ||
| defaults = { | ||
| "model_type": model_type, | ||
| "vocab_size": 32, | ||
| "hidden_size": 16, | ||
| "intermediate_size": 32, | ||
| "num_hidden_layers": 2, | ||
| "num_attention_heads": 4, | ||
| "num_key_value_heads": 4, | ||
| "rms_norm_eps": 1e-6, | ||
| "rope_theta": 10000.0, | ||
| "max_position_embeddings": 128, | ||
| } | ||
| defaults.update(overrides) | ||
| return cls.from_json(json.dumps(defaults)) | ||
|
|
||
| @staticmethod | ||
| def from_dir(model_dir: str | Path) -> ModelConfig: | ||
| model_path = Path(model_dir) | ||
| config_path = model_path / "config.json" | ||
| if config_path.exists(): | ||
| return ModelConfig.from_json(config_path.read_text()) | ||
| return ModelConfig.from_json(config_path.read_text()) |
4 changes: 4 additions & 0 deletions
4
python/tensorrt_model_connect/families/timm_repvgg/model/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Family-owned TensorRT model construction components.""" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Remove
timm_repvggfrom the ASR-only branch.timm_repvggis an image-classification family. This branch selects_load_nemo_asr_reference_model, and the resulting invocation callsmodel.transcribeat Line [614]. A task-reference run that reaches this branch will try to execute the RepVGG checkpoint as an ASR model instead of producing classification logits. Keep this condition limited tocanaryandnemotron_speech_streaming.As per path instructions, shared benchmark code must preserve family-specific behavior and timing semantics. The release entry confirms that
timm_repvggis an image-classification workload.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Path instructions