Skip to content
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

Add initial fambench support to e2e_models #821

Closed
wants to merge 6 commits 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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "third_party/tbb"]
path = legacy/third_party/tbb
url = https://github.com/01org/tbb
[submodule "submodules/FAMBench"]
path = submodules/FAMBench
url = https://github.com/facebookresearch/FAMBench.git
6 changes: 4 additions & 2 deletions run_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
SUPPORT_DEVICE_LIST = ["cpu", "cuda"]

def run(func) -> Dict[str, float]:
torch.cuda.synchronize()
if torch.cuda.is_available():
torch.cuda.synchronize()
result = {}
# Collect time_ns() instead of time() which does not provide better precision than 1
# second according to https://docs.python.org/3/library/time.html#time.time.
t0 = time.time_ns()
func()
torch.cuda.synchronize()
if torch.cuda.is_available():
torch.cuda.synchronize()
t2 = time.time_ns()
result["latency_ms"] = (t2 - t0) / 1_000_000.0
return result
Expand Down
1 change: 1 addition & 0 deletions submodules/FAMBench
Submodule FAMBench added at a0f12c
67 changes: 67 additions & 0 deletions torchbenchmark/e2e_models/fambench_xlmr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
import sys
import torch
import subprocess
from pathlib import Path
from dataclasses import dataclass

from torchbenchmark.util.e2emodel import E2EBenchmarkModel

from typing import Optional, List

CURRENT_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
FAMBENCH_ROOT = CURRENT_DIR.parent.parent.parent.joinpath("submodules", "FAMBench")

def _create_data_dir(data_dir: str):
data_dir = Path(data_dir)
data_dir.mkdir(parents=True, exist_ok=True)
return data_dir

def _get_fambench_test_root(name: str):
xlmr_ootb_root = FAMBENCH_ROOT.joinpath("benchmarks")
assert xlmr_ootb_root.exists(), f"Can't find FAMBench source at {xlmr_ootb_root.absolute()}," \
"please check out the submodules."
return xlmr_ootb_root

@dataclass
class FAMBenchXLMREvalConfig:
"""
Original config reference:
https://github.com/facebookresearch/FAMBench/blob/main/benchmarks/run_xlmr_ootb.sh
"""
config_name = "default-config"
nbatches = 10
batchsize = 16
seqlength = 16
vocabsize = 250000
warmupbatches = 1
log_dir = os.path.join(CURRENT_DIR, ".data", "logs")
config_flags=["--inference-only", f"--num-batches={nbatches}", f"--batch-size={batchsize}", \
f"--sequence-length={seqlength}", f"--vocab-size={vocabsize}", \
f"--famconfig={config_name}", "--half-model", f"--warmup-batches={warmupbatches}", \
f"--logdir={log_dir}"]

class Model(E2EBenchmarkModel):
DEFAULT_EVAL_BSIZE = FAMBenchXLMREvalConfig.batchsize
def __init__(self, test: str, batch_size: Optional[int]=None, extra_args: List[str]=[]):
super().__init__(test=test, batch_size=batch_size, extra_args=extra_args)
if not torch.cuda.is_available():
raise NotImplementedError("FAMBench only support running on Nvidia GPU.")
self.device = "cuda"
self.device_num = torch.cuda.device_count()
self.name = "xlmr"
self.implementation = "ootb"
self.code_root = _get_fambench_test_root(self.name)
if test == "eval":
self.config = FAMBenchXLMREvalConfig()
self.config.batchsize = self.batch_size
self.num_examples = self.config.nbatches * self.batch_size
_create_data_dir(self.config.log_dir)

def train(self):
raise NotImplementedError("FAMBench XLMR train is not implemented yet.")

def eval(self):
prog_args = [sys.executable, f"{self.name}/{self.implementation}/{self.name}.py"]
prog_args.extend(self.config.config_flags)
subprocess.check_call(prog_args, cwd=self.code_root)
8 changes: 8 additions & 0 deletions torchbenchmark/e2e_models/fambench_xlmr/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys
import subprocess

def pip_install_requirements():
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt'])

if __name__ == '__main__':
pip_install_requirements()
4 changes: 4 additions & 0 deletions torchbenchmark/e2e_models/fambench_xlmr/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bitarray
sacrebleu>=1.4.12
omegaconf
hydra-core