Skip to content

Commit

Permalink
tmp: bert npu run
Browse files Browse the repository at this point in the history
  • Loading branch information
deeplearningfromscratch committed Jul 22, 2024
1 parent 238106e commit 034ae10
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
6 changes: 6 additions & 0 deletions language/bert/RNGD_SUT.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def __init__(self, args):
args.quant_param_path,
args.quant_format_path,
)
for n, p in self.model.named_parameters():
print(n, p)
else:
self.model = self.model.trace()

Expand Down Expand Up @@ -141,11 +143,15 @@ def process_sample(self, sample_input, query_id=None):
self.dump.update({"input": query})

with torch.no_grad():
print(f"{input_ids=}")
print(f"{input_mask=}")
print(f"{segment_ids=}")
model_output = self.encoder.encode(
input_ids=torch.LongTensor(input_ids).unsqueeze(0).to(self.dev),
attention_mask=torch.LongTensor(input_mask).unsqueeze(0).to(self.dev),
token_type_ids=torch.LongTensor(segment_ids).unsqueeze(0).to(self.dev),
)
print("model_output", model_output)
if self.dump_path:
assert len(model_output) == 1
self.dump.update({"output": {"output_ids": model_output[0].tolist()}})
Expand Down
4 changes: 2 additions & 2 deletions language/bert/RNGD_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def encode(
for arg in self.model.concrete_args:
if arg in model_kwargs:
del model_kwargs[arg]

print(model_kwargs)
logits = self.model(**model_kwargs)

print(logits)
outputs = []
for batch_index, target_location in enumerate(packed_target_locations):
for single_target_location in target_location:
Expand Down
5 changes: 4 additions & 1 deletion language/bert/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--backend", choices=["tf", "pytorch", "onnxruntime", "tf_estimator", "ray", "rngd"], default="tf", help="Backend")
"--backend", choices=["tf", "pytorch", "onnxruntime", "tf_estimator", "ray", "rngd", "rngd-npu"], default="tf", help="Backend")
parser.add_argument("--scenario", choices=["SingleStream", "Offline",
"Server", "MultiStream"], default="Offline", help="Scenario")
parser.add_argument("--accuracy", action="store_true",
Expand Down Expand Up @@ -102,6 +102,9 @@ def main():
assert not args.profile, "Profiling is only supported by onnxruntime backend!"
from RNGD_SUT import get_rngd_sut
sut = get_rngd_sut(args)
elif args.backend == "rngd-npu":
from RNGD_NPU_SUT import get_rngd_npu_sut
sut = get_rngd_npu_sut(args)
else:
raise ValueError("Unknown backend: {:}".format(args.backend))

Expand Down
2 changes: 1 addition & 1 deletion scripts/build_rngd_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ install_mlperf_loadgen() {
install_pip_packages() {
echo "Installing DVC with S3 support..."
pip install 'dvc[s3]'
pip install datasets==2.18.0 nltk==3.8.1 evaluate==0.4.1 absl-py==2.1.0 rouge_score==0.1.2
pip install datasets==2.18.0 nltk==3.8.1 evaluate==0.4.1 absl-py==2.1.0 rouge_score==0.1.2 tokenization==1.0.7
}

# https://www.notion.so/furiosa/RNGD-SW-Stack-runtime-7df73fb4d92241e09a2721612ebd9c3d?pvs=4#847dd27d9857405a8b3c26b4538c3656
Expand Down
5 changes: 3 additions & 2 deletions scripts/eval_mlperf_gptj.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ run_multi_device_eval() {
echo -e "\nAll evaluations completed.\n"

if [ "$N_DEVICES" == "$N_PARTITIONS" ]; then
python "$work_dir/gather_log_accuracy.py" --log-dir="$LOG_PATH"
python "$work_dir/gather_log.py" "$LOG_PATH" -p "$N_PARTITIONS" -n "$N_COUNT"
MLPERF_ACCURACY_FILE="$LOG_PATH/merged_mlperf_log_accuracy.json"

if [ "$DO_DUMP" = true ]; then
python "$work_dir/gather_generator_dump.py" --log-dir="$LOG_PATH"
python "$work_dir/gather_log.py" "$LOG_PATH" -p "$N_PARTITIONS" -n "$N_COUNT"
fi
else
SKIP_VERIFY_ACCURACY=true
Expand Down Expand Up @@ -162,6 +162,7 @@ LOG_PATH=${LOG_PATH:="$log_dir/$model_name/$SCENARIO/$(date +%Y%m%d_%H%M%S%Z)"}
DEVICE=${DEVICE:="npu"}
DEVICE_NUM=${DEVICE_NUM:="0"}
DEVICES=${DEVICES:="$DEVICE:$DEVICE_NUM:0-3,$DEVICE:$DEVICE_NUM:4-7"}
DEVICES="npu:1:0-3,npu:1:4-7"
N_COUNT=${N_COUNT:="13368"}
N_DEVICES=${N_DEVICES:="1"}
N_PARTITIONS="${N_PARTITIONS:-$N_DEVICES}"
Expand Down
2 changes: 1 addition & 1 deletion scripts/eval_qbert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ python $work_dir/accuracy-squad.py --vocab_file=$VOCAB_PATH \
--out_file=$LOG_PATH/predictions.json \
--max_examples=$N_COUNT \
&> $LOG_PATH/accuracy_result.log

cat $LOG_PATH/accuracy_result.log
printf "Save evaluation log to $LOG_PATH"

unset LOG_PATH
Expand Down

0 comments on commit 034ae10

Please sign in to comment.