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

Fix Python bindings for TensorMemory #655

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
cdfdcfc
Expose constructors for TensorMemory, InferenceMemory and ResponseMem…
dagardner-nv Jan 20, 2023
4b353ec
Remove un-needed print statement
dagardner-nv Jan 20, 2023
ca9f5a2
Update tests
dagardner-nv Jan 20, 2023
e2022bc
add a tensors property
dagardner-nv Jan 20, 2023
8d5dfaf
Merge branch 'branch-23.01' into david-constructors-604
dagardner-nv Jan 23, 2023
47788b0
Merge branch 'branch-23.01' into david-constructors-604
dagardner-nv Jan 26, 2023
ae0f480
Merge branch 'branch-23.01' into david-constructors-604
dagardner-nv Jan 26, 2023
26cb7bf
Use a type alias
dagardner-nv Jan 27, 2023
00815f6
WIP
dagardner-nv Jan 27, 2023
5e84e64
Merge branch 'branch-23.01' into david-constructors-604
dagardner-nv Jan 27, 2023
f9a317c
Fix bad copy-paste
dagardner-nv Jan 28, 2023
91f58ca
Set docstring on property method
dagardner-nv Jan 28, 2023
6d85a52
Move cupy_to_tensors and tensors_to_cupy to CupyUtil
dagardner-nv Jan 28, 2023
648ca0a
wip - not working
dagardner-nv Jan 28, 2023
158e7e7
wip
dagardner-nv Jan 28, 2023
7341d02
Fix constructor args
dagardner-nv Jan 30, 2023
392eb44
tests wip
dagardner-nv Jan 30, 2023
e3c7f41
Merge branch 'branch-23.01' into david-constructors-604
dagardner-nv Jan 30, 2023
952cfeb
wip
dagardner-nv Jan 30, 2023
ac6f381
Merge branch 'branch-23.01' into david-constructors-604
dagardner-nv Jan 30, 2023
b443ac0
Finish tests
dagardner-nv Jan 30, 2023
9a6d1cd
Ensure popen is defined
dagardner-nv Jan 30, 2023
87b63c3
Move tensor_map_t
dagardner-nv Jan 30, 2023
f64c895
wip
dagardner-nv Jan 30, 2023
7fc1c71
Use typedef
dagardner-nv Jan 30, 2023
db2bb9f
Remove unused namespace alias
dagardner-nv Jan 30, 2023
e3ae25d
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Jan 31, 2023
5111825
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Feb 1, 2023
65872e7
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Feb 7, 2023
75a9e4e
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Feb 8, 2023
d428e16
Replace the tensor property with explicit get_tensors and set_tensors…
dagardner-nv Feb 8, 2023
98c02e9
Exclude tensors from the repr
dagardner-nv Feb 8, 2023
fc58151
Exclude tensors from generated eq and hash
dagardner-nv Feb 8, 2023
e12fb17
Actually return the attr :)
dagardner-nv Feb 8, 2023
90d1c3d
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Feb 13, 2023
3749c45
Add & adopt get_tensor and set_tensor methods
dagardner-nv Feb 13, 2023
c4ba089
wip
dagardner-nv Feb 14, 2023
bce1ec3
wip
dagardner-nv Feb 14, 2023
24b62f8
Interface proxy classes for TensorMemory subclasses now inherit from …
dagardner-nv Feb 14, 2023
cfb6cb9
Make get_input, set_input, get_output & set_output methods actual cla…
dagardner-nv Feb 14, 2023
aac60f9
Add py::args to bindings
dagardner-nv Feb 14, 2023
6e12412
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Feb 14, 2023
def8a98
Rempove debug print statements
dagardner-nv Feb 14, 2023
a6e63ee
Merge branch 'david-constructors-604' of github.com:dagardner-nv/Morp…
dagardner-nv Feb 14, 2023
5f7cba3
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Feb 15, 2023
86ec93a
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Feb 16, 2023
0bdeefb
Testing removing some pybind includes to see if IWYU flags it.
mdemoret-nv Feb 22, 2023
2591b70
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Feb 22, 2023
59c03cb
Fix bug where tensors was static
dagardner-nv Feb 24, 2023
2e993cd
Set default value for tensors to none
dagardner-nv Feb 24, 2023
c70d3bf
Remove out of date dataclass
dagardner-nv Feb 24, 2023
94bbe6b
Remove get_tensor_object
dagardner-nv Feb 24, 2023
e1c0823
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Feb 24, 2023
b9eb78a
Fix missed merge conflict
dagardner-nv Feb 24, 2023
8380a83
Check tensor lengths match the count, use moves for tensor objects
dagardner-nv Feb 24, 2023
64265e0
Ensure tensor lengths match the count
dagardner-nv Feb 24, 2023
e96f8c2
Fix tests
dagardner-nv Feb 25, 2023
c68b0f7
Add type hints
dagardner-nv Feb 25, 2023
408f67b
Merge branch 'branch-23.03' into david-constructors-604
dagardner-nv Feb 28, 2023
56d46c4
Add type hint
dagardner-nv Feb 28, 2023
ddd4da7
Remove optional num_selected_rows arg, it wasn't needed
dagardner-nv Feb 28, 2023
14d8d47
Fix bad copy/paste docstring
dagardner-nv Feb 28, 2023
47efc93
Move tensor memory classes to their own modules
dagardner-nv Feb 28, 2023
8c91579
First pass at python MultiTensorMessage class
dagardner-nv Feb 28, 2023
2b773bb
wip
dagardner-nv Feb 28, 2023
b31b02f
wip
dagardner-nv Feb 28, 2023
d04685b
wip
dagardner-nv Feb 28, 2023
0e3dc97
wip
dagardner-nv Feb 28, 2023
6e0c263
Edge connectors
dagardner-nv Feb 28, 2023
eaaaeb0
bindings for MultiTensorMessage
dagardner-nv Feb 28, 2023
8333577
wip
dagardner-nv Feb 28, 2023
fc41741
cleanups
dagardner-nv Feb 28, 2023
0522823
cleanups
dagardner-nv Feb 28, 2023
8c748e7
Insert license
dagardner-nv Feb 28, 2023
5a3cebb
IWYU fixes
dagardner-nv Feb 28, 2023
3635018
Formatting
dagardner-nv Feb 28, 2023
c8898c4
wip
dagardner-nv Mar 6, 2023
99f0630
Merge branch 'branch-23.03' into david-constructors-604 [no ci]
dagardner-nv Mar 6, 2023
7597545
Fix merge error
dagardner-nv Mar 6, 2023
e0051ff
Throw key_error when used in a get method, and attribute_error when b…
dagardner-nv Mar 6, 2023
79c35e7
Raise a KeyError when used in a get method, and AttributeError when b…
dagardner-nv Mar 6, 2023
8b3527b
ResponseMemoryAE should subclass ResponseMemoryProbs
dagardner-nv Mar 6, 2023
ca84ceb
IWYU fixes
dagardner-nv Mar 6, 2023
6ff4a33
wip
dagardner-nv Mar 6, 2023
f2a80fd
wip [no ci]
dagardner-nv Mar 7, 2023
01b1852
Raise AttributeError only for attributes [no ci]
dagardner-nv Mar 7, 2023
13ff166
Formatting and IWYU
dagardner-nv Mar 7, 2023
7be55fb
Remove unused import
dagardner-nv Mar 7, 2023
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
3 changes: 3 additions & 0 deletions ci/iwyu/mappings.imp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
# Protobuf
{ "include": [ "<google/protobuf/repeated_ptr_field.h>", private, "<google/protobuf/repeated_field.h>", "public" ] },

# pybind11
{ "include": [ "<pybind11/detail/common.h>", private, "<pybind11/pytypes.h>", "public" ] },

# rxcpp
# Hide includes that are exported by <rxcpp/rx.hpp>
{ "include": [ "\"rx-includes.hpp\"", private, "<rxcpp/rx.hpp>", "public" ] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#include "morpheus/messages/memory/tensor_memory.hpp"
#include "morpheus/types.hpp" // for TensorMap

#include <cstddef>
#include <pybind11/pytypes.h> // for object

#include <cstddef> // for size_t
#include <memory> // for shared_ptr
#include <string>

namespace morpheus {
Expand Down Expand Up @@ -54,7 +57,7 @@ class InferenceMemory : public TensorMemory
InferenceMemory(size_t count, TensorMap&& tensors);

/**
* @brief Checks if a tensor named `name` exists in `tensors`
* @brief Checks if a tensor named `name` exists in `tensors`. Alias for `has_tensor`.
*
* @param name
* @return true
Expand All @@ -67,15 +70,17 @@ class InferenceMemory : public TensorMemory
/**
* @brief Interface proxy, used to insulate python bindings.
*/
struct InferenceMemoryInterfaceProxy
struct InferenceMemoryInterfaceProxy : public TensorMemoryInterfaceProxy
{
/**
* @brief Get the count object
* @brief Create and initialize a InferenceMemory object, and return a shared pointer to the result. Each array in
* `tensors` should be of length `count`.
*
* @param self
* @return std::size_t
* @param count : Lenght of each array in `tensors`
* @param tensors : Map of string on to cupy arrays
* @return std::shared_ptr<InferenceMemory>
*/
static std::size_t get_count(InferenceMemory& self);
static std::shared_ptr<InferenceMemory> init(std::size_t count, pybind11::object& tensors);
};
#pragma GCC visibility pop

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <cstddef>
#include <memory>
#include <string>

namespace morpheus {
/****** Component public implementations *******************/
Expand All @@ -52,7 +51,7 @@ class InferenceMemoryFIL : public InferenceMemory
* @param seq_ids : Ids used to index from an inference input to a message. Necessary since there can be more
* inference inputs than messages (i.e., if some messages get broken into multiple inference requests)
*/
InferenceMemoryFIL(size_t count, TensorObject input__0, TensorObject seq_ids);
InferenceMemoryFIL(size_t count, TensorObject&& input__0, TensorObject&& seq_ids);

/**
* @brief Returns the 'input__0' tensor, throws a `std::runtime_error` if it does not exist
Expand All @@ -73,27 +72,26 @@ class InferenceMemoryFIL : public InferenceMemory
/**
* @brief Sets a tensor named 'input__0'
*
* @param input_ids
* @throw std::runtime_error
* @throw std::runtime_error
* @param input__0
* @throws std::length_error If the number of rows in `input__0` does not match `count`.
*/
void set_input__0(TensorObject input_ids);
void set_input__0(TensorObject&& input__0);

/**
* @brief Sets a tensor named 'seq_ids'
*
* @param seq_ids
* @throw std::runtime_error
* @throws std::length_error If the number of rows in `seq_ids` does not match `count`.
*/
void set_seq_ids(TensorObject seq_ids);
void set_seq_ids(TensorObject&& seq_ids);
};

/****** InferenceMemoryFILInterfaceProxy *************************/
#pragma GCC visibility push(default)
/**
* @brief Interface proxy, used to insulate python bindings
*/
struct InferenceMemoryFILInterfaceProxy
struct InferenceMemoryFILInterfaceProxy : public InferenceMemoryInterfaceProxy
{
/**
* @brief Create and initialize an InferenceMemoryFIL object, and return a shared pointer to the result
Expand All @@ -108,23 +106,6 @@ struct InferenceMemoryFILInterfaceProxy
pybind11::object input__0,
pybind11::object seq_ids);

/**
* Get messages count in the inference memory instance
*
* @param self
* @return std::size_t
*/
static std::size_t count(InferenceMemoryFIL& self);

/**
* Return the requested tensor for a given name
*
* @param self
* @param name Tensor name
* @return TensorObject
*/
static TensorObject get_tensor(InferenceMemoryFIL& self, const std::string& name);

/**
* @brief Returns the 'input__0' as cupy array
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,57 +52,63 @@ class InferenceMemoryNLP : public InferenceMemory
* @param seq_ids : Ids used to index from an inference input to a message. Necessary since there can be more
inference inputs than messages (i.e., if some messages get broken into multiple inference requests)
*/
InferenceMemoryNLP(std::size_t count, TensorObject input_ids, TensorObject input_mask, TensorObject seq_ids);
InferenceMemoryNLP(std::size_t count, TensorObject&& input_ids, TensorObject&& input_mask, TensorObject&& seq_ids);

/**
* @brief Get the input ids object
*
* @return const TensorObject&
* @throws std::runtime_error If no tensor named "input_ids" exists
*/
const TensorObject& get_input_ids() const;

/**
* @brief Get the input mask object
*
* @return const TensorObject&
* @throws std::runtime_error If no tensor named "input_mask" exists
*/
const TensorObject& get_input_mask() const;

/**
* @brief Get the seq ids object
*
* @return const TensorObject&
* @throws std::runtime_error If no tensor named "seq_ids" exists
*/
const TensorObject& get_seq_ids() const;

/**
* @brief Set the input ids object
*
* @param input_ids
* @throws std::length_error If the number of rows in `input_ids` does not match `count`.
*/
void set_input_ids(TensorObject input_ids);
void set_input_ids(TensorObject&& input_ids);

/**
* @brief Set the input mask object
*
* @param input_mask
* @throws std::length_error If the number of rows in `input_mask` does not match `count`.
*/
void set_input_mask(TensorObject input_mask);
void set_input_mask(TensorObject&& input_mask);

/**
* @brief Set the seq ids object
*
* @param seq_ids
* @throws std::length_error If the number of rows in `seq_ids` does not match `count`.
*/
void set_seq_ids(TensorObject seq_ids);
void set_seq_ids(TensorObject&& seq_ids);
};

/****** InferenceMemoryNLPInterfaceProxy********************/
#pragma GCC visibility push(default)
/**
* @brief Interface proxy, used to insulate python bindings.
*/
struct InferenceMemoryNLPInterfaceProxy
struct InferenceMemoryNLPInterfaceProxy : public InferenceMemoryInterfaceProxy
{
/**
* @brief Create and initialize an InferenceMemoryNLP object, and return a shared pointer to the result
Expand All @@ -119,19 +125,12 @@ struct InferenceMemoryNLPInterfaceProxy
pybind11::object input_mask,
pybind11::object seq_ids);

/**
* Get messages count in the inference memory object
*
* @param self
* @return std::size_t
*/
static std::size_t count(InferenceMemoryNLP& self);

/**
* @brief : Returns token-ids for each string padded with 0s to max_length as python object
*
* @param self
* @return pybind11::object
* @throws pybind11::attribute_error
*/
static pybind11::object get_input_ids(InferenceMemoryNLP& self);

Expand All @@ -148,6 +147,7 @@ struct InferenceMemoryNLPInterfaceProxy
*
* @param self
* @return pybind11::object
* @throws pybind11::attribute_error
*/
static pybind11::object get_input_mask(InferenceMemoryNLP& self);

Expand All @@ -164,6 +164,7 @@ struct InferenceMemoryNLPInterfaceProxy
*
* @param self
* @return pybind11::object
* @throws pybind11::attribute_error
*/
static pybind11::object get_seq_ids(InferenceMemoryNLP& self);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
#pragma once

#include "morpheus/messages/memory/tensor_memory.hpp"
#include "morpheus/objects/tensor_object.hpp" // for TensorObject
#include "morpheus/types.hpp" // for TensorMap
#include "morpheus/types.hpp" // for TensorMap

#include <pybind11/pytypes.h>
#include <pybind11/pytypes.h> // for object

#include <cstddef> // for size_t
#include <memory> // for shared_ptr
#include <string>

namespace morpheus {
Expand Down Expand Up @@ -57,7 +57,7 @@ class ResponseMemory : public TensorMemory
ResponseMemory(size_t count, TensorMap&& tensors);

/**
* @brief Checks if a tensor named `name` exists in `tensors`
* @brief Checks if a tensor named `name` exists in `tensors`. Alias for `has_tensor`.
*
* @param name
* @return true
Expand All @@ -72,25 +72,17 @@ class ResponseMemory : public TensorMemory
* @brief Interface proxy, used to insulate python bindings.
*
*/
struct ResponseMemoryInterfaceProxy
struct ResponseMemoryInterfaceProxy : public TensorMemoryInterfaceProxy
{
/**
* @brief Get the output object
* @brief Create and initialize a ResponseMemory object, and return a shared pointer to the result. Each array in
* `cupy_tensors` should be of length `count`.
*
* @param self
* @param name
* @return pybind11::object
*/
static pybind11::object get_output(ResponseMemory& self, const std::string& name);

/**
* @brief Get the output tensor object
*
* @param self
* @param name
* @return TensorObject
* @param count : Lenght of each array in `cupy_tensors`
* @param cupy_tensors : Map of string on to cupy arrays
* @return std::shared_ptr<ResponseMemory>
*/
static TensorObject get_output_tensor(ResponseMemory& self, const std::string& name);
static std::shared_ptr<ResponseMemory> init(std::size_t count, pybind11::object& tensors);
};
#pragma GCC visibility pop

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ResponseMemoryProbs : public ResponseMemory
* @param count
* @param probs
*/
ResponseMemoryProbs(size_t count, TensorObject probs);
ResponseMemoryProbs(size_t count, TensorObject&& probs);
/**
* @brief Construct a new Response Memory Probs object
*
Expand All @@ -60,26 +60,28 @@ class ResponseMemoryProbs : public ResponseMemory
ResponseMemoryProbs(size_t count, TensorMap&& tensors);

/**
* @brief Returns the tensor named 'probs', throws a `std::runtime_error` if it does not exist
* @brief Returns the tensor named 'probs'. alias for `get_tensor("probs")`
*
* @return const TensorObject&
* @throws std::runtime_error If no tensor named "probs" exists
*/
const TensorObject& get_probs() const;

/**
* @brief Update the tensor named 'probs'
*
* @param probs
* @throws std::length_error If the number of rows in `probs` does not match `count`.
*/
void set_probs(TensorObject probs);
void set_probs(TensorObject&& probs);
};

/****** ResponseMemoryProbsInterfaceProxy*******************/
#pragma GCC visibility push(default)
/**
* @brief Interface proxy, used to insulate python bindings
*/
struct ResponseMemoryProbsInterfaceProxy
struct ResponseMemoryProbsInterfaceProxy : public ResponseMemoryInterfaceProxy
{
/**
* @brief Create and initialize a ResponseMemoryProbs object, and return a shared pointer to the result
Expand All @@ -91,23 +93,16 @@ struct ResponseMemoryProbsInterfaceProxy
static std::shared_ptr<ResponseMemoryProbs> init(cudf::size_type count, pybind11::object probs);

/**
* @brief Get messages count in the response memory probs object
*
* @param self
* @return std::size_t
*/
static std::size_t count(ResponseMemoryProbs& self);

/**
* @brief Get the response memory probs object
* @brief Get the response memory probs object ()
*
* @param self
* @return pybind11::object
* @throws pybind11::key_error When no tensor named "probs" exists.
*/
static pybind11::object get_probs(ResponseMemoryProbs& self);

/**
* @brief Set the response memory probs object
* @brief Set the response memory probs object (alias for `set_tensor("probs", cupy_values)`)
*
* @param self
* @param cupy_values
Expand Down
Loading