Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions tutorials/CSharp/synthetic_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"\n",
"Synthetic data sets can be very useful when evaluating and choosing a model.\n",
"\n",
"Note that we're taking some shortcuts in this example -- rather than writing the data set as a text file that can be loaded from any modeling framework, we're saving the data as serialized TorchSharp tensors. Is should be straight-forward to modify the tutorial to write the data sets as text, instead."
"Note that we're taking some shortcuts in this example -- rather than writing the data set as a text file that can be loaded from any modeling framework, we're saving the data as serialized TorchSharp tensors. It should be straight-forward to modify the tutorial to write the data sets as text, instead."
]
},
{
Expand Down Expand Up @@ -339,7 +339,7 @@
" // Clear the gradients before doing the back-propagation\n",
" model.zero_grad();\n",
"\n",
" // Do back-progatation, which computes all the gradients.\n",
" // Do back-propagation, which computes all the gradients.\n",
" output.backward();\n",
"\n",
" optimizer.step();\n",
Expand Down Expand Up @@ -445,7 +445,7 @@
" // Clear the gradients before doing the back-propagation\n",
" model.zero_grad();\n",
"\n",
" // Do back-progatation, which computes all the gradients.\n",
" // Do back-propagation, which computes all the gradients.\n",
" output.backward();\n",
"\n",
" optimizer.step();\n",
Expand Down Expand Up @@ -483,7 +483,7 @@
"source": [
"#### Dataset and DataLoader\n",
"\n",
"If we wanted to be really advanced, we would use TorchSharp data sets and data loaders, which would allow us to randomize the test data set between epocs (at the end of the outer training loop). Here's how we'd do that."
"If we wanted to be really advanced, we would use TorchSharp data sets and data loaders, which would allow us to randomize the test data set between epochs (at the end of the outer training loop). Here's how we'd do that."
]
},
{
Expand Down Expand Up @@ -583,7 +583,7 @@
" // Clear the gradients before doing the back-propagation\n",
" model.zero_grad();\n",
"\n",
" // Do back-progatation, which computes all the gradients.\n",
" // Do back-propagation, which computes all the gradients.\n",
" output.backward();\n",
"\n",
" optimizer.step();\n",
Expand Down
4 changes: 2 additions & 2 deletions tutorials/CSharp/tutorial1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"However, for these tutorials, it would obscure the API to have too many usings. It's better, for pedagocial reasons, to explicitly qualify names until their scope becomes well known. So, the tutorials will generally use a minimal set of usings."
"However, for these tutorials, it would obscure the API to have too many usings. It's better, for pedagogical reasons, to explicitly qualify names until their scope becomes well known. So, the tutorials will generally use a minimal set of usings."
]
},
{
Expand Down Expand Up @@ -128,7 +128,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that there are now three styles that may be used to format tensor output: C#-style, NumPy-style and Julia-style. The default is 'Julia,' but if you continue to use he top-of-notebook formatting, whatever you set it to in the cell at the top will be used to format tensors automatically."
"Note that there are now three styles that may be used to format tensor output: C#-style, NumPy-style and Julia-style. The default is 'Julia,' but if you continue to use the top-of-notebook formatting, whatever you set it to in the cell at the top will be used to format tensors automatically."
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions tutorials/CSharp/tutorial2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
"\n",
"### Extracting an Array from a Tensor\n",
"\n",
"To get access to the internal data of a tensor as .NET array, use the 'data<T>()' property. It doesn't return an array, but a TensorAccessor<T>, which implements IEnumerable<T> and can therefore be turned into an array. The TensorAccessor<T> instance keeps a reference to the tensor data, but calling `ToArray<T>()` on it will create a copy."
"To get access to the internal data of a tensor as a .NET array, use the 'data<T>()' property. It doesn't return an array, but a TensorAccessor<T>, which implements IEnumerable<T> and can therefore be turned into an array. The TensorAccessor<T> instance keeps a reference to the tensor data, but calling `ToArray<T>()` on it will create a copy."
]
},
{
Expand Down Expand Up @@ -531,7 +531,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see, `arange` behaves a little differently from other factories -- the default element type is not float32, it's inferred from the arguments. To use floating-point, we an either specify the type, or use floating-point values as arguments:"
"As you can see, `arange` behaves a little differently from other factories -- the default element type is not float32, it's inferred from the arguments. To use floating-point, we can either specify the type, or use floating-point values as arguments:"
]
},
{
Expand Down Expand Up @@ -605,7 +605,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"When printing out floating-point tensors, it is often helpful to provide a formatting string, applied only to FP elements, including the real and imaginary parts of complex numbers. `.ToString(true, fltFormat: \"0.00\")` would be a lot to type every time, so TorcSharp defines a shorter (and Python-looking) method `str()` that does the trick. `print()` also takes a format string."
"When printing out floating-point tensors, it is often helpful to provide a formatting string, applied only to FP elements, including the real and imaginary parts of complex numbers. `.ToString(true, fltFormat: \"0.00\")` would be a lot to type every time, so TorchSharp defines a shorter (and Python-looking) method `str()` that does the trick. `print()` also takes a format string."
]
},
{
Expand Down Expand Up @@ -805,7 +805,7 @@
"source": [
"// On Apple HW (not x64), move to MPS and back:\n",
"\n",
"// t.mps().cpu() // Uncomment if you're running on moder Apple HW."
"// t.mps().cpu() // Uncomment if you're running on modern Apple HW."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion tutorials/CSharp/tutorial3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
"source": [
"# Numerics Library\n",
"\n",
"The collection of numerical operators that are available is too large to go through here, but suffice it to say that all the usual suspects are available. Most of the operate on an element-wise basis, i.e. the operator is applied to each element of the operands, possibly with broadcasting getting involved.\n",
"The collection of numerical operators that are available is too large to go through here, but suffice it to say that all the usual suspects are available. Most of them operate on an element-wise basis, i.e. the operator is applied to each element of the operands, possibly with broadcasting getting involved.\n",
"\n",
"One notable and __very__ significant exception is matrix multiplication, which is vector dot product generalized to matrices. The '*' operator denotes element-wise multiplication, while matrix multiplication is performed by the 'mm' method:"
]
Expand Down
2 changes: 1 addition & 1 deletion tutorials/CSharp/tutorial4.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To help with sampling, there's a class called `Binomial` whcih will run a number of coin tosses and count the number of times the result is '1'."
"To help with sampling, there's a class called `Binomial` which will run a number of coin tosses and count the number of times the result is '1'."
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions tutorials/CSharp/tutorial5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Copying a tensor from device to device is very straight-forward. Note that applying 'to()' to a tensor does not move it. Because of this inefficiency, it is better to create a tensor where it belongs, than to first create it on the CPU and move it over later. That said, it is often necessary to copy input data, because it comes from files and in-memory data that can only be turned into tensors on a CPU.\n",
"Copying a tensor from device to device is very straight-forward. Note that applying `to()` to a tensor does not move it. Because of this inefficiency, it is better to create a tensor where it belongs, than to first create it on the CPU and move it over later. That said, it is often necessary to copy input data, because it comes from files and in-memory data that can only be turned into tensors on a CPU.\n",
"\n",
"There are two primary ways to copy a tensor to the GPU -- using 'cuda()' or using 'to()' The former is simpler, while the latter is more flexible -- it allows you to simultaneously convert the element type of a tensor and copy it over."
"There are two primary ways to copy a tensor to the GPU -- using `cuda()` or using `to()` The former is simpler, while the latter is more flexible -- it allows you to simultaneously convert the element type of a tensor and copy it over."
]
},
{
Expand Down Expand Up @@ -343,7 +343,7 @@
"source": [
"# Placing Model Parameters on the GPU\n",
"\n",
"To use a GPU, tensors have to be copied or moved there. When you train, your data preparation logic is responsible for getting data to the GPU, but we also need the weights there. TorchSharp supports this by defining a 'to()' method on Modules, which can be used to move (not copy) the weights the model relies on to the GPU (or back to the CPU). We haven't looked at models yet, but keep this in mind for later:\n",
"To use a GPU, tensors have to be copied or moved there. When you train, your data preparation logic is responsible for getting data to the GPU, but we also need the weights there. TorchSharp supports this by defining a `to()` method on Modules, which can be used to move (not copy) the weights the model relies on to the GPU (or back to the CPU). We haven't looked at models yet, but keep this in mind for later:\n",
"\n",
"```C#\n",
"var model = ...;\n",
Expand Down
20 changes: 10 additions & 10 deletions tutorials/CSharp/tutorial6.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"source": [
"## Model Classes\n",
"\n",
"Typically, we want to keep the logic of a model in a class of its own. This makes it easy to use other TorchSharp constructs to combine and run models. Conceptually, that's all a model is -- a Tensor -> Tensor function implemented as a class with a 'forward()' function. This function is where the logic of the model is placed. (If C# supported operator(), like C++ does, that's what we'd use here, instead. Just like Python does.)\n",
"Typically, we want to keep the logic of a model in a class of its own. This makes it easy to use other TorchSharp constructs to combine and run models. Conceptually, that's all a model is -- a Tensor -> Tensor function implemented as a class with a `forward()` function. This function is where the logic of the model is placed. (If C# supported `operator()`, like C++ does, that's what we'd use here, instead. Just like Python does.)\n",
"\n",
"TorchSharp makes it easy to build models, because you only have to specify the forward function. To do backprogation, you also need the backward function, which supports using the chain rule of calculus to calculate gradients. In Torch, the backward function is automatically implemented as long as the forward function relies only on Torch APIs for computations.\n",
"\n",
Expand Down Expand Up @@ -374,7 +374,7 @@
"// Clear the gradients before doing the back-propagation\n",
"model.zero_grad();\n",
"\n",
"// Do back-progatation, which computes all the gradients.\n",
"// Do back-propagation, which computes all the gradients.\n",
"output.backward();\n",
"\n",
"// Adjust the weights using the gradients.\n",
Expand Down Expand Up @@ -434,7 +434,7 @@
"// Clear the gradients before doing the back-propagation\n",
"model.zero_grad();\n",
"\n",
"// Do back-progatation, which computes all the gradients.\n",
"// Do back-propagation, which computes all the gradients.\n",
"output.backward();\n",
"\n",
"optimizer.step();\n",
Expand Down Expand Up @@ -477,7 +477,7 @@
"// Clear the gradients before doing the back-propagation\n",
"model.zero_grad();\n",
"\n",
"// Do back-progatation, which computes all the gradients.\n",
"// Do back-propagation, which computes all the gradients.\n",
"output.backward();\n",
"\n",
"optimizer.step();\n",
Expand Down Expand Up @@ -514,7 +514,7 @@
"// Clear the gradients before doing the back-propagation\n",
"model.zero_grad();\n",
"\n",
"// Do back-progatation, which computes all the gradients.\n",
"// Do back-propagation, which computes all the gradients.\n",
"output.backward();\n",
"\n",
"optimizer.step();\n",
Expand Down Expand Up @@ -555,7 +555,7 @@
" // Clear the gradients before doing the back-propagation\n",
" model.zero_grad();\n",
"\n",
" // Do back-progatation, which computes all the gradients.\n",
" // Do back-propagation, which computes all the gradients.\n",
" output.backward();\n",
"\n",
" optimizer.step();\n",
Expand Down Expand Up @@ -870,7 +870,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using Tensorbard\n",
"### Using Tensorboard\n",
"\n",
"Tensorboard is a tool that was originally built for Tensorflow, but it is general enough that it may be used with a number of data sources, including PyTorch and TorchSharp. The TorchSharp support for TB is limited, but it is useful for logging scalars during training, for example by logging accuracy or loss at the end of each epoch.\n",
"\n",
Expand Down Expand Up @@ -904,7 +904,7 @@
" // Clear the gradients before doing the back-propagation\n",
" model.zero_grad();\n",
"\n",
" // Do back-progatation, which computes all the gradients.\n",
" // Do back-propagation, which computes all the gradients.\n",
" output.backward();\n",
"\n",
" optimizer.step();\n",
Expand All @@ -923,7 +923,7 @@
"source": [
"## Sequential\n",
"\n",
"The prior sections have described the most general way of constructing a model, that is, by creating a class that abstracts the logic of the model and explicitly calls each layer's `forward` methos. While it's not too complicated to do so, it's a lot of \"ceremony\" to accomplish something very regular.\n",
"The prior sections have described the most general way of constructing a model, that is, by creating a class that abstracts the logic of the model and explicitly calls each layer's `forward` method. While it's not too complicated to do so, it's a lot of \"ceremony\" to accomplish something very regular.\n",
"\n",
"Fortunately, for models, or components of models, that simply pass one tensor from layer to layer, there's a class to handle it. It's called `Sequential` and is created by passing a sequence of tuples. The first element of the tuple is the name of the layer (required), and the second is the component.\n",
"\n",
Expand Down Expand Up @@ -954,7 +954,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"How can that be? Well, it's because save/load doesn't actually save and restore the model, it saves and restores the weights. All it cares about is that the layer's with weights have the same definition, and that they have the same name. In the Trivial case, the names were derived from the field names, and in the Sequential case, they are explicitly given. ReLU doesn't have any weights, so the fact that we did it differently doesn't factor it. The name of the relu layer can be anything, it just has to be something that isn't `null`.\n",
"How can that be? Well, it's because save/load doesn't actually save and restore the model, it saves and restores the weights. All it cares about is that the layers with weights have the same definition, and that they have the same name. In the Trivial case, the names were derived from the field names, and in the Sequential case, they are explicitly given. ReLU doesn't have any weights, so the fact that we did it differently doesn't factor it. The name of the relu layer can be anything, it just has to be something that isn't `null`.\n",
"\n",
"About `ReLU` -- in the Sequential case, we implemented that with a layer? That's because Sequential requires that its arguments be subclasses of `Module`, so a function doesn't work."
]
Expand Down
4 changes: 2 additions & 2 deletions tutorials/CSharp/tutorial7.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
" // Clear the gradients before doing the back-propagation\n",
" model.zero_grad();\n",
"\n",
" // Do back-progatation, which computes all the gradients.\n",
" // Do back-propagation, which computes all the gradients.\n",
" output.backward();\n",
"\n",
" optimizer.step();\n",
Expand Down Expand Up @@ -185,7 +185,7 @@
" // Clear the gradients before doing the back-propagation\n",
" model.zero_grad();\n",
"\n",
" // Do back-progatation, which computes all the gradients.\n",
" // Do back-propagation, which computes all the gradients.\n",
" output.backward();\n",
"\n",
" optimizer.step();\n",
Expand Down
10 changes: 5 additions & 5 deletions tutorials/FSharp/synthetic_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"\n",
"Synthetic data sets can be very useful when evaluating and choosing a model.\n",
"\n",
"Note that we're taking some shortcuts in this example -- rather than writing the data set as a text file that can be loaded from any modeling framework, we're saving the data as serialized TorchSharp tensors. Is should be straight-forward to modify the tutorial to write the data sets as text, instead."
"Note that we're taking some shortcuts in this example -- rather than writing the data set as a text file that can be loaded from any modeling framework, we're saving the data as serialized TorchSharp tensors. It should be straight-forward to modify the tutorial to write the data sets as text, instead."
]
},
{
Expand Down Expand Up @@ -315,7 +315,7 @@
" // Clear the gradients before doing the back-propagation\n",
" model.zero_grad()\n",
"\n",
" // Do back-progatation, which computes all the gradients.\n",
" // Do back-propagation, which computes all the gradients.\n",
" output.backward()\n",
"\n",
" optimizer.step() |> ignore\n",
Expand Down Expand Up @@ -419,7 +419,7 @@
" // Clear the gradients before doing the back-propagation\n",
" model.zero_grad()\n",
"\n",
" // Do back-progatation, which computes all the gradients.\n",
" // Do back-propagation, which computes all the gradients.\n",
" output.backward()\n",
"\n",
" optimizer.step() |> ignore\n",
Expand Down Expand Up @@ -455,7 +455,7 @@
"source": [
"#### Dataset and DataLoader\n",
"\n",
"If we wanted to be really advanced, we would use TorchSharp data sets and data loaders, which would allow us to randomize the test data set between epocs (at the end of the outer training loop). Here's how we'd do that."
"If we wanted to be really advanced, we would use TorchSharp data sets and data loaders, which would allow us to randomize the test data set between epochs (at the end of the outer training loop). Here's how we'd do that."
]
},
{
Expand Down Expand Up @@ -545,7 +545,7 @@
" // Clear the gradients before doing the back-propagation\n",
" model.zero_grad()\n",
"\n",
" // Do back-progatation, which computes all the gradients.\n",
" // Do back-propagation, which computes all the gradients.\n",
" output.backward()\n",
"\n",
" optimizer.step() |> ignore\n",
Expand Down
Loading