-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Conversation
MXInitialise Readies mxnet for use. While this is possible with some other commands this function makes more sense and does not require unneeded variables. MXNDArrayLoadListFromMemory Duplicates MXNDArrayLoad but from a location in memory. This was needed for my work as we bundle models into another file.
include/mxnet/c_api.h
Outdated
* This ensures the engine has been initialised and | ||
* the operators have been registered. | ||
*/ | ||
MXNET_DLL void MXInitialise(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case is it required to call this method? It sounds like this should be documented widely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under the hood it just calls the list symbols method which registers the operators, but this means the purpose of the call is clearer. The examples all call something that calls the same method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Initialize is spelled with a 'z' :)
I can see that, thanks. But that doesn't explain why it was never required
and has not caused any issues so far. Please explain how you encountered a
problem and add a test to cover this case.
Am 26.01.2018 8:00 vorm. schrieb "David Braude" <notifications@github.com>:
… ***@***.**** commented on this pull request.
------------------------------
In include/mxnet/c_api.h
<#9573 (comment)>
:
> @@ -201,6 +201,12 @@ MXNET_DLL const char *MXGetLastError();
* \return 0 when success, -1 when failure happens.
*/
MXNET_DLL int MXRandomSeed(int seed);
+/*!
+ * \brief Initialise MXNet
+ * This ensures the engine has been initialised and
+ * the operators have been registered.
+ */
+MXNET_DLL void MXInitialise();
Under the hood it just calls the list symbols method which registers the
operators, but this means the purpose of the call is clearer.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#9573 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ARxB6zXOVDm644YcG7m1292IseZ7Fh5Dks5tOfa3gaJpZM4RuJS6>
.
|
with just this if you comment out the MXInitialise(): ` int main() {
} you will get |
Thanks for the explanation! @szha @piiswrong is this the correct usage? |
include/mxnet/c_api.h
Outdated
* \param out_names the names of returning NDArrays, can be NULL | ||
* \return 0 when success, -1 when failure happens | ||
*/ | ||
MXNET_DLL int MXNDArrayLoadListFromMemory(const void *buf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it it becomes difficult to put all your resources in 1 file. For instance we are a text to speech company and we need to keep all the resources for a voice in one file. One could also resolve the problem by using a file pointer instead of a buffer, but I thought this would be a more general approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it would allow you to use encrypted or compressed formats too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have an API for loading and saving list/dict of NDArrays
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the c_api.h the only function that looked right for working from memory was MXNDArrayLoadFromRawBytes but that seems to only work with 1 array rather than loading a list/dict unless I misunderstood?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking over the predict API and there are functions there that can get this data
but it requires loading the list handle, then manually creating NDArrays from each element in the list. Would it not be better to do this in one function in the main api?
Merge branch 'master' of git://github.com/apache/incubator-mxnet
sorry I was away for a long weekend, any other comments or questions? |
include/mxnet/c_api.h
Outdated
* This ensures the engine has been initialised and | ||
* the operators have been registered. | ||
*/ | ||
MXNET_DLL void MXInitialise(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Initialize is spelled with a 'z' :)
src/c_api/c_api.cc
Outdated
ret->ret_handles.resize(data.size()); | ||
for (size_t i = 0; i < data.size(); ++i) { | ||
NDArray *ptr = new NDArray(); | ||
*ptr = data[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you immediately reassign 'ptr' and leak the newly created NDArray?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valgrind gives no errors, and if you look at MXNDArrayLoad it is the same as how files are loaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, it's dereferenced. Not sure how I missed that.
src/c_api/c_api.cc
Outdated
@@ -91,6 +91,12 @@ int MXRandomSeed(int seed) { | |||
API_END(); | |||
} | |||
|
|||
void MXInitialise() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this isn't called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put in the example code above, but the functions are not registered so if you try and load a symbol from a file before calling it you will get an error:
Check failed: op != nullptr Operator FullyConnected is not registered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So wouldn't this rather be a task to do when you load a file, rather than having this as a standalone function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at src/c_api/c_predict_api.cc lines 111
There is a bit where all the symbols are registered with MXListAllOpNames
I think it would be better to use a function whose name is clear, which can be inserted whenever it is needed such as in file loading and the prediction API.
The CAPI is meant to follow the hour glass model. Its like small kernel. If something can be done by composing existing API we shouldn't add a new API for it. It should be done in the frontend. This API feels like a convenience wrapper rather than core functionality. |
so I tried to implement the equivalent to the load from memory using the predict API and the main API, but in the end I failed. I need to be able to load the main API because it is an LSTM model which the Predict API does not support. I will remove the initialise function and fix the bugs with symbol loading instead but I don't think it is actually possible to fix load a dictionary / list from memory into NDArray handles. Would you prefer me moving the loading function into a different request so the bug can be fixed quicker? |
Was at a conference, don't know where that build error was from but it seemed to fix itself once I updated to the latest version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated and removed extra api feature
"Approved changes" by me only refer to my comments. |
… CNN network using the models defined by example/image-classification (apache#9805) * Enable the reporting of cross-entropy or nll loss value during training * Set the default value of loss as a '' to avoid a Python runtime issue when loss argument is not set
* Add SoftSign Activation function
* draft * move to contrib * rename op * CR comments * Update contrib.py * Update contrib.py * Update random.py * update example in the doc * update example in symbol doc * CR comments * update op name * update op name * update op name in test * update test * Update contrib.py
* Example implementation of the softmax output layer using RTC * Remove broken NDArrayOp example * Update README.md of the python custom operator examples
… etc. (apache#8972) * Profiling enhancements * Set new dmlc-core commit * Address CR comments * Update profiler.py * lint
* added test output files to gitignore * corrected indentation
this has fallen way behind the master I'm going to close this pull request and do the two parts separately |
Description
Simplified some processes using the C API
Checklist
Essentials
make lint
)Changes
Comments
Added two functions that wrap existing functionality to make it easier to use in C / C++ applications.
MXInitialise
Readies mxnet for use. While this is possible with some other commands this function makes more sense and does not require unneeded variables.
MXNDArrayLoadListFromMemory
Duplicates MXNDArrayLoad but from a location in memory. This was needed for my work as we bundle models into another file.