Skip to content

default NPI file added #498

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
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
11 changes: 11 additions & 0 deletions QEfficient/transformers/models/gemma3/modeling_gemma3.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,17 @@ def forward(self, input_ids, position_ids, pixel_values, image_idx, past_key_val
image_idx = (indices1.max() + 1).unsqueeze(0).unsqueeze(0)
return outputs.logits, pixel_values, image_idx, outputs.past_key_values

def get_npi_file(self, model_name: str, **compiler_options):
if model_name == "google/gemma-3-4b-it":
compiler_options["node_precision_info"] = constants.DEFAULT_GEMMA3_4B_NODE_PRECISION_INFO
elif model_name == "google/gemma-3-27b-it":
compiler_options["node_precision_info"] = constants.DEFAULT_GEMMA3_27B_NODE_PRECISION_INFO
else:
raise ValueError(
f"For Model {self.pretrained_model_name_or_path} default NPI file is not supported/added. Please use one of the following: google/gemma-3-4b-it, google/gemma-3-27b-it"
)
return compiler_options

def get_specializations(
self,
batch_size: int,
Expand Down
6 changes: 6 additions & 0 deletions QEfficient/transformers/models/modeling_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@ def compile(
**compiler_options,
)

if hasattr(self.model, "get_npi_file"):
compiler_options = self.model.get_npi_file(self.model.pretrained_model_name_or_path, **compiler_options)

custom_io_vision = {}
kv_cache_dtype = "mxint8" if mxint8_kv_cache else "float16"
custom_io_vision["pixel_values"] = "float16"
Expand Down Expand Up @@ -1030,6 +1033,9 @@ def compile(
**compiler_options,
)

if hasattr(self.model, "get_npi_file"):
self.model.get_npi_file(self.pretrained_model_name_or_path)

custom_io = {}
kv_cache_dtype = "mxint8" if mxint8_kv_cache else "float16"
# inputs
Expand Down
5 changes: 4 additions & 1 deletion QEfficient/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import os
from dataclasses import dataclass

from QEfficient.transformers.models import gemma3 as gemma3

UTILS_DIR = os.path.dirname(os.path.abspath(__file__))
QEFF_DIR = os.path.dirname(UTILS_DIR)
ROOT_DIR = os.path.dirname(QEFF_DIR)
Expand Down Expand Up @@ -100,7 +102,8 @@ def get_models_dir():
LLAMA4_MAX_POSITION_EMBEDDINGS = 65536

# Gemma3 Constant
GEMMA3_MAX_POSITION_EMBEDDINGS = 32768
DEFAULT_GEMMA3_4B_NODE_PRECISION_INFO = "QEfficient/transformers/models/gemma3/fp32_nodes_gemma3_4b_mm.yaml"
DEFAULT_GEMMA3_27B_NODE_PRECISION_INFO = "QEfficient/transformers/models/gemma3/fp32_nodes_gemma3_27b_mm.yaml"


class Constants:
Expand Down
500 changes: 0 additions & 500 deletions examples/gemma3_example/fp32_nodes_gemma3_27b_text.yaml

This file was deleted.

275 changes: 0 additions & 275 deletions examples/gemma3_example/fp32_nodes_gemma3_4b_text.yaml

This file was deleted.

6 changes: 2 additions & 4 deletions examples/gemma3_example/gemma3_mm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
# pass HF_TOKEN if gated model
# For running the model in single QPC approach use kv_offload=False. For Dual QPC approach use kv_offload=True ###
qeff_model = QEFFAutoModelForImageTextToText.from_pretrained(
model_id, config=config, attn_implementation="eager", kv_offload=True
model_id, config=config, attn_implementation="eager", kv_offload=False
)

### use skip_vision=Ture, if want to run only text, or false ###
skip_vision = True
skip_vision = False

if skip_vision:
## Only Text ##
Expand All @@ -41,7 +41,6 @@
aic_enable_depth_first=True,
skip_vision=True,
mos=1,
node_precision_info="examples/gemma3_example/fp32_mm.yaml",
)

messages = [
Expand Down Expand Up @@ -77,7 +76,6 @@
mxint8_kv_cache=False,
aic_enable_depth_first=True,
mos=1,
node_precision_info="examples/gemma3_example/fp32_mm.yaml",
)

### IMAGE + TEXT ###
Expand Down
Loading