Skip to content

Commit

Permalink
llama v2 (#1775)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #1775

Reviewed By: xuzhao9

Differential Revision: D47723915

Pulled By: msaroufim

fbshipit-source-id: ef6686b328f691833907660ded2fbb28d317ea61
  • Loading branch information
msaroufim authored and facebook-github-bot committed Jul 24, 2023
1 parent 30a3c4a commit 196b3b8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pytest-benchmark
requests
tabulate
git+https://github.com/huggingface/pytorch-image-models.git@6635bc3
transformers==4.30.0
transformers==4.31.0
MonkeyType
psutil
pyyaml
Expand Down
15 changes: 15 additions & 0 deletions torchbenchmark/models/llama_v2_7b_16h/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from torchbenchmark.tasks import NLP
from torchbenchmark.util.framework.huggingface.model_factory import HuggingFaceModel, HuggingFaceAuthMixin

class Model(HuggingFaceModel, HuggingFaceAuthMixin):
task = NLP.LANGUAGE_MODELING
DEFAULT_TRAIN_BSIZE = 1
DEFAULT_EVAL_BSIZE = 1
DEEPCOPY = False

def __init__(self, test, device, jit=False, batch_size=None, extra_args=[]):
HuggingFaceAuthMixin.__init__(self)
super().__init__(name="llama_v2", test=test, device=device, jit=jit, batch_size=batch_size, extra_args=extra_args)

def train(self):
return NotImplementedError("7b LLAMA model will OOM on CI GPU machines")
9 changes: 9 additions & 0 deletions torchbenchmark/models/llama_v2_7b_16h/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import subprocess
import sys
import os
from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model

if __name__ == '__main__':
model_name = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
cache_model(model_name)
13 changes: 13 additions & 0 deletions torchbenchmark/models/llama_v2_7b_16h/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
devices:
NVIDIA A100-SXM4-40GB:
eval_batch_size: 1
eval_benchmark: false
eval_deterministic: false
eval_nograd: true
not_implemented:
- jit: true
- device: cpu
- device: cuda
test: train
train_benchmark: false
train_deterministic: false
4 changes: 3 additions & 1 deletion torchbenchmark/util/framework/huggingface/model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from torchbenchmark.util.model import BenchmarkModel
from torchbenchmark.tasks import NLP
import transformers
from transformers import AutoConfig, ReformerConfig, BertConfig, GenerationConfig
from transformers import AutoConfig, ReformerConfig, BertConfig, LlamaConfig, GenerationConfig
from typing import Tuple

class_models = {
Expand All @@ -27,6 +27,8 @@
'hf_Bert': (512, 512, 'BertConfig()', 'AutoModelForMaskedLM'),
# see https://huggingface.co/bert-large-cased
'hf_Bert_large': (512, 512, 'BertConfig(hidden_size=1024, num_hidden_layers=24, num_attention_heads=16)', 'AutoModelForMaskedLM'),
# default num_hidden_layers=32 but that OOMs, feel free to change this config to something more real
'llama_v2_7b_16h' : (512,512, 'LlamaConfig(num_hidden_layers=16)', 'AutoModelForCausalLM'),
}

cpu_input_slice = {
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/util/framework/huggingface/patch_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import sys
from .model_factory import class_models
from transformers import AutoConfig, ReformerConfig, BigBirdConfig, BertConfig
from transformers import AutoConfig, ReformerConfig, BigBirdConfig, BertConfig, LlamaConfig

PATCH_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "patches")

Expand Down

0 comments on commit 196b3b8

Please sign in to comment.