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

Add support for the Einsum operator #2772

Merged
merged 42 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e98cf49
Add support for the Einsum operator [WIP]
mirza-halilcevic Feb 14, 2024
8472cce
Merge remote-tracking branch 'upstream/develop' into einsum_support
mirza-halilcevic Feb 28, 2024
b44d80b
Add support for ... broadcasting and limited diagonal support
music-dino Mar 6, 2024
d7c7793
Implement more onnx_verify tests
music-dino Mar 6, 2024
d31932d
Merge remote-tracking branch 'upstream/develop' into einsum_support
music-dino Mar 6, 2024
bcf5015
Add missing gen_onnx.py tests for Einsum.
mirza-halilcevic Mar 6, 2024
fd38cf0
Add missing .onnx verify test files
music-dino Mar 7, 2024
047022e
Add two more einsum diagonal onnx verify tests
music-dino Mar 7, 2024
e2c6279
Add partial documentation
music-dino Mar 7, 2024
31c8aa6
Additional refactoring and documentation.
mirza-halilcevic Mar 7, 2024
dd1306a
Additional refactoring and renaming.
mirza-halilcevic Mar 11, 2024
26637f2
Re-enable onnx backend tests.
mirza-halilcevic Mar 11, 2024
a15ee68
Merge remote-tracking branch 'upstream/develop' into einsum_support
mirza-halilcevic Mar 11, 2024
4ff489e
Refactor gather_diagonal.
mirza-halilcevic Mar 11, 2024
c1448dd
Merge remote-tracking branch 'upstream/develop' into einsum_support
mirza-halilcevic Mar 11, 2024
596f1b9
Addressed several PR review comments.
mirza-halilcevic Mar 20, 2024
8a7e55d
Merge remote-tracking branch 'upstream/develop' into einsum_support
mirza-halilcevic Mar 20, 2024
8537b14
Merge remote-tracking branch 'upstream/develop' into einsum_support
mirza-halilcevic Mar 25, 2024
66de4ba
Address PR review comments
mirza-halilcevic Mar 27, 2024
34c3426
Merge remote-tracking branch 'upstream/develop' into einsum_support
mirza-halilcevic Mar 27, 2024
6b20225
Fix licensing, tidy and format checks.
mirza-halilcevic Mar 27, 2024
01d1cef
Add negative tests.
mirza-halilcevic Mar 28, 2024
3dceee1
Fix formatting and address review comments.
mirza-halilcevic Apr 3, 2024
8df341d
Merge branch 'develop' into einsum_support
causten Apr 19, 2024
366f6dc
Address code review comments.
mirza-halilcevic Apr 29, 2024
53d78db
Add comments explaining unsqueeze_transpose.
mirza-halilcevic Apr 30, 2024
40c9e28
Fix formatting.
mirza-halilcevic May 14, 2024
3db8573
Merge remote-tracking branch 'upstream/develop' into einsum_support
mirza-halilcevic May 14, 2024
3185360
Merge remote-tracking branch 'upstream/develop' into einsum_support
mirza-halilcevic May 14, 2024
45e4ec5
Refactor unsqueeze_transpose and squeeze_transpose.
mirza-halilcevic May 14, 2024
2c3144d
Rename unsqueeze_transpose to transpose_unsqueeze and transpose_squeeze
mirza-halilcevic May 14, 2024
c35c66c
Merge branch 'develop' into einsum_support
causten May 15, 2024
36279ff
Replace ssize_t with int64_t because windows build is failing.
mirza-halilcevic May 16, 2024
350b27c
Merge remote-tracking branch 'upstream/einsum_support' into einsum_su…
mirza-halilcevic May 16, 2024
02418fa
Merge branch 'develop' into einsum_support
causten May 17, 2024
6813ef2
Merge branch 'develop' into einsum_support
causten May 17, 2024
bc7d5cb
Merge remote-tracking branch 'upstream/develop' into einsum_support
mirza-halilcevic May 23, 2024
2542894
Fix onnx test loading.
mirza-halilcevic May 29, 2024
6034347
Merge branch 'develop' into einsum_support
mirza-halilcevic May 29, 2024
2641933
Fix clang-tidy error.
mirza-halilcevic May 29, 2024
980dffc
Merge remote-tracking branch 'upstream/einsum_support' into einsum_su…
mirza-halilcevic May 29, 2024
7140ae2
Fix string_view iterator issue with windows build.
mirza-halilcevic May 29, 2024
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
9 changes: 8 additions & 1 deletion docs/dev/onnx_operators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,14 @@ Operator Support Matrix
| | | | shape is not |
| | | | supported |
+--------------------------+-----------+-----------------+------------------------------+
| Einsum | 👷 | 👷 | |
| Einsum | ✅ | Any | more than 1 diagonal per |
| | | | input is not supported |
| | | | e.g. ``iijj->ij`` |
| | | | |
| | | | batch diagonal where batches |
| | | | are not the leading dims is |
| | | | not supported |
| | | | e.g. ``ii...->i...`` |
+--------------------------+-----------+-----------------+------------------------------+
| Elu | ✅ | FP8, FP16, | |
| | | FP32, FP64 | |
Expand Down
57 changes: 4 additions & 53 deletions src/convert_to_json.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
* 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
Expand All @@ -23,66 +23,17 @@
*/
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <sstream>
#include <migraphx/errors.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/convert_to_json.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/lexing.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {

