Skip to content

Commit 52e68fc

Browse files
author
Danqing Wang (MPK)
committed
Address comment
1 parent 8419a74 commit 52e68fc

File tree

89 files changed

+16550
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+16550
-7
lines changed

data/bin/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This file should be written to the wheel package as
2+
# `executorch/data/bin/__init__.py`.
3+
#
4+
# Setuptools will expect to be able to say something like `from
5+
# executorch.data.bin import mybin; mybin()` for each entry listed in the
6+
# [project.scripts] section of pyproject.toml. This file makes the `mybin()`
7+
# function execute the binary at `executorch/data/bin/mybin` and exit with that
8+
# binary's exit status.
9+
10+
import subprocess
11+
import os
12+
import sys
13+
import types
14+
15+
# This file should live in the target `bin` directory.
16+
_bin_dir = os.path.join(os.path.dirname(__file__))
17+
18+
def _find_executable_files_under(dir):
19+
"""Lists all executable files in the given directory."""
20+
bin_names = []
21+
for filename in os.listdir(dir):
22+
filepath = os.path.join(dir, filename)
23+
if os.path.isfile(filepath) and os.access(filepath, os.X_OK):
24+
# Remove .exe suffix on windows.
25+
filename_without_ext = os.path.splitext(filename)[0]
26+
bin_names.append(filename_without_ext)
27+
return bin_names
28+
29+
# The list of binaries to create wrapper functions for.
30+
_bin_names = _find_executable_files_under(_bin_dir)
31+
32+
# We'll define functions named after each binary. Make them importable.
33+
__all__ = _bin_names
34+
35+
def _run(name):
36+
"""Runs the named binary, which should live under _bin_dir.
37+
38+
Exits the current process with the return code of the subprocess.
39+
"""
40+
raise SystemExit(subprocess.call([os.path.join(_bin_dir, name)] + sys.argv[1:], close_fds=False))
41+
42+
# Define a function named after each of the binaries.
43+
for bin_name in _bin_names:
44+
exec(f"def {bin_name}(): _run('{bin_name}')")

data/bin/flatc

3.48 MB
Binary file not shown.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
//
4+
// See README.md before modifying this file.
5+
//
6+
7+
include "scalar_type.fbs";
8+
9+
namespace bundled_program_flatbuffer;
10+
11+
// Identifier of a valid bundled program schema.
12+
file_identifier "BP08";
13+
// Extension of written files.
14+
file_extension "bpte";
15+
16+
// Reason for basic struct: union value type can only be table/struct/string
17+
table Int {
18+
int_val:long;
19+
}
20+
21+
table Bool {
22+
bool_val:bool;
23+
}
24+
25+
table Double {
26+
double_val:double;
27+
}
28+
29+
// All information we need to bundle for a tensor EValue input.
30+
table Tensor {
31+
// The scalar type of Tensor
32+
scalar_type: executorch_flatbuffer.ScalarType;
33+
// The target sizes of the tensor.
34+
sizes: [int];
35+
// The contents of the corresponding input tensor.
36+
data: [ubyte] (force_align: 16);
37+
dim_order:[ubyte];
38+
}
39+
40+
union ValueUnion {
41+
Tensor,
42+
Int,
43+
Bool,
44+
Double,
45+
}
46+
47+
// Abstraction for BundledMethodTestCase values
48+
table Value {
49+
val: ValueUnion;
50+
}
51+
52+
// A single test for a method. The provided inputs should produce the
53+
// expected outputs.
54+
table BundledMethodTestCase {
55+
// The inputs to provide to the method. The number and types of inputs must
56+
// match the schema of the method under test.
57+
inputs: [Value];
58+
59+
// The expected outputs generated while running the model in eager mode using
60+
// the inputs provided. Its length should be equal to the length of program
61+
// outputs.
62+
expected_outputs: [Value];
63+
}
64+
65+
// Collection of test cases for a program method.
66+
table BundledMethodTestSuite {
67+
// The name of the method to test; e.g., "forward" for the forward() method
68+
// of an nn.Module. This name match a method defined by the ExecuTorch
69+
// program.
70+
method_name: string;
71+
72+
// Individual test cases for the method.
73+
test_cases: [BundledMethodTestCase];
74+
}
75+
76+
77+
// Executorch program bunlded with data for verification.
78+
table BundledProgram {
79+
// Schema version.
80+
version:uint;
81+
82+
// Test sets to run against the program.
83+
// Each BundledMethodTestSuite should be used for the method of program sharing same name.
84+
method_test_suites: [BundledMethodTestSuite];
85+
86+
// The binary data of a serialized Executorch program.
87+
// The following `force_align` may sliently override any larger force_align
88+
// used in the program. Therefore, to keep the data (including constant
89+
// tensor, delegate data, etc, see schema.fbs for more info) in the
90+
// executorch program keeps the same alignment as original no matter how
91+
// the program schema changes, we need to make the force_align here the max
92+
// one around all kinds of force_align in the current and future program
93+
// schema, so we use the 32 as the force_align here.
94+
program: [ubyte] (force_align: 32);
95+
}
96+
97+
root_type BundledProgram;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
//
4+
// See README.md before modifying this file.
5+
//
6+
7+
namespace executorch_flatbuffer;
8+
9+
// The scalar data type.
10+
// Must match executorch/runtime/core/portable_type/tensor_impl.h
11+
enum ScalarType : byte {
12+
BYTE = 0,
13+
CHAR = 1,
14+
SHORT = 2,
15+
INT = 3,
16+
LONG = 4,
17+
HALF = 5,
18+
FLOAT = 6,
19+
DOUBLE = 7,
20+
BOOL = 11,
21+
QINT8 = 12,
22+
QUINT8 = 13,
23+
QINT32 = 14,
24+
QUINT4X2 = 16,
25+
QUINT2X4 = 17,
26+
BITS16 = 22,
27+
FLOAT8E5M2 = 23,
28+
FLOAT8E4M3FN = 24,
29+
FLOAT8E5M2FNUZ = 25,
30+
FLOAT8E4M3FNUZ = 26,
31+
UINT16 = 27,
32+
UINT32 = 28,
33+
UINT64 = 29,
34+
// Types currently not implemented.
35+
// COMPLEXHALF = 8,
36+
// COMPLEXFLOAT = 9,
37+
// COMPLEXDOUBLE = 10,
38+
// BFLOAT16 = 15,
39+
// BITS1x8 = 18,
40+
// BITS2x4 = 19,
41+
// BITS4x2 = 20,
42+
// BITS8 = 21,
43+
}

examples/models/llama/export_llama_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"static_llama",
9595
"qwen2_5",
9696
"phi-4-mini",
97-
"smollm",
97+
"smolllm2",
9898
]
9999
TORCHTUNE_DEFINED_MODELS = ["llama3_2_vision"]
100100

examples/models/smollm/convert_weights.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ def smollm_tune_to_meta(state_dict: Dict[str, torch.Tensor]) -> Dict[str, torch.
4242
new_key = get_mapped_key(key, inverted_mapping_dict)
4343
converted_state_dict[new_key] = value
4444

45-
# Input and output embeddings are tied.
46-
converted_state_dict["output.weight"] = converted_state_dict[
47-
"tok_embeddings.weight"
48-
]
49-
5045
return converted_state_dict
5146

5247

@@ -68,7 +63,7 @@ def main():
6863
checkpoint_dir=args.input_dir,
6964
checkpoint_files=["model.safetensors"],
7065
output_dir=".",
71-
model_type="MISTRAL",
66+
model_type="LLAMA",
7267
)
7368

7469
print("Loading checkpoint...")

0 commit comments

Comments
 (0)