Skip to content

Commit 05a4134

Browse files
committed
Summary
Added 8 new representative models to ExecutorTorch examples: EfficientNet-B4: Image classification with CNN architecture DETR-ResNet50: Object detection using transformer decoder SegFormer-ADE: Semantic segmentation transformer Swin2SR: Super-resolution with Swin transformer ALBERT: Lightweight BERT for NLP tasks TrOCR: Optical character recognition transformer Wav2Vec2: Cross-lingual speech representation learning All models include XNNPACK backend support with appropriate quantization configurations and full CI integration. Test plan: Validate model export and execution with portable backend Test XNNPACK delegation and quantization (with appropriate exclusions) Integrate into CI workflows for automated testing Verify all models perform their intended tasks accurately
1 parent f82c2f0 commit 05a4134

File tree

18 files changed

+384
-3
lines changed

18 files changed

+384
-3
lines changed

.ci/scripts/test_model.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ elif [[ "${BACKEND}" == *"xnnpack"* ]]; then
317317
echo "Testing ${MODEL_NAME} with xnnpack..."
318318
WITH_QUANTIZATION=true
319319
WITH_DELEGATION=true
320-
if [[ "$MODEL_NAME" == "mobilebert" ]]; then
321-
# TODO(T197452682)
320+
if [[ "$MODEL_NAME" == "mobilebert" || "$MODEL_NAME" == "albert" ]]; then
321+
# TODO(https://github.com/pytorch/executorch/issues/12341)
322+
# mobilebert, albert incompatible with XNNPACK quantization
322323
WITH_QUANTIZATION=false
323324
fi
324325
test_model_with_xnnpack "${WITH_QUANTIZATION}" "${WITH_DELEGATION}"

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
contents: read
6464
strategy:
6565
matrix:
66-
model: [linear, add, add_mul, ic3, ic4, mv2, mv3, resnet18, resnet50, vit, w2l, mobilebert, emformer_join, emformer_transcribe]
66+
model: [linear, add, add_mul, ic3, ic4, mv2, mv3, resnet18, resnet50, vit, w2l, mobilebert, emformer_join, emformer_transcribe, efficientnet_b4, detr_resnet50, segformer_ade, albert, wav2vec2]
6767
backend: [portable, xnnpack-quantization-delegation]
6868
runner: [linux.arm64.2xlarge]
6969
include:

examples/models/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ class Model(str, Enum):
3737
EfficientSam = "efficient_sam"
3838
Qwen25 = "qwen2_5"
3939
Phi4Mini = "phi_4_mini"
40+
EfficientNetB4 = "efficientnet_b4"
41+
DetrResNet50 = "detr_resnet50"
42+
SegformerADE = "segformer_ade"
43+
Albert = "albert"
44+
BiLSTM = "bilstm"
45+
Swin2SR2x = "swin2sr_2x"
46+
TrOCRHandwritten = "trocr_handwritten"
47+
Wav2Vec2 = "wav2vec2"
4048

4149
def __str__(self) -> str:
4250
return self.value
@@ -82,6 +90,13 @@ def __str__(self) -> str:
8290
str(Model.EfficientSam): ("efficient_sam", "EfficientSAM"),
8391
str(Model.Qwen25): ("qwen2_5", "Qwen2_5Model"),
8492
str(Model.Phi4Mini): ("phi_4_mini", "Phi4MiniModel"),
93+
str(Model.EfficientNetB4): ("efficientnet_b4", "EfficientNetB4Model"),
94+
str(Model.DetrResNet50): ("detr_resnet50", "DetrResNet50Model"),
95+
str(Model.SegformerADE): ("segformer_ade", "SegformerADEModel"),
96+
str(Model.Albert): ("albert", "AlbertModelExample"),
97+
str(Model.Swin2SR2x): ("swin2sr_2x", "Swin2SR2xModel"),
98+
str(Model.TrOCRHandwritten): ("trocr_handwritten", "TrOCRHandwrittenModel"),
99+
str(Model.Wav2Vec2): ("wav2vec2", "Wav2Vec2Model"),
85100
}
86101

