"test/git@developer.sourcefind.cn:zhaoyu6/sglang.git" did not exist on "930fe467bdc99e54c61dd63e69f5aa0a817b15e3"
Commit 63952fb9 authored by Brian Pickrell's avatar Brian Pickrell
Browse files

Merge branch 'develop' into multinomial_parse

parents 61f3895c e7471141
...@@ -743,6 +743,33 @@ def clip_test_args_type_mismatch(): ...@@ -743,6 +743,33 @@ def clip_test_args_type_mismatch():
return ([node], [x], [y], [min_val, max_val]) return ([node], [x], [y], [min_val, max_val])
@onnx_test()
def clip_dyn_min_max_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [None])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [None])
min_val = helper.make_tensor('min', TensorProto.FLOAT, [], [0.0])
max_val = helper.make_tensor('max', TensorProto.FLOAT, [], [6.0])
node = onnx.helper.make_node('Clip',
inputs=['0', 'min', 'max'],
outputs=['1'])
return ([node], [x], [y], [min_val, max_val])
@onnx_test()
def clip_dyn_min_only_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [None])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT, [None])
min_val = helper.make_tensor('min', TensorProto.FLOAT, [], [0.0])
node = onnx.helper.make_node('Clip', inputs=['0', 'min'], outputs=['1'])
return ([node], [x], [y], [min_val])
@onnx_test() @onnx_test()
def concat_test(): def concat_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 4, 3]) x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [2, 4, 3])
......
...@@ -823,6 +823,47 @@ TEST_CASE(clip_test_args_type_mismatch) ...@@ -823,6 +823,47 @@ TEST_CASE(clip_test_args_type_mismatch)
EXPECT(p == prog); EXPECT(p == prog);
} }
TEST_CASE(clip_dyn_min_max_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto min_val = mm->add_literal(0.0f);
auto max_val = mm->add_literal(6.0f);
std::vector<migraphx::shape::dynamic_dimension> dds = {{2, 8, {3}}};
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, dds});
min_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_dyn_dims", to_value(dds)}}), min_val, l0);
max_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_dyn_dims", to_value(dds)}}), max_val, l0);
auto ret = mm->add_instruction(migraphx::make_op("clip"), l0, min_val, max_val);
mm->add_return({ret});
migraphx::onnx_options options;
options.default_dyn_dim_value = {2, 8, {3}};
auto prog = parse_onnx("clip_dyn_min_max_test.onnx", options);
EXPECT(p == prog);
}
TEST_CASE(clip_dyn_min_only_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto min_val = mm->add_literal(0.0f);
std::vector<migraphx::shape::dynamic_dimension> dds = {{2, 8, {3}}};
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, dds});
min_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_dyn_dims", to_value(dds)}}), min_val, l0);
auto ret = mm->add_instruction(migraphx::make_op("max"), l0, min_val);
mm->add_return({ret});
migraphx::onnx_options options;
options.default_dyn_dim_value = {2, 8, {3}};
auto prog = parse_onnx("clip_dyn_min_only_test.onnx", options);
EXPECT(p == prog);
}
TEST_CASE(concat_test) TEST_CASE(concat_test)
{ {
migraphx::program p; migraphx::program p;
......
...@@ -82,13 +82,17 @@ TEST_CASE(param_add) ...@@ -82,13 +82,17 @@ TEST_CASE(param_add)
auto hp1 = mm->add_instruction(migraphx::make_op("convert"), p1); auto hp1 = mm->add_instruction(migraphx::make_op("convert"), p1);
auto hp2 = mm->add_instruction(migraphx::make_op("convert"), p2); auto hp2 = mm->add_instruction(migraphx::make_op("convert"), p2);
auto hs = mm->add_instruction(migraphx::make_op("add"), hp1, hp2); auto hs = mm->add_instruction(migraphx::make_op("add"), hp1, hp2);
auto res = mm->add_instruction( auto fs = mm->add_instruction(
migraphx::make_op("convert", migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::float_type)}}), {{"target_type", migraphx::to_value(migraphx::shape::float_type)}}),
hs); hs);
if(add_return) if(add_return)
{ {
mm->add_return({res}); mm->add_return({fs});
}
else
{
mm->add_instruction(migraphx::make_op("identity"), {fs});
} }
return p; return p;
...@@ -159,10 +163,10 @@ TEST_CASE(param_add_sub) ...@@ -159,10 +163,10 @@ TEST_CASE(param_add_sub)
auto diff = mm->add_instruction(migraphx::make_op("sub"), sum, p2); auto diff = mm->add_instruction(migraphx::make_op("sub"), sum, p2);
auto hdiff = mm->add_instruction( auto hdiff = mm->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::half_type}}), diff); migraphx::make_op("convert", {{"target_type", migraphx::shape::half_type}}), diff);
auto res = mm->add_instruction(migraphx::make_op("add"), hdiff, hp1); auto hadd = mm->add_instruction(migraphx::make_op("add"), hdiff, hp1);
auto r = mm->add_instruction( auto fadd = mm->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::float_type}}), res); migraphx::make_op("convert", {{"target_type", migraphx::shape::float_type}}), hadd);
mm->add_return({r}); mm->add_return({fadd});
return p; return p;
}; };
...@@ -258,7 +262,8 @@ TEST_CASE(param_add_sub) ...@@ -258,7 +262,8 @@ TEST_CASE(param_add_sub)
}; };
auto p0 = create_program_float(); auto p0 = create_program_float();
migraphx::run_passes(p0, {migraphx::quantize_fp16_pass{{"all"}}}); migraphx::run_passes(
p0, {migraphx::quantize_fp16_pass{{"all"}}, migraphx::dead_code_elimination{}});
EXPECT(p0 == create_program_fp16()); EXPECT(p0 == create_program_fp16());
auto p1 = create_program_float(); auto p1 = create_program_float();
...@@ -278,7 +283,6 @@ TEST_CASE(literal_add) ...@@ -278,7 +283,6 @@ TEST_CASE(literal_add)
auto l1 = mm->add_literal(migraphx::literal(s, data)); auto l1 = mm->add_literal(migraphx::literal(s, data));
auto l2 = mm->add_literal(migraphx::literal(s, data)); auto l2 = mm->add_literal(migraphx::literal(s, data));
mm->add_instruction(migraphx::make_op("add"), l1, l2); mm->add_instruction(migraphx::make_op("add"), l1, l2);
return p; return p;
}; };
...@@ -291,11 +295,11 @@ TEST_CASE(literal_add) ...@@ -291,11 +295,11 @@ TEST_CASE(literal_add)
auto l1 = mm->add_literal(migraphx::literal(s, data)); auto l1 = mm->add_literal(migraphx::literal(s, data));
auto l2 = mm->add_literal(migraphx::literal(s, data)); auto l2 = mm->add_literal(migraphx::literal(s, data));
auto hs = mm->add_instruction(migraphx::make_op("add"), l1, l2); auto hs = mm->add_instruction(migraphx::make_op("add"), l1, l2);
mm->add_instruction( auto fs = mm->add_instruction(
migraphx::make_op("convert", migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::float_type)}}), {{"target_type", migraphx::to_value(migraphx::shape::float_type)}}),
hs); hs);
mm->add_instruction(migraphx::make_op("identity"), fs);
return p; return p;
}; };
......
...@@ -850,6 +850,31 @@ TEST_CASE(clip_test) ...@@ -850,6 +850,31 @@ TEST_CASE(clip_test)
EXPECT(migraphx::verify_range(results_vector, gold)); EXPECT(migraphx::verify_range(results_vector, gold));
} }
TEST_CASE(clip_dyn_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<migraphx::shape::dynamic_dimension> dds = {{2, 8, {3}}};
migraphx::shape s{migraphx::shape::float_type, dds};
auto l = mm->add_parameter("X", s);
auto min_val = mm->add_literal(0.0f);
auto max_val = mm->add_literal(6.0f);
min_val = mm->add_instruction(migraphx::make_op("multibroadcast"), min_val, l);
max_val = mm->add_instruction(migraphx::make_op("multibroadcast"), max_val, l);
mm->add_instruction(migraphx::make_op("clip"), l, min_val, max_val);
p.compile(migraphx::make_target("ref"));
migraphx::shape static_shape{migraphx::shape::float_type, {3}};
migraphx::parameter_map params;
std::vector<float> data = {-1.0, 0.0, 10.0};
params["X"] = migraphx::argument(static_shape, data.data());
auto result = p.eval(params).back();
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0.0, 0.0, 6.0};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(concat_test) TEST_CASE(concat_test)
{ {
{ {
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/apply_alpha_beta.hpp>
struct gemm_add_broadcast_half : verify_program<gemm_add_broadcast_half>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::half_type, {1, 2, 3}};
migraphx::shape m2_shape{migraphx::shape::half_type, {1, 3, 4}};
migraphx::shape m3_shape{migraphx::shape::half_type, {1, 1, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto l2 = mm->add_parameter("2", m2_shape);
auto l3 = mm->add_parameter("3", m3_shape);
auto l3_b =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {1, 2, 4}}}), l3);
auto dot = mm->add_instruction(migraphx::make_op("dot"), l1, l2);
mm->add_instruction(migraphx::make_op("add"), dot, l3_b);
return p;
}
};
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/apply_alpha_beta.hpp>
struct gemm_add_half : verify_program<gemm_add_half>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::half_type, {1, 2, 3}};
migraphx::shape m2_shape{migraphx::shape::half_type, {1, 3, 4}};
migraphx::shape m3_shape{migraphx::shape::half_type, {1, 2, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto l2 = mm->add_parameter("2", m2_shape);
auto l3 = mm->add_parameter("3", m3_shape);
auto dot = mm->add_instruction(migraphx::make_op("dot"), l1, l2);
mm->add_instruction(migraphx::make_op("add"), dot, l3);
return p;
}
};
...@@ -38,7 +38,7 @@ struct test_pad_highest : verify_program<test_pad_highest> ...@@ -38,7 +38,7 @@ struct test_pad_highest : verify_program<test_pad_highest>
migraphx::shape s0{migraphx::shape::half_type, {2, 2}}; migraphx::shape s0{migraphx::shape::half_type, {2, 2}};
auto l0 = mm->add_literal(migraphx::literal{s0, data0}); auto l0 = mm->add_literal(migraphx::literal{s0, data0});
migraphx::op::pad op{}; migraphx::op::pad op{};
op.value = std::numeric_limits<float>::max(); op.value = std::numeric_limits<migraphx::half>::max();
op.pads = {0, 0, 1, 1}; op.pads = {0, 0, 1, 1};
mm->add_instruction(op, l0); mm->add_instruction(op, l0);
return p; return p;
......
...@@ -38,7 +38,7 @@ struct test_pad_lowest : verify_program<test_pad_lowest> ...@@ -38,7 +38,7 @@ struct test_pad_lowest : verify_program<test_pad_lowest>
migraphx::shape s0{migraphx::shape::half_type, {2, 2}}; migraphx::shape s0{migraphx::shape::half_type, {2, 2}};
auto l0 = mm->add_literal(migraphx::literal{s0, data0}); auto l0 = mm->add_literal(migraphx::literal{s0, data0});
migraphx::op::pad op{}; migraphx::op::pad op{};
op.value = std::numeric_limits<float>::lowest(); op.value = std::numeric_limits<migraphx::half>::lowest();
op.pads = {0, 0, 1, 1}; op.pads = {0, 0, 1, 1};
mm->add_instruction(op, l0); mm->add_instruction(op, l0);
return p; return p;
......
FROM ubuntu:22.04
ARG PREFIX=/usr/local
# Support multiarch
RUN dpkg --add-architecture i386
# Install rocm key
RUN apt-get update && apt-get install -y gnupg2 --no-install-recommends curl && \
curl -fsSL http://repo.radeon.com/rocm/rocm.gpg.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/rocm-keyring.gpg
# Add rocm repository
RUN sh -c "echo 'deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/rocm-keyring.gpg] http://repo.radeon.com/rocm/apt/5.5 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"
# Install dependencies
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated \
apt-utils \
build-essential \
#clang-format-10 \
cmake \
curl \
doxygen \
#g++-7 \
gdb \
git \
lcov \
locales \
pkg-config \
python3 \
python3-dev \
python3-pip \
software-properties-common \
wget \
rocm-device-libs \
hip-base \
libnuma-dev \
miopen-hip \
rocblas \
hipfft \
rocthrust \
rocrand \
hipsparse \
rccl \
rccl-dev \
rocm-smi-lib \
rocm-dev \
roctracer-dev \
hipcub \
hipblas \
hipify-clang \
half \
libssl-dev \
zlib1g-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# add this for roctracer dependancies
RUN pip3 install CppHeaderParser
# Workaround broken rocm packages
RUN ln -s /opt/rocm-* /opt/rocm
RUN echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf
RUN echo "/opt/rocm/llvm/lib" > /etc/ld.so.conf.d/rocm-llvm.conf
RUN ldconfig
RUN locale-gen en_US.UTF-8
RUN update-locale LANG=en_US.UTF-8
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
# Install dependencies
ADD dev-requirements.txt /dev-requirements.txt
ADD requirements.txt /requirements.txt
ADD rbuild.ini /rbuild.ini
COPY ./tools/install_prereqs.sh /
RUN /install_prereqs.sh /usr/local / && rm /install_prereqs.sh
RUN test -f /usr/local/hash || exit 1
# Install yapf
RUN pip3 install yapf==0.28.0
# Install doc requirements
ADD doc/requirements.txt /doc-requirements.txt
RUN pip3 install -r /doc-requirements.txt
# Download real models to run onnx unit tests
ENV ONNX_HOME=/.onnx
COPY ./tools/download_models.sh /
RUN /download_models.sh && rm /download_models.sh
# Install latest ccache version
RUN cget -p $PREFIX install facebook/zstd@v1.4.5 -X subdir -DCMAKE_DIR=build/cmake
RUN cget -p $PREFIX install ccache@v4.1 -DENABLE_TESTING=OFF
RUN cget -p /opt/cmake install kitware/cmake@v3.24.3
COPY ./test/onnx/.onnxrt-commit /
ARG ONNXRUNTIME_REPO=https://github.com/Microsoft/onnxruntime
ARG ONNXRUNTIME_BRANCH=main
ARG ONNXRUNTIME_COMMIT
RUN git clone --single-branch --branch ${ONNXRUNTIME_BRANCH} --recursive ${ONNXRUNTIME_REPO} onnxruntime && \
cd onnxruntime && \
if [ -z "$ONNXRUNTIME_COMMIT" ] ; then git checkout $(cat /.onnxrt-commit) ; else git checkout ${ONNXRUNTIME_COMMIT} ; fi && \
/bin/sh /onnxruntime/dockerfiles/scripts/install_common_deps.sh
ADD tools/build_and_test_onnxrt.sh /onnxruntime/build_and_test_onnxrt.sh
RUN cget -p /usr/local install ROCmSoftwarePlatform/rocMLIR@a997d5f51314b45d7a4c04f1599966dcf53f9b4d -DBUILD_MIXR_TARGET=On -DLLVM_ENABLE_ZSTD=Off -DLLVM_ENABLE_THREADS=Off
ENV MIOPEN_FIND_DB_PATH=/tmp/miopen/find-db
ENV MIOPEN_USER_DB_PATH=/tmp/miopen/user-db
ENV LD_LIBRARY_PATH=$PREFIX/lib
# Setup ubsan environment to printstacktrace
ENV UBSAN_OPTIONS=print_stacktrace=1
ENV ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1
RUN ln -s /opt/rocm/llvm/bin/llvm-symbolizer /usr/bin/llvm-symbolizer
...@@ -56,8 +56,9 @@ echo "Dependencies are installed at $PREFIX" ...@@ -56,8 +56,9 @@ echo "Dependencies are installed at $PREFIX"
# Install deps with rbuild # Install deps with rbuild
rbuild prepare -d $PREFIX -s develop rbuild prepare -d $PREFIX -s develop
# install onnx package for unit tests export CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=ON"
pip3 install onnx==1.10.2 numpy==1.21.6 typing==3.7.4 pytest==6.0.1 packaging==23.0 pip3 install onnx==1.10.2 numpy==1.21.6 typing==3.7.4 pytest==6.0.1 packaging==23.0
# pin version of protobuf in Python for onnx runtime unit tests # pin version of protobuf in Python for onnx runtime unit tests between dist versions
pip3 install protobuf==3.20.0 pip3 install protobuf==3.20.0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment