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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
!src
!transformers
!requirements.txt
!Makefile
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ ENV PYTHONPATH=/app
RUN useradd -m -u $USER -s /bin/bash $USERNAME \
&& chown $USERNAME /app

# git-lfs is needed to interact with the huggingface hub
RUN apt-get update \
&& apt-get install git-lfs \
&& rm -rf /var/lib/apt/lists/* \
&& git lfs install

COPY --chown=$USERNAME ./requirements.txt ./
COPY --chown=$USERNAME transformers/ ./transformers

# Stock version of pip doesn't work with editable transformers.
RUN pip install --upgrade pip --no-cache-dir && pip install -r requirements.txt --no-cache-dir

COPY --chown=$USERNAME Makefile .
COPY --chown=$USERNAME src/ ./src
78 changes: 42 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
check_dirs := src scripts

.PHONY: style
style:
black --preview $(check_dirs)
isort $(check_dirs)

batch_size := 1
BATCH_SIZE ?= 1
DTYPE ?= float16
HIDDEN_SIZE ?= 2048
N_HEAD ?= 16
N_LAYER ?= 24
N_POSITION ?= 2048
MAX_INPUT_LENGTH ?= -1

RUN_HF := python3 src/main.py --pipeline_class=HF_Pipeline
RUN_DS := deepspeed --num_gpus 1 src/main.py --pipeline_class=DS_Pipeline
EXP_ARGS := --dtype=${DTYPE} --batch_size=${BATCH_SIZE} --max_input_length=${MAX_INPUT_LENGTH} ${EXTRA_ARGS}
COMMON_ARGS := ${EXP_ARGS} n_head=${N_HEAD} n_layer=${N_LAYER}
BLOOM_ARGS := --model_type=bloom ${COMMON_ARGS} hidden_size=${HIDDEN_SIZE}
GPT2_ARGS := --model_type=gpt2 ${COMMON_ARGS} n_embd=${HIDDEN_SIZE}
BIGCODE_ARGS := --model_type=gpt_bigcode ${COMMON_ARGS} n_embd=${HIDDEN_SIZE}


.PHONY: install
install:
git submodule update --init
pip install -r requirements.txt

# BLOOM AliBi
hf-1b-bloom-fp32:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class BLOOM --dtype float32 --batch_size ${batch_size}

hf-1b-bloom-bf16:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class BLOOM --dtype bfloat16 --batch_size ${batch_size}

hf-1b-bloom-int8:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class BLOOM --dtype int8 --batch_size ${batch_size}

ds-inference-1b-bloom-fp16:
deepspeed --num_gpus 1 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class DS_Pipeline --model_class BLOOM --batch_size ${batch_size}

# GPT2 MHA
hf-1b-GPT2-mha-fp32:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class GPT2 --n_positions 2048 --attention_type 1 --dtype float32 --batch_size ${batch_size}

hf-1b-GPT2-mha-bf16:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class GPT2 --n_positions 2048 --attention_type 1 --dtype bfloat16 --batch_size ${batch_size}
.PHONY: bloom
bloom:
${RUN_HF} ${BLOOM_ARGS}

hf-1b-GPT2-mha-int8:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class GPT2 --n_positions 2048 --attention_type 1 --dtype int8 --batch_size ${batch_size}
.PHONY: bloom-ds
bloom-ds:
${RUN_DS} ${BLOOM_ARGS}

ds-inference-1b-GPT2-mha-fp16:
deepspeed --num_gpus 1 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class DS_Pipeline --model_class GPT2 --n_positions 2048 --attention_type 1 --batch_size ${batch_size}
.PHONY: gpt2
gpt2:
${RUN_HF} ${GPT2_ARGS}

# GPT2 MQA1
hf-1b-GPT2-mqa1-fp32:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class GPT2 --n_positions 2048 --attention_type 2 --dtype float32 --batch_size ${batch_size}
.PHONY: gpt2-ds
gpt2-ds:
${RUN_DS} ${GPT2_ARGS}

hf-1b-GPT2-mqa1-bf16:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class GPT2 --n_positions 2048 --attention_type 2 --dtype bfloat16 --batch_size ${batch_size}
.PHONY: gpt-bigcode-mha
gpt-bigcode-mha:
${RUN_HF} ${BIGCODE_ARGS} attention_type=1

hf-1b-GPT2-mqa1-int8:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class GPT2 --n_positions 2048 --attention_type 2 --dtype int8 --batch_size ${batch_size}
.PHONY: gpt-bigcode-mqa1
gpt-bigcode-mqa1:
${RUN_HF} ${BIGCODE_ARGS} attention_type=2

# Input length experiments
hf-1b-GPT2-mqa1-int8-input-length:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class GPT2 --n_positions 2048 --attention_type 2 --dtype int8 --batch_size ${batch_size} --max_input_length ${max_input_length}
.PHONY: gpt-bigcode-mqa2
gpt-bigcode-mqa2:
${RUN_HF} ${BIGCODE_ARGS} attention_type=3

hf-1b-GPT2-mha-int8-input-length:
python3 src/main.py --hidden_size 2048 --n_head 16 --n_layer 24 --pipeline_class HF_Pipeline --model_class GPT2 --n_positions 2048 --attention_type 1 --dtype int8 --batch_size ${batch_size} --max_input_length ${max_input_length}
.PHONY: santacoder
santacoder:
${RUN_HF} --pretrained_model=bigcode/santacoder-fast-inference --tokenizer=bigcode/santacoder ${EXP_ARGS}
3 changes: 3 additions & 0 deletions scripts/make_graph_throughput.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import matplotlib.pyplot as plt


# TODO: Update this script


def get_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()

Expand Down
3 changes: 3 additions & 0 deletions scripts/parse_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from pandas import DataFrame


# TODO: Update this script


def get_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()

Expand Down
12 changes: 1 addition & 11 deletions scripts/run_batch_size.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
export CUDA_VISIBLE_DEVICES=0

rm -rf ./tmp

for bs in {1,2,4,8,16,32,64}
do
make $1 batch_size=$bs
done

# split for loops
for i in {1..20}
do
bs=$(($i*128))
make $1 batch_size=$bs
make $1 BATCH_SIZE=$bs
done
10 changes: 0 additions & 10 deletions scripts/run_batch_size1.sh

This file was deleted.

6 changes: 1 addition & 5 deletions scripts/run_input_length.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export CUDA_VISIBLE_DEVICES=0

rm -rf ./tmp

for max_input_length in {4,8,16,32,64,128,256,512,1024,1536,1900}
do
make $1 batch_size=32 max_input_length=$max_input_length
make $1 batch_size=32 MAX_INPUT_LENGTH=$max_input_length
done
28 changes: 23 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,30 @@
def main(argv: Optional[List[str]] = None) -> None:
args = parse_args(argv=argv)

inputs = get_dummy_batch(args.batch_size, args.max_input_length)

generate_kwargs = {"max_new_tokens": args.max_new_tokens, "do_sample": False}

pipeline_class = get_pipeline_class(args.pipeline_class)
benchmark_end_to_end(args, pipeline_class, inputs, generate_kwargs)
pipeline = pipeline_class(
model_type=args.model_type,
pretrained_model=args.pretrained_model,
config_args=args.config_args,
tokenizer=args.tokenizer,
device=args.device,
dtype=args.dtype,
fast_init=args.fast_init,
)

benchmark_end_to_end(
pipeline=pipeline,
inputs=get_dummy_batch(args.batch_size, args.max_input_length),
generate_kwargs={"max_new_tokens": args.max_new_tokens, "do_sample": False},
profile=args.profile,
skip=args.skip,
warmup=args.profile if args.warmup is None else args.warmup,
cycles=args.cycles,
full_trace=args.full_trace,
show_op_names=args.show_op_names,
max_log_outputs=args.batch_size if args.max_log_outputs is None else args.max_log_outputs,
clear_every_run=args.clear_every_run,
)


if __name__ == "__main__":
Expand Down
23 changes: 13 additions & 10 deletions src/pipelines/ds.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import os
from argparse import Namespace

import deepspeed
import torch

from src.pipelines.pipeline import Pipeline
from src.utils.arguments import check_unused


class DS_Pipeline(Pipeline):
def __init__(self, args: Namespace) -> None:
check_unused(args, {"device": torch.device("cuda")}, enforce=True)
# TODO: Works with other dtypes?
check_unused(args, {"dtype": torch.float16})
super().__init__(args)
def __init__(self, **kwargs):
super().__init__(**kwargs)

if self.device != torch.device("cuda"):
raise ValueError(f"Deepspeed does not support device {self.device}")

if self.dtype not in (torch.float32, torch.float16, torch.bfloat16):
raise ValueError(f"Deepspeed does not support dtype {self.dtype}")

if self.config.model_type not in ("bloom", "gpt2"):
raise ValueError(f"Deepspeed does not support model type {self.config.model_type}")

self.model = deepspeed.init_inference(
self.model,
mp_size=int(os.getenv("WORLD_SIZE", "1")),
# base_dir="./",
dtype=args.dtype,
replace_with_kernel_inject=args.inject_kernel,
enable_cuda_graph=args.cuda_graph,
dtype=self.dtype,
replace_with_kernel_inject=True,
)
Loading