Skip to content

Add wav2letter model to examples #71

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 8 additions & 0 deletions examples/export/test/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,11 @@ def test_vit_export_to_executorch(self):
self._assert_eager_lowered_same_result(
eager_model, example_inputs, self.validate_tensor_allclose
)

def test_w2l_export_to_executorch(self):
eager_model, example_inputs = MODEL_NAME_TO_MODEL["w2l"]()
eager_model = eager_model.eval()

self._assert_eager_lowered_same_result(
eager_model, example_inputs, self.validate_tensor_allclose
)
1 change: 1 addition & 0 deletions examples/models/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python_library(
"//executorch/examples/models/mobilenet_v2:mv2_export",
"//executorch/examples/models/mobilenet_v3:mv3_export",
"//executorch/examples/models/torchvision_vit:vit_export",
"//executorch/examples/models/wav2letter:w2l_export",
"//executorch/exir/backend:compile_spec_schema",
],
)
8 changes: 8 additions & 0 deletions examples/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def gen_torchvision_vit_model_and_inputs() -> Tuple[torch.nn.Module, Any]:
return TorchVisionViTModel.get_model(), TorchVisionViTModel.get_example_inputs()


def gen_wav2letter_model_and_inputs() -> Tuple[torch.nn.Module, Any]:
from ..models.wav2letter import Wav2LetterModel

model = Wav2LetterModel()
return model.get_model(), model.get_example_inputs()


MODEL_NAME_TO_MODEL = {
"mul": lambda: (MulModule(), MulModule.get_example_inputs()),
"linear": lambda: (LinearModule(), LinearModule.get_example_inputs()),
Expand All @@ -103,4 +110,5 @@ def gen_torchvision_vit_model_and_inputs() -> Tuple[torch.nn.Module, Any]:
"mv2": gen_mobilenet_v2_model_inputs,
"mv3": gen_mobilenet_v3_model_inputs,
"vit": gen_torchvision_vit_model_and_inputs,
"w2l": gen_wav2letter_model_and_inputs,
}
14 changes: 14 additions & 0 deletions examples/models/wav2letter/TARGETS
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")

python_library(
name = "w2l_export",
srcs = [
"__init__.py",
"export.py",
],
base_module = "executorch.examples.models.wav2letter",
deps = [
"//caffe2:torch",
"//pytorch/audio:torchaudio",
],
)
11 changes: 11 additions & 0 deletions examples/models/wav2letter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from .export import Wav2LetterModel

__all__ = [
Wav2LetterModel,
]
30 changes: 30 additions & 0 deletions examples/models/wav2letter/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import logging

import torch
from torchaudio import models

FORMAT = "[%(filename)s:%(lineno)s] %(message)s"
logging.basicConfig(format=FORMAT)


class Wav2LetterModel:
def __init__(self):
self.batch_size = 10
self.input_frames = 700
self.vocab_size = 4096

def get_model(self):
logging.info("loading wav2letter model")
wav2letter = models.Wav2Letter(num_classes=self.vocab_size)
logging.info("loaded wav2letter model")
return wav2letter

def get_example_inputs(self):
input_shape = (self.batch_size, 1, self.input_frames)
return (torch.randn(input_shape),)