|
1 | 1 | # PyTorch
|
2 | 2 |
|
3 |
| -SageMaker Zero-Code-Change supported containers: PyTorch 1.3. See [AWS Docs](https://docs.aws.amazon.com/sagemaker/latest/dg/train-model.html) for more information.\ |
4 |
| -Python API supported versions: 1.2, 1.3. |
5 |
| - |
6 | 3 | ## Contents
|
| 4 | +- [Support](#support) |
| 5 | +- [How to Use](#how-to-use) |
7 | 6 | - [Module Loss Example](#module-loss-example)
|
8 | 7 | - [Functional Loss Example](#functional-loss-example)
|
9 | 8 | - [Full API](#full-api)
|
10 | 9 |
|
| 10 | +## Support |
| 11 | + |
| 12 | +### Versions |
| 13 | +- Zero Script Change experience where you need no modifications to your training script is supported in the official [SageMaker Framework Container for PyTorch 1.3](https://docs.aws.amazon.com/sagemaker/latest/dg/pre-built-containers-frameworks-deep-learning.html), or the [AWS Deep Learning Container for PyTorch 1.3](https://aws.amazon.com/machine-learning/containers/). |
| 14 | + |
| 15 | +- The library itself supports the following versions when using changes to the training script: PyTorch 1.2, 1.3. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## How to Use |
| 20 | +### Using Zero Script Change containers |
| 21 | +In this case, you don't need to do anything to get the hook running. You are encouraged to configure the hook from the SageMaker python SDK so you can run different jobs with different configurations without having to modify your script. If you want access to the hook to configure certain things which can not be configured through the SageMaker SDK, you can retrieve the hook as follows. |
| 22 | +``` |
| 23 | +import smdebug.pytorch as smd |
| 24 | +hook = smd.Hook.create_from_json_file() |
| 25 | +``` |
| 26 | +Note that you can create the hook from smdebug's python API as is being done in the next section even in such containers. |
| 27 | + |
| 28 | +### Bring your own container experience |
| 29 | +#### 1. Create a hook |
| 30 | +If using SageMaker, you will configure the hook in SageMaker's python SDK using the Estimator class. Instantiate it with |
| 31 | +`smd.Hook.create_from_json_file()`. Otherwise, call the hook class constructor, `smd.Hook()`. |
| 32 | + |
| 33 | +#### 2. Register the model to the hook |
| 34 | +Call `hook.register_module(net)`. |
| 35 | + |
| 36 | +#### 3. Register your loss function to the hook |
| 37 | +If using a loss which is a subclass of `nn.Module`, call `hook.register_loss(loss_criterion)` once before starting training.\ |
| 38 | +If using a loss which is a subclass of `nn.functional`, call `hook.record_tensor_value(loss)` after each training step. |
| 39 | + |
| 40 | +#### 4. (Optional) Configure Collections, SaveConfig and ReductionConfig |
| 41 | +See the [Common API](api.md) page for details on how to do this. |
| 42 | + |
| 43 | +--- |
| 44 | + |
11 | 45 | ## Module Loss Example
|
12 | 46 | ```python
|
13 | 47 | import smdebug.pytorch as smd
|
@@ -38,6 +72,8 @@ for (inputs, labels) in trainloader:
|
38 | 72 | optimizer.step()
|
39 | 73 | ```
|
40 | 74 |
|
| 75 | +--- |
| 76 | + |
41 | 77 | ## Functional Loss Example
|
42 | 78 | ```python
|
43 | 79 | import smdebug.pytorch as smd
|
@@ -70,6 +106,8 @@ for (inputs, labels) in trainloader:
|
70 | 106 | optimizer.step()
|
71 | 107 | ```
|
72 | 108 |
|
| 109 | +--- |
| 110 | + |
73 | 111 | ## Full API
|
74 | 112 | See the [Common API](api.md) page for details about Collection, SaveConfig, and ReductionConfig.\
|
75 | 113 | See the [Analysis](analysis.md) page for details about analyzing a training job.
|
|
0 commit comments