onnxruntime/orttraining/orttraining/python/training
pengwa a6887f171f
Refactor schema extraction and output unflattening (#16894)
### Motivation and Context

When we handle PyTorch models' inputs in different places (ORTModule or
others), it's common for us to flatten a structured data into a 1-D
tensor list (required by lib for example torch.onnx.export,
torch.autograd.Function.forward or ORT inference session), then do
subsequent work, then unflatten back to original hierarchy as returned
values.

DeepStage3 hooks support work also need such a lib to do similar things,
so I was proposing to extract this pair of APIs in training/utils/,
which can be more used more generally. Also a comprehensive set of test
data are used for testing unflatten/flatten in unit tests.

Let me know if you have any other suggestions. 


### Refactor schema extraction and output unflattening

Move `_extract_schema` and `unflatten_user_output` in
`orttraining/orttraining/python/training/ortmodule/_io.py` . to
`extract_data_and_schema` and `unflatten_data_using_schema` in
`orttraining/orttraining/python/training/utils/torch_io_helper.py` as
shared libs, which can be used later by other features (deepspeed stage
3 hook rewrite).

While there are still a few duplicated logic handling flatten with
different task by recursively loop the data struct, will change them
step by step in case of heavy review efforts.
2023-08-04 13:58:21 +08:00
..
amp [Better Engineering] Bump ruff to 0.0.278 and fix new lint errors (#16789) 2023-07-21 12:53:41 -07:00
api Add support for training apis to support custom ops (#16601) 2023-07-14 11:15:51 -07:00
experimental Manage ORTModule configurations consistently (#16396) 2023-06-27 19:19:36 +08:00
onnxblock Disable PERF* rules in ruff to allow better readability (#16834) 2023-07-25 15:38:22 -07:00
optim [Better Engineering] Bump ruff to 0.0.278 and fix new lint errors (#16789) 2023-07-21 12:53:41 -07:00
ort_triton Disable PERF* rules in ruff to allow better readability (#16834) 2023-07-25 15:38:22 -07:00
ortmodule Refactor schema extraction and output unflattening (#16894) 2023-08-04 13:58:21 +08:00
torchdynamo [DORT] Enable Dynamic Shape in DORT and Use Different InferenceSession's when Inputs Are Not Compatible (#16753) 2023-07-24 16:54:01 -07:00
utils Refactor schema extraction and output unflattening (#16894) 2023-08-04 13:58:21 +08:00
__init__.py Refining the offline tooling for training artifact generation (#15212) 2023-03-30 18:05:51 -07:00
_checkpoint_storage.py Enable pylint and numpy rules (#15218) 2023-03-27 20:37:53 -07:00
_utils.py [Better Engineering] Bump ruff to 0.0.278 and fix new lint errors (#16789) 2023-07-21 12:53:41 -07:00
artifacts.py Add support for training apis to support custom ops (#16601) 2023-07-14 11:15:51 -07:00
checkpoint.py Disable PERF* rules in ruff to allow better readability (#16834) 2023-07-25 15:38:22 -07:00
model_desc_validation.py
orttrainer.py Disable PERF* rules in ruff to allow better readability (#16834) 2023-07-25 15:38:22 -07:00
orttrainer_options.py [Better Engineering] Bump ruff to 0.0.278 and fix new lint errors (#16789) 2023-07-21 12:53:41 -07:00
postprocess.py Disable PERF* rules in ruff to allow better readability (#16834) 2023-07-25 15:38:22 -07:00