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

Llama2 7b model C++ example #3666

Open
wants to merge 57 commits into
base: develop
Choose a base branch
from
Open

Conversation

ototh-htec
Copy link

@ototh-htec ototh-htec commented Nov 29, 2024

Implemented an example for https://huggingface.co/amd/Llama-2-7b-chat-hf-awq-int4-asym-gs128-onnx/tree/main Llama2 7b model with MIGraphX.

Details about the example and description for running is available in README (https://github.com/ROCm/AMDMIGraphX/tree/htec/mgx-llama2-7b-example/examples/transformers/mgx_llama2)

gyulaz-htec and others added 30 commits November 17, 2024 04:33
src/api/api.cpp Outdated
@@ -1522,6 +1522,21 @@ extern "C" migraphx_status migraphx_module_add_instruction(migraphx_instruction_
return api_error_result;
}

extern "C" migraphx_status migraphx_module_get_last_instruction(migraphx_instruction_t* out,
Copy link
Collaborator

@gyulaz-htec gyulaz-htec Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove these changes (commits) which are related to exposing this API part. Because we ended up not needing these changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed them

Copy link

codecov bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.23%. Comparing base (2e9104a) to head (b499638).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3666   +/-   ##
========================================
  Coverage    92.23%   92.23%           
========================================
  Files          514      514           
  Lines        21746    21746           
========================================
  Hits         20057    20057           
  Misses        1689     1689           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ototh-htec ototh-htec changed the title [WIP] Llama2 7b model C++ example Llama2 7b model C++ example Dec 6, 2024
@ototh-htec ototh-htec marked this pull request as ready for review December 6, 2024 09:11
@ototh-htec ototh-htec requested review from a team and causten as code owners December 6, 2024 09:11
@migraphx-bot
Copy link
Collaborator

Test Batch Rate new
b49963
Rate old
4b15b6
Diff Compare
torchvision-resnet50 64 3,254.17 3,257.89 -0.11%
torchvision-resnet50_fp16 64 6,988.94 6,918.72 1.01%
torchvision-densenet121 32 2,432.26 2,432.91 -0.03%
torchvision-densenet121_fp16 32 4,085.65 4,086.33 -0.02%
torchvision-inceptionv3 32 1,627.76 1,628.71 -0.06%
torchvision-inceptionv3_fp16 32 2,742.43 2,745.51 -0.11%
cadene-inceptionv4 16 764.96 764.62 0.04%
cadene-resnext64x4 16 810.58 814.13 -0.44%
slim-mobilenet 64 7,461.51 7,458.12 0.05%
slim-nasnetalarge 64 208.46 209.03 -0.27%
slim-resnet50v2 64 3,440.03 3,436.59 0.10%
bert-mrpc-onnx 8 1,150.36 1,150.32 0.00%
bert-mrpc-tf 1 475.69 449.82 5.75% 🔆
pytorch-examples-wlang-gru 1 428.15 437.44 -2.12%
pytorch-examples-wlang-lstm 1 436.50 383.25 13.89% 🔆
torchvision-resnet50_1 1 777.19 741.45 4.82% 🔆
cadene-dpn92_1 1 399.33 400.49 -0.29%
cadene-resnext101_1 1 382.84 382.70 0.04%
onnx-taau-downsample 1 345.53 345.15 0.11%
dlrm-criteoterabyte 1 33.35 33.31 0.11%
dlrm-criteoterabyte_fp16 1 52.51 52.72 -0.40%
agentmodel 1 8,059.84 8,463.32 -4.77% 🔴
unet_fp16 2 58.74 58.77 -0.05%
resnet50v1_fp16 1 935.52 934.37 0.12%
resnet50v1_int8 1 995.64 1,030.33 -3.37% 🔴
bert_base_cased_fp16 64 1,169.76 1,170.28 -0.04%
bert_large_uncased_fp16 32 363.68 363.03 0.18%
bert_large_fp16 1 199.12 199.90 -0.39%
distilgpt2_fp16 16 2,197.04 2,197.64 -0.03%
yolov5s 1 528.96 518.78 1.96%
tinyllama 1 43.34 43.68 -0.79%
vicuna-fastchat 1 165.26 173.15 -4.56% 🔴
whisper-tiny-encoder 1 418.07 417.60 0.11%
whisper-tiny-decoder 1 432.36 429.03 0.78%

This build is not recommended to merge 🔴

@migraphx-bot
Copy link
Collaborator


     ✅ bert-mrpc-onnx: PASSED: MIGraphX meets tolerance

     ✅ bert-mrpc-tf: PASSED: MIGraphX meets tolerance

     ✅ pytorch-examples-wlang-gru: PASSED: MIGraphX meets tolerance

     ✅ pytorch-examples-wlang-lstm: PASSED: MIGraphX meets tolerance

     ✅ torchvision-resnet50_1: PASSED: MIGraphX meets tolerance

     ✅ cadene-dpn92_1: PASSED: MIGraphX meets tolerance

     ✅ cadene-resnext101_1: PASSED: MIGraphX meets tolerance

     ✅ dlrm-criteoterabyte: PASSED: MIGraphX meets tolerance

     ✅ agentmodel: PASSED: MIGraphX meets tolerance

     ✅ unet: PASSED: MIGraphX meets tolerance

     ✅ resnet50v1: PASSED: MIGraphX meets tolerance

     ✅ bert_base_cased_fp16: PASSED: MIGraphX meets tolerance

🔴bert_large_uncased_fp16: FAILED: MIGraphX is not within tolerance - check verbose output


     ✅ bert_large: PASSED: MIGraphX meets tolerance

     ✅ yolov5s: PASSED: MIGraphX meets tolerance

     ✅ tinyllama: PASSED: MIGraphX meets tolerance

     ✅ vicuna-fastchat: PASSED: MIGraphX meets tolerance

     ✅ whisper-tiny-encoder: PASSED: MIGraphX meets tolerance

     ✅ whisper-tiny-decoder: PASSED: MIGraphX meets tolerance

     ✅ distilgpt2_fp16: PASSED: MIGraphX meets tolerance

make -j

# Running the example
export MIOPEN_FIND_ENFORCE=3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? I don't believe we make any MIOpen calls for this model.

Copy link
Contributor

@spolifroni-amd spolifroni-amd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readme looks fine from a grammar/spelling angle

#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.

make -j

# Running the example
export MIOPEN_FIND_ENFORCE=3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export MIOPEN_FIND_ENFORCE=3

#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.

#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.

/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.

/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.

/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.

/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.

#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.

#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.

### Getting the pre-quantized model from HuggingFace
```bash
pip install -U "huggingface_hub[cli]"
huggingface-cli login YOUR_HF_TOKEN
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
huggingface-cli login YOUR_HF_TOKEN
huggingface-cli login login --token <YOUR_HF_TOKEN>

```bash
pip install -U "huggingface_hub[cli]"
huggingface-cli login YOUR_HF_TOKEN
hugginggface-cli download https://huggingface.co/amd/Llama-2-7b-chat-hf-awq-int4-asym-gs128-onnx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hugginggface-cli download https://huggingface.co/amd/Llama-2-7b-chat-hf-awq-int4-asym-gs128-onnx
huggingface-cli download amd/Llama-2-7b-chat-hf-awq-int4-asym-gs128-onnx


```bash
# Convert dataset to numpy format
./prepocess_dataset.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a step is missing. I performed the steps listed to use the pre-quantized model

Suggested change
./prepocess_dataset.py
gunzip /mgx_llama2/open_orca/open_orca_gpt4_tokenized_llama.calibration_1000.pkl.gz
python3 preprocess_dataset.py


# Builidng the example
cd mgx_llama2
mkdir build && cd build
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was already a build dir so the command failed.


# Running the example
export MIOPEN_FIND_ENFORCE=3
./mgxllama2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root@12320f9edbf9:/mgx_llama2/build# ./mgxllama2
terminate called after throwing an instance of 'std::runtime_error'
  what():  hip error (101): invalid device ordinal
Aborted (core dumped)

./mgxllama2

# Test the accuracy of the output
python3 eval_accuracy.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root@12320f9edbf9:/mgx_llama2# python3 eval_accuracy.py
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_http.py", line 406, in hf_raise_for_status
    response.raise_for_status()
  File "/usr/local/lib/python3.10/dist-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/meta-llama/Llama-2-7b-chat-hf/resolve/main/config.json

#### Building and running the example

```bash
# Convert dataset to numpy format
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I launched the docker via run_docker.sh I landed in the /mgx_llama2/build directory so the preprocess_dataset.py command's path is wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants