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

RSDK-4196 Add support for flat tensors in mlmodel #122

Merged
merged 2 commits into from
Aug 1, 2023

Conversation

acmorrow
Copy link
Member

Updates the C++ SDK to support the changes from viamrobotics/api#279.

@acmorrow acmorrow requested a review from a team as a code owner June 27, 2023 12:59
@acmorrow acmorrow requested review from njooma and removed request for a team June 27, 2023 12:59
@@ -10,6 +10,7 @@
# performance-move-const-arg: TODO(RSDK-3019)
# misc-unused-parameters: TODO(RSDK-3008) remove this and fix all lints.
# readability-function-cognitive-complexity: No, complexity is subjective and sometimes necessary.
# readability-else-after-return: No, this causes code complexification
Copy link
Member Author

Choose a reason for hiding this comment

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

This clang-tidy rule makes the following a lint error:

if (foo) {
    return x;
} else if (bar) {
    return y;
} else {
    return z;
}

And requires that it be written:

if (foo) {
    return x;
}

if (bar) {
    return y;
}

return z;

Which just feels unnecessary. I think I get what they are trying to do, which is to avoid the following:

if (!result) {
    return error;
} else {
    return success;
}

In favor of:

if (!result) {
    return error;
}

return success;

Which is a change i would generally support. But it doesn't work well at all for the big ladders of conditionals I need to write to handle the various type cases in this PR. I tried living with it and it caused me distress so I disabled the check.

If others feel differently I can restore the check and make the mechanical changes to placate the linter.

mlmodel_details::tensor_storage storage;
MLModelService::named_tensor_views views;
};
constexpr bool kUseFlatTensors = true;
Copy link
Member Author

Choose a reason for hiding this comment

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

I've opted to leave the existing struct based implementation in place so I can easily A/B test. All code selected by kUseFlatTensors = false would be removable if we decided to make a breaking change.

@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <memory>
Copy link
Member Author

Choose a reason for hiding this comment

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

I've moved these down where they belong.

@stuqdog stuqdog removed the request for review from njooma June 27, 2023 13:10
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

LGTM!

if (!data || (size == 0) || shape.empty()) {
std::ostringstream message;
message << "Empty or zero length data or shape";
throw std::invalid_argument(message.str());
Copy link
Member

Choose a reason for hiding this comment

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

(q) just for my own clarity, what is message doing here? Naively it looks like we're adding a string and then immediately unpacking that string.

Copy link
Member Author

Choose a reason for hiding this comment

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

@stuqdog - Merely copy paste from other places where I was adding some state to the string, but here I'm not. I'll remove it.

@kharijarrett kharijarrett removed their request for review July 10, 2023 14:24
Copy link
Member

@bhaney bhaney left a comment

Choose a reason for hiding this comment

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

looked like there wasn't much to change, but you also mentioned how you already wrote a lot with flat-tensors in mind. LGTM!

@acmorrow acmorrow changed the title PoC flat tensors for MLModel interface in C++ SDK RSDK-4196 Add support for flat tensors in mlmodel Aug 1, 2023
@acmorrow acmorrow merged commit 5f19d94 into viamrobotics:main Aug 1, 2023
2 checks passed
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.

3 participants