Skip to content

Commit

Permalink
Add exportable baby llama example (#4345)
Browse files Browse the repository at this point in the history
Summary:

Add a small LLaMa model, based on the babyllama paper. Note that this test case is only one layer by default, and the number of layers can be adjusted in the test.

Differential Revision: D60073137
  • Loading branch information
mcremon-meta authored and facebook-github-bot committed Jul 23, 2024
1 parent 3154afc commit 5016b17
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/cadence/models/babyllama.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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.

# Example script for exporting simple models to flatbuffer

import logging

from executorch.backends.cadence.aot.ops_registrations import * # noqa

import torch

from executorch.backends.cadence.aot.export_example import export_model

from executorch.examples.models.llama2.llama_transformer import ModelArgs, Transformer


FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
logging.basicConfig(level=logging.INFO, format=FORMAT)


if __name__ == "__main__":

args = ModelArgs(
dim=512,
vocab_size=512,
hidden_dim=1024,
n_heads=8,
# use_kv_cache=True,
n_layers=1,
)
seq = 64
b = 1
model = Transformer(args)
example_inputs = (torch.randint(0, 10, [b, seq], dtype=torch.int64),)

export_model(model, example_inputs)

0 comments on commit 5016b17

Please sign in to comment.