<jupyter_start><jupyter_text>MXNet Computations OverviewWhat is MXNet?- Library for building neural networks.- Enables algorithms to run on GPUs for faster processing.- Enables parallelization across instances.- Uses symbolic programs to enable Python code to run as fast as C. Symbolic ProgramsHow does using symbolic programming speed up the program?- The Python defines the computation.- Computation is defined as a DAG (Directed Acyclic Graph).- Computation happens at native layer after DAG completely defined. SymbolWhat is a `Symbol`?- A `Symbol` is a multi-output symbolic expression. - It can be a single variable. - Or it could be an expression composed of variables. Symbolic ComputationLet's define a symbolic computation.<jupyter_code>import mxnet as mx

a = mx.sym.Variable('a')
b = mx.sym.Variable('b')
c = a + b<jupyter_output><empty_output><jupyter_text>Let's visualize the computation graph.<jupyter_code>mx.viz.plot_network(c)<jupyter_output><empty_output><jupyter_text>Let's make things more complicated.<jupyter_code>d = c * a + 10
mx.viz.plot_network(d)<jupyter_output><empty_output><jupyter_text>ModuleWhat is a module?- A `Module` is a machine that can execute a program defined by `Symbol`. Module APIsHere are some things you can do with modules. ```python Call high-level APIs to train and predict.mod.fit(nd_iter, num_epoch=10, ...) mod.predict(new_nd_iter)  Use intermediate-level APIs to train. mod.forward(data_batch)mod.backward()mod.update()```  Neural NetworksHere is how you can define neural networks using MXNet.<jupyter_code>net = mx.sym.Variable ('data')
net = mx.sym.FullyConnected (data=net, name='fc1', num_hidden=128)
net = mx.sym.Activation (data=net, name='relu1', act_type="relu")
net = mx.sym.FullyConnected (data=net, name='fc2', num_hidden=10)
net = mx.sym.SoftmaxOutput (data=net, name='out')
mx.viz.plot_network (net, shape={'data' : (100,200) } )<jupyter_output><empty_output><jupyter_text>ContextWhat does a context indicate in MXNet?- Context determines if your vector is processed on CPU or GPU.  GPU vs CPULet's create some vectors in MXNet and then see if we can move them to the GPU.<jupyter_code>import mxnet as mx
from mxnet import nd

# Initialize random seed.
mx.random.seed(1)

# Generate some vectors.
x = nd.random_normal(0, 1, shape=(3,4))
y = nd.ones((3,4))

# Print x.
print(x)
# Print y.
print(y)
# Find if x is on GPU or CPU.
print(x.context)
# Copy x to GPU context.
try:
    x_gpu = x.copyto(mx.gpu(0))
except:
    print("GPU is not supported on this machine.")<jupyter_output>GPU is not supported on this machine.
{'fraction_non_alphanumeric': 0.10518174787316319, 'fraction_numerical': 0.010054137664346482, 'mean_word_length': 5.248792270531401, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '362249', 'license': 'MIT', 'n_tokens_mistral': 846, 'n_tokens_neox': 828, 'n_words': 295, 'path': 'machine-learning/mxnet-computations.ipynb', 'repo_name': 'asimjalis/aws-demos', 'size': '2586'}