Skip to content

Commit ccbecb4

Browse files
authored
Update saving_loading_models.py
1 parent 30e8c31 commit ccbecb4

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

beginner_source/saving_loading_models.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,30 @@
227227
# normalization layers to evaluation mode before running inference.
228228
# Failing to do this will yield inconsistent inference results.
229229
#
230-
230+
# Saving an ExportedProgram
231+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
232+
#
233+
# If you are using torch.export, you can save and load your ExportedProgram using the
234+
# `torch.export.save()` and `torch.export.load()` APIs. with the `.pt2` file extension.
235+
#
236+
# .. code-block:: python
237+
#
238+
# class SimpleModel(torch.nn.Module):
239+
# def forward(self, x):
240+
# return x + 10
241+
#
242+
# # Create a sample input
243+
# sample_input = torch.randn(5)
244+
#
245+
# # Export the model
246+
# exported_program = torch.export.export(SimpleModel(), sample_input)
247+
#
248+
# # Save the exported program
249+
# torch.export.save(exported_program, 'exported_program.pt2')
250+
#
251+
# # Load the exported program
252+
# saved_exported_program = torch.export.load('exported_program.pt2')
253+
#
231254

232255
######################################################################
233256
# Saving & Loading a General Checkpoint for Inference and/or Resuming Training

0 commit comments

Comments
 (0)