Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ROCmSoftwarePlatform/AMDMIGraphX…
Browse files Browse the repository at this point in the history
… into ocp_to_fnuz
  • Loading branch information
CharlieL7 committed Jan 3, 2025
2 parents 20c494b + 13159b3 commit 2f2dda1
Show file tree
Hide file tree
Showing 108 changed files with 3,348 additions and 279 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/config.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#=====ROCM INFO=====
ROCM_VERSION : '6.0.2'
ROCM_VERSION : '6.3.1'
#default ROCm version to be used
ROCM_BASE_IMAGE : 'rocm/dev-ubuntu-20.04'
ROCM_BASE_IMAGE : 'rocm/dev-ubuntu-22.04'
#base image from dockerhub to be used
ROCM_BUILT_IMAGE : 'rocm-migraphx'
#name of the docker image built upon ROCm base
Expand All @@ -26,4 +26,4 @@ PERFORMANCE_TEST_TIMEOUT : '30m'

#===== W A R N I N G =====
#VARIABLE NAMES NOT TO BE CHANGED, VALUES ONLY!
#VALUES MUST BE ENGLOSED IN SINGLE QUOTES!
#VALUES MUST BE ENGLOSED IN SINGLE QUOTES!
4 changes: 2 additions & 2 deletions .github/workflows/performance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
rocm_release:
description: ROCm Version
required: true
default: '6.0.2'
default: '6.3.1'
performance_reports_repo:
description: Repository where performance reports are stored
required: true
Expand Down Expand Up @@ -96,4 +96,4 @@ jobs:
secrets:
gh_token: ${{ secrets.MIGRAPHX_BOT_TOKEN }}
mail_user: ${{ secrets.MAIL_USERNAME }}
mail_pass: ${{ secrets.MAIL_PASSWORD }}
mail_pass: ${{ secrets.MAIL_PASSWORD }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apt-get update && apt-get install -y software-properties-common gnupg2 --no-
curl -sL http://repo.radeon.com/rocm/rocm.gpg.key | apt-key add -

# Add rocm repository
RUN sh -c 'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/6.2/ jammy main > /etc/apt/sources.list.d/rocm.list'
RUN sh -c 'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/6.3/ jammy main > /etc/apt/sources.list.d/rocm.list'

# From docs.amd.com for installing rocm. Needed to install properly
RUN sh -c "echo 'Package: *\nPin: release o=repo.radeon.com\nPin-priority: 600' > /etc/apt/preferences.d/rocm-pin-600"
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def rocmtestnode(Map conf) {
rm -rf build
mkdir build
cd build
cmake -DCTEST_TIMEOUT=3600 -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_DEV=On -DCMAKE_EXECUTE_PROCESS_COMMAND_ECHO=STDOUT -DMIGRAPHX_DISABLE_VIRTUAL_ENV=ON ${flags} ..
cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_DEV=On -DCMAKE_EXECUTE_PROCESS_COMMAND_ECHO=STDOUT -DMIGRAPHX_DISABLE_VIRTUAL_ENV=ON ${flags} ..
git diff
git diff-index --quiet HEAD || (echo "Git repo is not clean after running cmake." && exit 1)
make -j\$(nproc) generate VERBOSE=1
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ignore:
- "test/"
- "src/driver"
- "build/"
- "src/netron_output.cpp"
2 changes: 1 addition & 1 deletion docs/sphinx/requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rocm-docs-core==1.11.0
rocm-docs-core==1.12.0
sphinx-collapse
2 changes: 1 addition & 1 deletion docs/sphinx/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ requests==2.32.3
# via
# pygithub
# sphinx
rocm-docs-core==1.11.0
rocm-docs-core==1.12.0
# via -r requirements.in
smmap==5.0.1
# via gitdb
Expand Down
4 changes: 4 additions & 0 deletions examples/diffusion/python_stable_diffusion_3/txt2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ def encode_token_weights(self, model_name, token_weight_pairs):
def get_embeddings(self, prompt_tokens):
l_out, l_pooled = self.encode_token_weights("clip-l",
prompt_tokens["l"])
# stable-diffusion-3-lite-onnx has swapped outputs for clip-l text encoder
if l_out.shape != (1, 77, 768):
l_out, l_pooled = l_pooled, l_out

g_out, g_pooled = self.encode_token_weights("clip-g",
prompt_tokens["g"])
if not self.skip_t5:
Expand Down
2 changes: 1 addition & 1 deletion hip-clang.docker
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG PREFIX=/usr/local
RUN dpkg --add-architecture i386

# Add rocm repository
RUN sh -c 'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/6.2/ focal main > /etc/apt/sources.list.d/rocm.list'
RUN sh -c 'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/6.3/ jammy main > /etc/apt/sources.list.d/rocm.list'

# From docs.amd.com for installing rocm. Needed to install properly
RUN sh -c "echo 'Package: *\nPin: release o=repo.radeon.com\nPin-priority: 600' > /etc/apt/preferences.d/rocm-pin-600"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ pybind/pybind11@3e9dfa2866941655c56877882565e7577de6fc7b --build
msgpack/[email protected] -DMSGPACK_BUILD_TESTS=Off
sqlite3@3.43.2 -DCMAKE_POSITION_INDEPENDENT_CODE=On
ROCm/composable_kernel@b7775add2d28251674d81e220cd4a857b90b997a -DCK_BUILD_JIT_LIB=On -DCMAKE_POSITION_INDEPENDENT_CODE=On
ROCm/rocMLIR@e61b0f0e516f09144445b3c8eb372f39eb82d53b -DBUILD_FAT_LIBROCKCOMPILER=On
ROCm/rocMLIR@13065c4b3a216e1b13dfb8f746b8a0d421f124e8 -DBUILD_FAT_LIBROCKCOMPILER=On
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_library(migraphx
argument.cpp
autocast_fp8.cpp
auto_contiguous.cpp
base64.cpp
common.cpp
common_dims.cpp
compile_src.cpp
Expand Down Expand Up @@ -74,6 +75,7 @@ add_library(migraphx
memory_coloring.cpp
module.cpp
msgpack.cpp
netron_output.cpp
normalize_attributes.cpp
normalize_ops.cpp
op_enums.cpp
Expand Down
81 changes: 81 additions & 0 deletions src/base64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <migraphx/base64.hpp>
#include <vector>
#include <array>
#include <iostream>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {

namespace {
using byte = unsigned char;

std::array<char, 64> constexpr b64_chars{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};

/// base64 encoder snippet altered from https://stackoverflow.com/a/37109258
std::string encode(const std::vector<byte>& buf)
{
std::size_t len = buf.size();
std::vector<byte> res_vec((len + 2) / 3 * 4, '=');
std::size_t j = 0;
std::size_t remaining = len % 3;
const size_t last = len - remaining;

for(size_t i = 0; i < last; i += 3)
{
std::size_t n = static_cast<std::size_t>(buf.at(i)) << 16u |
static_cast<std::size_t>(buf.at(i + 1)) << 8u |
static_cast<std::size_t>(buf.at(i + 2));
res_vec.at(j++) = b64_chars.at(n >> 18u);
res_vec.at(j++) = b64_chars.at(n >> 12u & 0x3Fu);
res_vec.at(j++) = b64_chars.at(n >> 6u & 0x3Fu);
res_vec.at(j++) = b64_chars.at(n & 0x3Fu);
}
// Set padding
if(remaining != 0)
{
std::size_t n = --remaining == 0 ? static_cast<std::size_t>(buf.at(last))
: static_cast<std::size_t>(buf.at(last)) << 8u |
static_cast<std::size_t>(buf.at(last + 1));
res_vec.at(j++) = b64_chars.at(remaining == 0 ? n >> 2u : n >> 10u & 0x3Fu);
res_vec.at(j++) = b64_chars.at(remaining == 0 ? n << 4u & 0x3Fu : n >> 4u & 0x03Fu);
res_vec.at(j++) = remaining == 0 ? '=' : b64_chars.at(n << 2u & 0x3Fu);
}
return {res_vec.begin(), res_vec.end()};
}

} // namespace

std::string base64_encode(const std::string& str)
{
return encode(std::vector<byte>(str.begin(), str.end()));
}

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
18 changes: 18 additions & 0 deletions src/driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#include <migraphx/simplify_reshapes.hpp>
#include <migraphx/register_target.hpp>

#include <migraphx/netron_output.hpp>

#include <fstream>

namespace migraphx {
Expand Down Expand Up @@ -166,6 +168,10 @@ struct loader
{"--binary"},
ap.help("Print out program in binary format."),
ap.set_value("binary"));
ap(output_type,
{"--netron"},
ap.help("Print out program as Netron readable json."),
ap.set_value("netron"));
ap(output, {"--output", "-o"}, ap.help("Output to file."));
}

Expand Down Expand Up @@ -418,6 +424,8 @@ struct loader
*os << to_json_string(p.to_value()) << std::endl;
else if(type == "binary")
write(*os, save_buffer(p));
else if(type == "netron")
*os << make_netron_output(p) << std::endl;
}
};

Expand Down Expand Up @@ -482,6 +490,7 @@ struct compiler
compiler_target ct;
compile_options co;
bool to_fp16 = false;
bool to_bf16 = false;
bool to_fp8 = false;
bool to_int8 = false;
bool to_int4 = false;
Expand All @@ -506,6 +515,7 @@ struct compiler
ap.help("Exhastively search for best tuning parameters for kernels"),
ap.set_value(true));
ap(to_fp16, {"--fp16"}, ap.help("Quantize for fp16"), ap.set_value(true));
ap(to_bf16, {"--bf16"}, ap.help("Quantize for bf16"), ap.set_value(true));
ap(to_int8, {"--int8"}, ap.help("Quantize for int8"), ap.set_value(true));
ap(to_fp8, {"--fp8"}, ap.help("Quantize for fp8"), ap.set_value(true));
ap(to_int4, {"--int4-weights"}, ap.help("Quantize weights for int4"), ap.set_value(true));
Expand Down Expand Up @@ -555,6 +565,10 @@ struct compiler
{
quantize_fp16(p);
}
if(to_bf16)
{
quantize_bf16(p);
}
if(to_int8)
{
quantize_int8(p, t, {host_params(p)});
Expand Down Expand Up @@ -639,6 +653,10 @@ struct verify : command<verify>
{
vo.quantize = precision::fp16;
}
if(c.to_bf16)
{
vo.quantize = precision::bf16;
}
if(c.to_int8)
{
vo.quantize = precision::int8;
Expand Down
1 change: 1 addition & 0 deletions src/driver/precision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum class precision
{
fp32,
fp16,
bf16,
int8
};

Expand Down
13 changes: 10 additions & 3 deletions src/driver/verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ verify::tolerance get_tolerances(const program& p,
std::optional<double> atol,
std::optional<double> rtol)
{
bool has_fp16 = any_of(p.get_modules(), [](auto&& m) {
return any_of(*m, [](auto&& ins) { return (ins.get_shape().type() == shape::half_type); });
bool has_16bit = any_of(p.get_modules(), [](auto&& m) {
return any_of(*m, [](auto&& ins) {
return (ins.get_shape().type() == shape::half_type or
ins.get_shape().type() == shape::bf16_type);
});
});
migraphx::verify::tolerance result{};
if(has_fp16 or vo.quantize == precision::fp16)
if(has_16bit or vo.quantize == precision::fp16 or vo.quantize == precision::bf16)
{
result.rms_tol = 8e-2;
result.atol = 4e-2;
Expand Down Expand Up @@ -100,6 +103,10 @@ std::vector<argument> run_target(program p,
{
quantize_fp16(p);
}
if(vo.quantize == precision::bf16)
{
quantize_bf16(p);
}
p.compile(t, options);

parameter_map m;
Expand Down
39 changes: 39 additions & 0 deletions src/include/migraphx/base64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MIGRAPHX_GUARD_RTGLIB_BASE64_HPP
#define MIGRAPHX_GUARD_RTGLIB_BASE64_HPP

#include <string>
#include <migraphx/config.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {

/// encode string to base64
std::string base64_encode(const std::string& str);

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx

#endif
39 changes: 39 additions & 0 deletions src/include/migraphx/netron_output.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MIGRAPHX_GUARD_RTGLIB_NETRON_OUTPUT_HPP
#define MIGRAPHX_GUARD_RTGLIB_NETRON_OUTPUT_HPP

#include <string>
#include <migraphx/config.hpp>
#include <migraphx/program.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {

MIGRAPHX_EXPORT std::string make_netron_output(const program& prog);

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx

#endif
3 changes: 3 additions & 0 deletions src/include/migraphx/quantization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ quantize_fp8(program& prog, const target& t, const std::vector<parameter_map>& c

MIGRAPHX_EXPORT void quantize_int4_weights(program& prog);

MIGRAPHX_EXPORT void quantize_bf16(program& prog,
const std::vector<std::string>& ins_names = {"all"});

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx

Expand Down
Loading

0 comments on commit 2f2dda1

Please sign in to comment.