-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-1255] update hybridize documentation #13597
Conversation
@mxnet-label-bot add[Doc, pr-awaiting-review] |
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.
Pretty handy doc! Thanks for the summarization.
docs/tutorials/gluon/hybrid.md
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit : hybrid_forward
docs/tutorials/gluon/hybrid.md
Outdated
``` | ||
|
||
### 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
docs/tutorials/gluon/hybrid.md
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: to explicitly call
docs/tutorials/gluon/hybrid.md
Outdated
|
||
#### 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit : In-place
docs/tutorials/gluon/hybrid.md
Outdated
#### 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`. |
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: otherwise
b25454a
to
ffd8e57
Compare
ffd8e57
to
ee7df70
Compare
@aaronmarkham @zheng-da could you help review? Thanks! |
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.
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`
docs/tutorials/gluon/hybrid.md
Outdated
@@ -137,4 +137,94 @@ to gluon with `SymbolBlock`: | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Operators that does not work with hybridize | |
## Operators that do not work with hybridize |
docs/tutorials/gluon/hybrid.md
Outdated
@@ -137,4 +137,94 @@ to gluon with `SymbolBlock`: | |||
net2 = gluon.SymbolBlock.imports('model-symbol.json', ['data'], 'model-0001.params') | |||
``` | |||
|
|||
## 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
docs/tutorials/gluon/hybrid.md
Outdated
### 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
docs/tutorials/gluon/hybrid.md
Outdated
|
||
### 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
docs/tutorials/gluon/hybrid.md
Outdated
|
||
### 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
docs/tutorials/gluon/hybrid.md
Outdated
|
||
#### 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`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. |
docs/tutorials/gluon/hybrid.md
Outdated
|
||
#### 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid all in-place operators. I have added example: avoid x+=y
and use x = x + y
.
docs/tutorials/gluon/hybrid.md
Outdated
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
docs/tutorials/gluon/hybrid.md
Outdated
@@ -1,6 +1,9 @@ | |||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Content instead of Contents (but don't restart CI just for that change).
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 added a link to the new dive into deeplearning book so made it "contents"
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.
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
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.
Super minor nits.
docs/tutorials/gluon/hybrid.md
Outdated
|
||
### 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
docs/tutorials/gluon/hybrid.md
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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`. |
docs/tutorials/gluon/hybrid.md
Outdated
@@ -1,6 +1,9 @@ | |||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*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