Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/ci_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copy of executorch/requirements-dev.txt as of v1.2.0
# Copy of executorch/requirements-dev.txt as of v1.3.1

cmake>=3.29, <4.0.0 # For building binary targets in the wheel.
packaging>=24.2 # Lower bound required by setuptools
Expand All @@ -10,4 +10,4 @@ zstd # Imported by resolve_buck.py.
certifi # Imported by resolve_buck.py.
lintrunner==0.12.7
lintrunner-adapters==0.13.0
torch==2.11.0
torch==2.12.0
4 changes: 4 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line-length = 120

[lint]
ignore = ["C408", "TRY002"]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import torch
from torch.export import export
from executorch.exir import to_edge_transform_and_lower


class Add(torch.nn.Module):
def __init__(self):
super(Add, self).__init__()
Expand Down Expand Up @@ -62,7 +63,7 @@ See `example/hello_world` for a complete example.
## Build
To use the library you must compile the C++ executorch library yourself, as there are many configurations that
determines which modules, backends, and operations are supported. See the `executorch-sys` crate for more info.
Currently the supported Cpp executorch version is `1.2.0`.
Currently the supported Cpp executorch version is `1.3.1`.


## Cargo Features
Expand Down
3 changes: 3 additions & 0 deletions etc/download_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def main():
"runtime/core/**/*.h",
"runtime/executor/**/*.h",
"runtime/platform/**/*.h",
"runtime/kernel/operator_registry.h",
"runtime/backend/options.h",
"runtime/backend/backend_options_map.h",
"extension/data_loader/**/*.h",
Expand All @@ -62,6 +63,8 @@ def main():
"extension/data_loader/mman.h",
"extension/data_loader/mman_windows.h",
"extension/module/bundled_module.h", # TODO
"runtime/core/device_allocator.h", # TODO
"runtime/core/device_memory_buffer.h", # TODO
"extension/flat_tensor/serialize/serialize.h",
"**/test/**",
"**/testing_util/**",
Expand Down
11 changes: 5 additions & 6 deletions etc/setup_dev_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ def main():
parser.add_argument(
"--skip-executorch-python",
action="store_true",
help="Remove the existing executorch directory before cloning",
help="Skip installing the executorch Python package",
)
args = parser.parse_args()

if args.clean:
if DEV_EXECUTORCH_DIR.exists():
shutil.rmtree(DEV_EXECUTORCH_DIR)
if args.clean and DEV_EXECUTORCH_DIR.exists():
shutil.rmtree(DEV_EXECUTORCH_DIR)

# TODO setup a venv here

Expand All @@ -50,7 +49,7 @@ def main():
"install",
"-r",
DEV_EXECUTORCH_DIR / "requirements-dev.txt",
"torch==2.11.0",
"torch==2.12.0",
"--extra-index-url",
"https://download.pytorch.org/whl/test/cpu",
]
Expand All @@ -72,7 +71,7 @@ def clone_executorch():
"--depth",
"1",
"--branch",
"v1.2.0",
"v1.3.1",
"https://github.com/pytorch/executorch.git",
".",
],
Expand Down
3 changes: 1 addition & 2 deletions examples/data_map/export_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from pathlib import Path

import torch
from torch.export import export

from executorch.exir import ExecutorchBackendConfig, to_edge_transform_and_lower
from torch.export import export


