From 3b8b29870fc86fc4e8dab04b727165d957f146b2 Mon Sep 17 00:00:00 2001 From: Jyoti Balodhi Date: Fri, 5 Mar 2021 21:13:22 +0530 Subject: [PATCH 1/3] Hybridization Disabling steps added --- .../packages/gluon/blocks/hybridize.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md b/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md index af892a5a1b44..6ee9c52c11b3 100644 --- a/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md +++ b/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md @@ -18,7 +18,9 @@ # Hybridize + ## A Hybrid of Imperative and Symbolic Programming + Imperative programming makes use of programming statements to change a program’s state. Consider the following example of simple imperative programming code. @@ -79,10 +81,9 @@ The three functions defined above will only return the results of the computatio A comparison of these two programming methods shows that -* imperative programming is easier. When imperative programming is used in Python, the majority of the code is straightforward and easy to write. At the same time, it is easier to debug imperative programming code. This is because it is easier to obtain and print all relevant intermediate variable values, or make use of Python’s built-in debugging tools. - -* Symbolic programming is more efficient and easier to port. Symbolic programming makes it easier to better optimize the system during compilation, while also having the ability to port the program into a format independent of Python. This allows the program to be run in a non-Python environment, thus avoiding any potential performance issues related to the Python interpreter. +- imperative programming is easier. When imperative programming is used in Python, the majority of the code is straightforward and easy to write. At the same time, it is easier to debug imperative programming code. This is because it is easier to obtain and print all relevant intermediate variable values, or make use of Python’s built-in debugging tools. +- Symbolic programming is more efficient and easier to port. Symbolic programming makes it easier to better optimize the system during compilation, while also having the ability to port the program into a format independent of Python. This allows the program to be run in a non-Python environment, thus avoiding any potential performance issues related to the Python interpreter. ## Hybrid programming provides the best of both worlds. @@ -123,7 +124,6 @@ net(x) It should be noted that only the layers inheriting the HybridBlock class will be optimized during computation. For example, the HybridSequential and `Dense` classes provided by Gluon are all subclasses of HybridBlock class, meaning they will both be optimized during computation. A layer will not be optimized if it inherits from the Block class rather than the HybridBlock class. - ### Computing Performance To demonstrate the performance improvement gained by the use of symbolic programming, we will compare the computation time before and after calling the `hybridize` function. Here we time 1000 `net` model computations. The model computations are based on imperative and symbolic programming, respectively, before and after `net` has called the `hybridize` function. @@ -144,7 +144,6 @@ print('after hybridizing: %.4f sec' % (benchmark(net, x))) As is observed in the above results, after a HybridSequential instance calls the `hybridize` function, computing performance is improved through the use of symbolic programming. - ### Achieving Symbolic Programming We can save the symbolic program and model parameters to the hard disk through the use of the `export` function after the `net` model has finished computing the output based on the input, such as in the case of `net(x)` in the `benchmark` function. @@ -304,3 +303,11 @@ value = mx.nd.ones_like(x)*2 condition = mx.nd.array([0,1,1]) mx.nd.where(condition=condition, x=x, y=value) ``` + +## Disabling hybridization + +If we want to disable the `hybridize` function we can do that by using the following code: + +```{.python .input} +net.hybridize(active=False) +``` From 9f769b328632644b3dfc356dda5f555515c2b8ac Mon Sep 17 00:00:00 2001 From: Jyoti Balodhi Date: Fri, 5 Mar 2021 21:24:38 +0530 Subject: [PATCH 2/3] Revert "Hybridization Disabling steps added" This reverts commit 3b8b29870fc86fc4e8dab04b727165d957f146b2. --- .../packages/gluon/blocks/hybridize.md | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md b/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md index 6ee9c52c11b3..af892a5a1b44 100644 --- a/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md +++ b/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md @@ -18,9 +18,7 @@ # Hybridize - ## A Hybrid of Imperative and Symbolic Programming - Imperative programming makes use of programming statements to change a program’s state. Consider the following example of simple imperative programming code. @@ -81,9 +79,10 @@ The three functions defined above will only return the results of the computatio A comparison of these two programming methods shows that -- imperative programming is easier. When imperative programming is used in Python, the majority of the code is straightforward and easy to write. At the same time, it is easier to debug imperative programming code. This is because it is easier to obtain and print all relevant intermediate variable values, or make use of Python’s built-in debugging tools. +* imperative programming is easier. When imperative programming is used in Python, the majority of the code is straightforward and easy to write. At the same time, it is easier to debug imperative programming code. This is because it is easier to obtain and print all relevant intermediate variable values, or make use of Python’s built-in debugging tools. + +* Symbolic programming is more efficient and easier to port. Symbolic programming makes it easier to better optimize the system during compilation, while also having the ability to port the program into a format independent of Python. This allows the program to be run in a non-Python environment, thus avoiding any potential performance issues related to the Python interpreter. -- Symbolic programming is more efficient and easier to port. Symbolic programming makes it easier to better optimize the system during compilation, while also having the ability to port the program into a format independent of Python. This allows the program to be run in a non-Python environment, thus avoiding any potential performance issues related to the Python interpreter. ## Hybrid programming provides the best of both worlds. @@ -124,6 +123,7 @@ net(x) It should be noted that only the layers inheriting the HybridBlock class will be optimized during computation. For example, the HybridSequential and `Dense` classes provided by Gluon are all subclasses of HybridBlock class, meaning they will both be optimized during computation. A layer will not be optimized if it inherits from the Block class rather than the HybridBlock class. + ### Computing Performance To demonstrate the performance improvement gained by the use of symbolic programming, we will compare the computation time before and after calling the `hybridize` function. Here we time 1000 `net` model computations. The model computations are based on imperative and symbolic programming, respectively, before and after `net` has called the `hybridize` function. @@ -144,6 +144,7 @@ print('after hybridizing: %.4f sec' % (benchmark(net, x))) As is observed in the above results, after a HybridSequential instance calls the `hybridize` function, computing performance is improved through the use of symbolic programming. + ### Achieving Symbolic Programming We can save the symbolic program and model parameters to the hard disk through the use of the `export` function after the `net` model has finished computing the output based on the input, such as in the case of `net(x)` in the `benchmark` function. @@ -303,11 +304,3 @@ value = mx.nd.ones_like(x)*2 condition = mx.nd.array([0,1,1]) mx.nd.where(condition=condition, x=x, y=value) ``` - -## Disabling hybridization - -If we want to disable the `hybridize` function we can do that by using the following code: - -```{.python .input} -net.hybridize(active=False) -``` From 0247a2c4c6e49af778125efaba4771ff5d1aee3f Mon Sep 17 00:00:00 2001 From: Jyoti Balodhi Date: Fri, 5 Mar 2021 21:39:07 +0530 Subject: [PATCH 3/3] Disabling Hybridization steps added --- .../packages/gluon/blocks/hybridize.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md b/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md index af892a5a1b44..5bf206a97fb4 100644 --- a/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md +++ b/docs/python_docs/python/tutorials/packages/gluon/blocks/hybridize.md @@ -18,7 +18,9 @@ # Hybridize + ## A Hybrid of Imperative and Symbolic Programming + Imperative programming makes use of programming statements to change a program’s state. Consider the following example of simple imperative programming code. @@ -79,10 +81,9 @@ The three functions defined above will only return the results of the computatio A comparison of these two programming methods shows that -* imperative programming is easier. When imperative programming is used in Python, the majority of the code is straightforward and easy to write. At the same time, it is easier to debug imperative programming code. This is because it is easier to obtain and print all relevant intermediate variable values, or make use of Python’s built-in debugging tools. - -* Symbolic programming is more efficient and easier to port. Symbolic programming makes it easier to better optimize the system during compilation, while also having the ability to port the program into a format independent of Python. This allows the program to be run in a non-Python environment, thus avoiding any potential performance issues related to the Python interpreter. +- imperative programming is easier. When imperative programming is used in Python, the majority of the code is straightforward and easy to write. At the same time, it is easier to debug imperative programming code. This is because it is easier to obtain and print all relevant intermediate variable values, or make use of Python’s built-in debugging tools. +- Symbolic programming is more efficient and easier to port. Symbolic programming makes it easier to better optimize the system during compilation, while also having the ability to port the program into a format independent of Python. This allows the program to be run in a non-Python environment, thus avoiding any potential performance issues related to the Python interpreter. ## Hybrid programming provides the best of both worlds. @@ -123,7 +124,6 @@ net(x) It should be noted that only the layers inheriting the HybridBlock class will be optimized during computation. For example, the HybridSequential and `Dense` classes provided by Gluon are all subclasses of HybridBlock class, meaning they will both be optimized during computation. A layer will not be optimized if it inherits from the Block class rather than the HybridBlock class. - ### Computing Performance To demonstrate the performance improvement gained by the use of symbolic programming, we will compare the computation time before and after calling the `hybridize` function. Here we time 1000 `net` model computations. The model computations are based on imperative and symbolic programming, respectively, before and after `net` has called the `hybridize` function. @@ -144,7 +144,6 @@ print('after hybridizing: %.4f sec' % (benchmark(net, x))) As is observed in the above results, after a HybridSequential instance calls the `hybridize` function, computing performance is improved through the use of symbolic programming. - ### Achieving Symbolic Programming We can save the symbolic program and model parameters to the hard disk through the use of the `export` function after the `net` model has finished computing the output based on the input, such as in the case of `net(x)` in the `benchmark` function. @@ -304,3 +303,11 @@ value = mx.nd.ones_like(x)*2 condition = mx.nd.array([0,1,1]) mx.nd.where(condition=condition, x=x, y=value) ``` + +## Disabling Hybridization + +If we want to disable the `hybridize` function, we can do that by using the following code: + +```{.python .input} +net.hybridize(active=False) +```