87102
__all__ = [

examples/models/albert/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
from .model import AlbertModelExample
8+
9+
__all__ = [
10+
"AlbertModelExample",
11+
]

examples/models/albert/model.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
import logging
8+
9+
import torch
10+
11+
from transformers import AlbertModel, AutoTokenizer # @manual
12+
13+
from ..model_base import EagerModelBase
14+
15+
16+
class AlbertModelExample(EagerModelBase):
17+
def __init__(self):
18+
pass
19+
20+
def get_eager_model(self) -> torch.nn.Module:
21+
logging.info("Loading ALBERT model")
22+
# pyre-ignore
23+
model = AlbertModel.from_pretrained("albert-base-v2", return_dict=False)
24+
model.eval()
25+
logging.info("Loaded ALBERT model")
26+
return model
27+
28+
def get_example_inputs(self):
29+
tokenizer = AutoTokenizer.from_pretrained("albert-base-v2")
30+
return (tokenizer("Hello, my dog is cute", return_tensors="pt")["input_ids"],)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
from .model import DetrResNet50Model
8+
9+
__all__ = [
10+
"DetrResNet50Model",
11+
]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
import logging
8+
9+
import torch
10+
from transformers import DetrForObjectDetection
11+
12+
from ..model_base import EagerModelBase
13+
14+
15+
class DetrWrapper(torch.nn.Module):
16+
"""Wrapper for HuggingFace DETR model to make it torch.export compatible"""
17+
18+
def __init__(self, model_name="facebook/detr-resnet-50"):
19+
super().__init__()
20+
self.detr = DetrForObjectDetection.from_pretrained(model_name)
21+
self.detr.eval()
22+
23+
def forward(self, pixel_values):
24+
# pixel_values: [batch, 3, height, width] - RGB image
25+
with torch.no_grad():
26+
outputs = self.detr(pixel_values)
27+
# Return logits and boxes for object detection
28+
return outputs.logits, outputs.pred_boxes
29+
30+
31+
class DetrResNet50Model(EagerModelBase):
32+
def __init__(self):
33+
pass
34+
35+
def get_eager_model(self) -> torch.nn.Module:
36+
logging.info("Loading DETR ResNet-50 model from HuggingFace")
37+
model = DetrWrapper("facebook/detr-resnet-50")
38+
model.eval()
39+
logging.info("Loaded DETR ResNet-50 model")
40+
return model
41+
42+
def get_example_inputs(self):
43+
# DETR standard input size: 800x800 RGB image (can handle various sizes)
44+
tensor_size = (1, 3, 800, 800)
45+
return (torch.randn(tensor_size),)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
from .model import EfficientNetB4Model
8+
9+
__all__ = [
10+
"EfficientNetB4Model",
11+
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
import logging
8+
9+
import torch
10+
11+
from torchvision.models import efficientnet_b4 # @manual
12+
from torchvision.models.efficientnet import EfficientNet_B4_Weights
13+
14+
from ..model_base import EagerModelBase
15+
16+
17+
class EfficientNetB4Model(EagerModelBase):
18+
def __init__(self):
19+
pass
20+
21+
def get_eager_model(self) -> torch.nn.Module:
22+
logging.info("Loading EfficientNet-B4 model")
23+
model = efficientnet_b4(weights=EfficientNet_B4_Weights.IMAGENET1K_V1)
24+
model.eval()
25+
logging.info("Loaded EfficientNet-B4 model")
26+
return model
27+
28+
def get_example_inputs(self):
29+
# EfficientNet-B4 uses 380x380 input size
30+
tensor_size = (1, 3, 380, 380)
31+
return (torch.randn(tensor_size),)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
from .model import SegformerADEModel
8+
9+
__all__ = [
10+
"SegformerADEModel",
11+
]

0 commit comments

Comments
 (0)