class ModuleAddMul(torch.nn.Module):
Expand Down
2 changes: 1 addition & 1 deletion examples/data_map/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn main_program() {
let data_map_loader = FileDataLoader::from_path(&data_file, None).unwrap();
let data_map = FlatTensorDataMap::load(&data_map_loader).unwrap();
let mut method = program
.load_method(c"forward", &memory_manager, None, Some(&data_map))
.load_method(c"forward", &memory_manager, None, Some(&data_map), None)
.unwrap();

let data = array![[1.0_f32, 2.0], [3.0, 4.0]];
Expand Down
5 changes: 2 additions & 3 deletions examples/etdump/export_model.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from pathlib import Path

import torch
from torch.export import export

from executorch.exir import to_edge_transform_and_lower
from torch.export import export


# A simple PyTorch model that adds two input tensors
class Add(torch.nn.Module):
def __init__(self):
super(Add, self).__init__()
super().__init__()

def forward(self, x: torch.Tensor, y: torch.Tensor):
return x + y
Expand Down
5 changes: 2 additions & 3 deletions examples/hello_world/export_model.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from pathlib import Path

import torch
from torch.export import export

from executorch.exir import to_edge_transform_and_lower
from torch.export import export


# A simple PyTorch model that adds two input tensors
class Add(torch.nn.Module):
def __init__(self):
super(Add, self).__init__()
super().__init__()

def forward(self, x: torch.Tensor, y: torch.Tensor):
return x + y
Expand Down
2 changes: 1 addition & 1 deletion examples/llama3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ To run the example, follow these steps (note that some steps should run from the
The llama model can be exported with many options, such as quantization, different data types (f32, bf16), different backends, kv caching, etc.
This example use a specific set of options, as specified above.
Different options require different export commands and modifications to the code and build script which you can play around with.
See the [llama README](https://github.com/pytorch/executorch/blob/v1.2.0/examples/models/llama/README.md) at the Cpp executorch repository for more details.
See the [llama README](https://github.com/pytorch/executorch/blob/v1.3.1/examples/models/llama/README.md) at the Cpp executorch repository for more details.
13 changes: 7 additions & 6 deletions examples/nano-gpt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
https://github.com/huggingface/transformers/blob/main/src/transformers/models/gpt2/modeling_gpt2.py
"""

import math
import inspect
import math
from dataclasses import dataclass

import torch
import torch.nn as nn
from torch import nn
from torch.nn import functional as F


class LayerNorm(nn.Module):
""" LayerNorm but with an optional bias. PyTorch doesn't support simply bias=False """

Expand Down Expand Up @@ -145,7 +146,7 @@ def __init__(self, config):
torch.nn.init.normal_(p, mean=0.0, std=0.02/math.sqrt(2 * config.n_layer))

# report number of parameters
print("number of parameters: %.2fM" % (self.get_num_params()/1e6,))
print(f"number of parameters: {self.get_num_params()/1e6:.2f}M")

def get_num_params(self, non_embedding=True):
"""
Expand All @@ -169,7 +170,7 @@ def _init_weights(self, module):

def forward(self, idx, targets=None):
device = idx.device
b, t = idx.size()
_b, t = idx.size()
assert t <= self.config.block_size, f"Cannot forward sequence of length {t}, block size is only {self.config.block_size}"
pos = torch.arange(0, t, dtype=torch.long, device=device) # shape (t)

Expand Down Expand Up @@ -210,7 +211,7 @@ def from_pretrained(cls, model_type, override_args=None):
# only dropout can be overridden see more notes below
assert all(k == 'dropout' for k in override_args)
from transformers import GPT2LMHeadModel
print("loading weights from pretrained gpt: %s" % model_type)
print(f"loading weights from pretrained gpt: {model_type}")

# n_layer, n_head and n_embd are determined from model_type
config_args = {
Expand Down Expand Up @@ -280,7 +281,7 @@ def configure_optimizers(self, weight_decay, learning_rate, betas, device_type):
# Create AdamW optimizer and use the fused version if it is available
fused_available = 'fused' in inspect.signature(torch.optim.AdamW).parameters
use_fused = fused_available and device_type == 'cuda'
extra_args = dict(fused=True) if use_fused else dict()
extra_args = {'fused': True} if use_fused else {}
optimizer = torch.optim.AdamW(optim_groups, lr=learning_rate, betas=betas, **extra_args)
print(f"using fused AdamW: {use_fused}")

Expand Down
5 changes: 2 additions & 3 deletions examples/no_ndarray/export_model.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from pathlib import Path

import torch
from torch.export import export

from executorch.exir import to_edge_transform_and_lower
from torch.export import export


# A simple PyTorch model that adds two input tensors
class Add(torch.nn.Module):
def __init__(self):
super(Add, self).__init__()
super().__init__()

def forward(self, x: torch.Tensor, y: torch.Tensor):
return x + y
Expand Down
5 changes: 2 additions & 3 deletions examples/no_std/export_model.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from pathlib import Path

import torch
from torch.export import export

from executorch.exir import to_edge_transform_and_lower
from torch.export import export


# A simple PyTorch model that adds two input tensors
class Add(torch.nn.Module):
def __init__(self):
super(Add, self).__init__()
super().__init__()

def forward(self, x: torch.Tensor, y: torch.Tensor):
return x + y
Expand Down
2 changes: 1 addition & 1 deletion examples/no_std/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn real_main() {
let memory_manager = MemoryManager::new(&allocator, Some(&mut planned_memory), None);

let mut method = program
.load_method(c"forward", &memory_manager, None, None)
.load_method(c"forward", &memory_manager, None, None, None)
.unwrap();

let input_array1 = ArrayStorage::new(array!(1.0_f32)).unwrap();
Expand Down
5 changes: 2 additions & 3 deletions examples/raw_tensor/export_model.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from pathlib import Path

import torch
from torch.export import export

from executorch.exir import to_edge_transform_and_lower
from torch.export import export


# A simple PyTorch model that adds two input tensors
class Add(torch.nn.Module):
def __init__(self):
super(Add, self).__init__()
super().__init__()

def forward(self, x: torch.Tensor, y: torch.Tensor):
return x + y
Expand Down
4 changes: 2 additions & 2 deletions executorch-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ For a general description of the project, see the the `executorch` crate.

## Build
To build the library, you need to build the C++ library yourself first.
Currently the supported Cpp executorch version is `1.2.0`.
Currently the supported Cpp executorch version is `1.3.1`.
The C++ library allow for great flexibility with many flags, customizing which modules, kernels, and extensions are built.
Multiple static libraries are built, and the Rust library links to them.
In the following example we build the C++ library with the necessary flags to run example `hello_world`:
```bash
# Clone the C++ library
cd ${EXECUTORCH_CPP_DIR}
git clone --depth 1 --branch v1.2.0 https://github.com/pytorch/executorch.git .
git clone --depth 1 --branch v1.3.1 https://github.com/pytorch/executorch.git .
git submodule sync --recursive
git submodule update --init --recursive

Expand Down
4 changes: 3 additions & 1 deletion executorch-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};

// const EXECUTORCH_VERSION: &str = "1.2.0";
// const EXECUTORCH_VERSION: &str = "1.3.1";

fn main() {
// TODO: verify on runtime we use the correct version of executorch
Expand Down Expand Up @@ -98,6 +98,8 @@ fn generate_bindings() {
.opaque_type("ET_MemoryManager")
.opaque_type("ET_OptionalTensorStorage")
.opaque_type("ET_DumpGen")
.opaque_type("ET_BackendOption")
.opaque_type("ET_LoadBackendOptionsMap")
.blocklist_item("ET_FreeableBuffer")
.blocklist_item(".*_bindgen_ty_.*")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));
Expand Down
Loading
Loading