using token = std::pair<const char*, const char*>;
using lexer = std::function<const char*(const char* start, const char* end)>;

template <class P>
auto lex_while(P p)
{
return [=](const char* start, const char* end) {
return std::find_if(start, end, [&](char c) { return not p(c); });
};
}

template <class P>
auto lex_if(P p)
{
return [=](const char* start, const char*) {
if(p(*start))
return start + 1;
return start;
};
}

std::vector<token> tokenize(const char* start, const char* end, const std::vector<lexer>& lexers)
{
std::vector<token> result;
while(start != end)
{
bool error = true;
for(const auto& l : lexers)
{
const auto* next = l(start, end);
if(next != start)
{
result.emplace_back(start, next);
start = next;
error = false;
break;
}
}

if(error)
{
MIGRAPHX_THROW("TOKENIZE: no token found!");
}
}

return result;
}

std::vector<token> json_tokenize(const std::string& s)
std::vector<std::string_view> json_tokenize(const std::string& s)
{
std::vector<lexer> lexers;

Expand Down Expand Up @@ -133,7 +84,7 @@ std::string convert_to_json(const std::string& str)

for(auto& token : tokens)
{
std::string s(token.first, token.second);
std::string s(token);
if(starts_with(s, "#") or starts_with(s, "//"))
continue;
if(std::isalpha(s.front()) != 0 and
Expand Down
98 changes: 98 additions & 0 deletions src/include/migraphx/lexing.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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_MIGRAPHLIB_LEXING_HPP
#define MIGRAPHX_GUARD_MIGRAPHLIB_LEXING_HPP

#include <functional>
#include <string>
#include <vector>
#include <migraphx/errors.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {

using lexer = std::function<const char*(const char* start, const char* end)>;

template <class P>
inline auto lex_while(P p)
{
return [=](const char* start, const char* end) {
return std::find_if(start, end, [&](char c) { return not p(c); });
};
}

template <class P>
inline auto lex_if(P p)
{
return [=](const char* start, const char*) {
if(p(*start))
return start + 1;
return start;
};
}

inline auto lex_equal(const std::string& s)
{
return [=](const char* start, const char* end) {
auto n = end - start;
if(n < s.size())
return start;
if(std::equal(start, start + s.size(), s.data()))
return start + s.size();
return start;
};
}

inline std::vector<std::string_view>
mirza-halilcevic marked this conversation as resolved.
Show resolved Hide resolved
tokenize(const char* start, const char* end, const std::vector<lexer>& lexers)
{
std::vector<std::string_view> result;
while(start != end)
{
bool error = true;
for(const auto& l : lexers)
{
const auto* next = l(start, end);
if(next != start)
{
result.emplace_back(start, next - start);
start = next;
error = false;
break;
}
}

if(error)
{
MIGRAPHX_THROW("TOKENIZE: no token found!");

Check warning on line 88 in src/include/migraphx/lexing.hpp

View check run for this annotation

Codecov / codecov/patch

src/include/migraphx/lexing.hpp#L88

Added line #L88 was not covered by tests
}
}

return result;
}

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx

#endif
Loading
Loading