File tree Expand file tree Collapse file tree 2 files changed +207
-168
lines changed
tutorials/sphinx-tutorials Expand file tree Collapse file tree 2 files changed +207
-168
lines changed Original file line number Diff line number Diff line change 51
51
from pathlib import Path
52
52
53
53
import numpy as np
54
- import tensordict .utils
55
54
56
55
import torch
57
56
360
359
print (compiled_module (pixels = pixels ))
361
360
362
361
#####################################
362
+ # An extra feature of AOTInductor is its capacity of dealing with dynamic shapes. This can be useful if you don't know
363
+ # the shape of your input data ahead of time. For instance, we may want to run our policy for one, two or more
364
+ # observations at a time. For this, let us re-export our policy, marking a new unsqueezed batch dimension as dynamic:
365
+
366
+ batch_dim = torch .export .Dim ("batch" , min = 1 , max = 32 )
367
+ pixels_unsqueeze = pixels .unsqueeze (0 )
368
+ exported_dynamic_policy = torch .export .export (
369
+ policy_transform ,
370
+ args = (),
371
+ kwargs = {"pixels" : pixels_unsqueeze },
372
+ strict = False ,
373
+ dynamic_shapes = {"pixels" : {0 : batch_dim }},
374
+ )
375
+ # Then recompile and export
376
+ pkg_path = aoti_compile_and_package (
377
+ exported_dynamic_policy ,
378
+ args = (),
379
+ kwargs = {"pixels" : pixels_unsqueeze },
380
+ package_path = path ,
381
+ )
382
+
383
+ #####################################
384
+ # More information about this can be found in the
385
+ # `AOTInductor tutorial <https://pytorch.org/tutorials/recipes/torch_export_aoti_python.html>`_.
386
+ #
363
387
# Exporting TorchRL models with ONNX
364
388
# ----------------------------------
365
389
#
You can’t perform that action at this time.
0 commit comments