-
Notifications
You must be signed in to change notification settings - Fork 305
/
Copy pathe2e.py
53 lines (46 loc) · 1.41 KB
/
e2e.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import importlib
import os
import pathlib
from dataclasses import dataclass
from typing import Any, Dict, List
E2E_MODEL_DIR = "e2e_models"
def _list_model_paths() -> List[str]:
p = pathlib.Path(__file__).parent.joinpath(E2E_MODEL_DIR)
return sorted(str(child.absolute()) for child in p.iterdir() if child.is_dir())
@dataclass
class E2EBenchmarkResult:
device: str
device_num: int
test: str
num_examples: int
num_epochs: int
batch_size: int
result: Dict[str, Any]
def load_e2e_model_by_name(model):
models = filter(
lambda x: model.lower() == x.lower(),
map(lambda y: os.path.basename(y), _list_model_paths()),
)
models = list(models)
if not models:
return None
assert (
len(models) == 1
), f"Found more than one models {models} with the exact name: {model}"
model_name = models[0]
try:
module = importlib.import_module(
f"torchbenchmark.e2e_models.{model_name}", package=__name__
)
except ModuleNotFoundError as e:
print(
f"Warning: Could not find dependent module {e.name} for Model {model_name}, skip it: {e}"
)
return None
Model = getattr(module, "Model", None)
if Model is None:
print(f"Warning: {module} does not define attribute Model, skip it")
return None
if not hasattr(Model, "name"):
Model.name = model_name
return Model