You never have std::shared_ptr<MySequential>.
The underlying is always std::shared_ptr<MySequentialImpl>.
MySequential is defined like this:
‘https://github.com/pytorch/pytorch/blob/a54416d208cd024779455c7b44e7b86f51a3da45/torch/csrc/api/include/torch/nn/pimpl.h#L202 2’
It is actually a ModuleHolder of MySequentialImpl, and ModuleHolder always hold a shared_ptr of MySequentialImpl.
If you want your MySequential obj (not shared_ptr) back, you can do
auto obj = torch::nn::ModuleHolder<MySequentialImpl>(module.ptr<MySequentialImpl>(0));
but you have to know the type of the module at each position in your module.
Normally, you just need to use the Impl ptr to call ->forward(), no?