[MXNET-1255] update hybridize documentation#13597
Conversation
|
@mxnet-label-bot add[Doc, pr-awaiting-review] |
ChaiBapchya
left a comment
There was a problem hiding this comment.
Pretty handy doc! Thanks for the summarization.
| return x[0] | ||
| ``` | ||
|
|
||
| The current workaround is explicitly call [`slice`](https://mxnet.incubator.apache.org/api/python/ndarray/ndarray.html#mxnet.ndarray.NDArray.slice) operators in `hybrid_forwar`d. |
| ``` | ||
|
|
||
| ### Slice | ||
| [] in NDArray is to get a slice from the array. [] in Symbol is to get an output from a grouped symbol. |
There was a problem hiding this comment.
nit : how about
[] in NDArray is used to get a slice from the array. However, [] in Symbol is used to get an output from a grouped symbol.
| return x[0] | ||
| ``` | ||
|
|
||
| The current workaround is explicitly call [`slice`](https://mxnet.incubator.apache.org/api/python/ndarray/ndarray.html#mxnet.ndarray.NDArray.slice) operators in `hybrid_forwar`d. |
There was a problem hiding this comment.
nit: to explicitly call
|
|
||
| #### In-Place Arithmetic Operators | ||
|
|
||
| In place arithmetic operators are also used a lot in Gluon imperative mode. You need to avoid that and write the operations explicitly in `hybrid_forward`. |
| #### In-Place Arithmetic Operators | ||
|
|
||
| In place arithmetic operators are also used a lot in Gluon imperative mode. You need to avoid that and write the operations explicitly in `hybrid_forward`. | ||
| For example, avoid `x += y` and use `x = x + y`, other wise you will get `NotImplementedError`. |
b25454a to
ffd8e57
Compare
ffd8e57 to
ee7df70
Compare
|
@aaronmarkham @zheng-da could you help review? Thanks! |
aaronmarkham
left a comment
There was a problem hiding this comment.
Made some suggested changes.
Line 3 mentions a newer version. That will deflect most traffic to this page, yet you're updating it with a lot of info. I'd Change that line to read:
## Related Content
* [Fast, portable neural networks with Gluon HybridBlocks](https://gluon.mxnet.io/chapter07_distributed-learning/hybridize.html)
Also, to clean up the formatting, why not try to use explicit math output with the math directive.
:math: `x.iadd(y)` <=> `x+=y`
| net2 = gluon.SymbolBlock.imports('model-symbol.json', ['data'], 'model-0001.params') | ||
| ``` | ||
|
|
||
| ## Operators that does not work with hybridize |
There was a problem hiding this comment.
| ## Operators that does not work with hybridize | |
| ## Operators that do not work with hybridize |
|
|
||
| ## Operators that does not work with hybridize | ||
|
|
||
| If you want to hybridize your model, you must use `F.some_operator` in your 'hybrid_forward' function, F will be 'mxnet.nd' before you hybridize and 'mxnet.sym' after hybridize. While most APIs are the same in NDArray and Symbol, there are some differences. Writing `F.some_operator` and call `hybridize` may not work all the time. |
There was a problem hiding this comment.
| If you want to hybridize your model, you must use `F.some_operator` in your 'hybrid_forward' function, F will be 'mxnet.nd' before you hybridize and 'mxnet.sym' after hybridize. While most APIs are the same in NDArray and Symbol, there are some differences. Writing `F.some_operator` and call `hybridize` may not work all the time. | |
| If you want to hybridize your model, you must use `F.some_operator` in your 'hybrid_forward' function. | |
| `F` will be 'mxnet.nd' before you hybridize and 'mxnet.sym' after hybridize. While most APIs are the same in NDArray and Symbol, there are some differences. Writing `F.some_operator` and call `hybridize` may not work all of the time. |
| ### Element-wise Operators | ||
|
|
||
| The following arithmetic and comparison APIs are automatically broadcasted if the input NDArrays have different shapes. | ||
| However, that's not the case in Symbol API, it's not automatically broadcasted and you have to manually specify whether to use element-wise operator or broadcast operators. |
There was a problem hiding this comment.
| However, that's not the case in Symbol API, it's not automatically broadcasted and you have to manually specify whether to use element-wise operator or broadcast operators. | |
| However, that's not the case in Symbol API. It's not automatically broadcasted, and you have to manually specify whether to use element-wise operator or broadcast operators. |
|
|
||
| ### Slice | ||
| `[]` in NDArray is used to get a slice from the array. However, `[]` in Symbol is used to get an output from a grouped symbol. | ||
| For example, you will get different result for the following method before and after hybridization. |
There was a problem hiding this comment.
| For example, you will get different result for the following method before and after hybridization. | |
| For example, you will get different results for the following method before and after hybridization. |
|
|
||
| ### Not implemented operators | ||
|
|
||
| Some of the often used operators in NDArray are not implemented in Symbol, and will cause hybridization failure |
There was a problem hiding this comment.
| Some of the often used operators in NDArray are not implemented in Symbol, and will cause hybridization failure | |
| Some of the often used operators in NDArray are not implemented in Symbol, and will cause hybridization failure. |
|
|
||
| #### Array API | ||
|
|
||
| `mx.nd.array()` is used a lot but Symbol does not have the array API. The current workaround is to use F.ones/ F.zeros/ F.full which exists in both NDArrays and Symbols. |
There was a problem hiding this comment.
| `mx.nd.array()` is used a lot but Symbol does not have the array API. The current workaround is to use F.ones/ F.zeros/ F.full which exists in both NDArrays and Symbols. | |
| `mx.nd.array()` is used a lot, but Symbol does not have the `array` API. The current workaround is to use `F.ones`, `F.zeros`, or `F.full`, which exist in both the NDArray and Symbol APIs. |
|
|
||
| #### In-Place Arithmetic Operators | ||
|
|
||
| In-place arithmetic operators are also used a lot in Gluon imperative mode. You need to avoid that and write the operations explicitly in `hybrid_forward`. |
There was a problem hiding this comment.
"avoid that"? What exactly? All in-place operators? Can you clarify this?
Maybe better to say something like...
| In-place arithmetic operators are also used a lot in Gluon imperative mode. You need to avoid that and write the operations explicitly in `hybrid_forward`. | |
| In-place arithmetic operators may be used in Gluon imperative mode, however if you expect to hybridize, you should write the operations explicitly instead. |
There was a problem hiding this comment.
avoid all in-place operators. I have added example: avoid x+=y and use x = x + y.
|
|
||
| | NDArray in-place arithmetic operators | Description | | ||
| |---|---| | ||
| |[*NDArray.\__iadd\__*](https://mxnet.incubator.apache.org/api/python/ndarray/ndarray.html#mxnet.ndarray.NDArray.__iadd__) | x.__iadd__(y) <=> x+=y | |
There was a problem hiding this comment.
Notice that the double underscore is bolding the text. I'd be worried what this will be interpreted as by Sphinx/rst down the line.
You can escape it, or like I mentioned before use :math:.
|
@aaronmarkham @ChaiBapchya Thanks for the review, I have addressed your comments.
|
|
@ThomasDelteil @nswamy Could you help take a look? Thanks! |
| # Hybrid - Faster training and easy deployment | ||
|
|
||
| *Note: a newer version is available [here](http://gluon.mxnet.io/chapter07_distributed-learning/hybridize.html).* | ||
| *Related Contents:* |
There was a problem hiding this comment.
nit: Content instead of Contents (but don't restart CI just for that change).
There was a problem hiding this comment.
I added a link to the new dive into deeplearning book so made it "contents"
There was a problem hiding this comment.
It's a semantic thing I guess. There's probably a rule here but... usually you can say Content is plural already (as it refers to a mass of stuff) and you don't usually say "Related Contents". It's more common to say "Related Content" even if there's more than one item in the list.
It is weird because you do say "Table of Contents", not "Table of Content".
🤷♂️ English is weird. It's not a showstopper... it's fine whichever way you want to do it. (but do it my way). Jk
|
|
||
| ### Not implemented operators | ||
|
|
||
| Some of the often used operators in NDArray are not implemented in Symbol, and will cause hybridization failure |
There was a problem hiding this comment.
| Some of the often used operators in NDArray are not implemented in Symbol, and will cause hybridization failure | |
| Some of the often used operators in NDArray are not implemented in Symbol, and will cause hybridization failure. |
| Some of the often used operators in NDArray are not implemented in Symbol, and will cause hybridization failure | ||
|
|
||
| #### NDArray.asnumpy | ||
| Symbol does not support `asnumpy` function, you need to avoid calling `asnumpy` in `hybrid_forward`. |
There was a problem hiding this comment.
| Symbol does not support `asnumpy` function, you need to avoid calling `asnumpy` in `hybrid_forward`. | |
| Symbol does not support the `asnumpy` function. You need to avoid calling `asnumpy` in `hybrid_forward`. |
| # Hybrid - Faster training and easy deployment | ||
|
|
||
| *Note: a newer version is available [here](http://gluon.mxnet.io/chapter07_distributed-learning/hybridize.html).* | ||
| *Related Contents:* |
There was a problem hiding this comment.
| *Related Contents:* | |
| *Related Content:* |
|
Seems like all the comments are addressed. |
* update hybridize documentation * address review comments * improve doc * address comments * address comments
* update hybridize documentation * address review comments * improve doc * address comments * address comments
Description
This is the first step to address issues in:
#10875
#12100
#12109
First provide documentation and current work around.
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Add documentations for operators does not work with hybridization
Comments