Create AnyModule from generic pointer?

Given:
std::shared_ptr ptr
that was created from a concrete type, e.g. Linear
is there a way to create an AnyModule other than going through possible types,

e.g.
if(const auto& a=std::dynamic_pointer_casttorch::nn::Linear(m))

  • AnyModule …*
    else if(…)

Thanks