#pragma once #include #include #include #include #include #include #include namespace torch::nativert { class TORCH_API ModelRunner { public: ModelRunner(const std::string& packagePath, const std::string& modelName); ModelRunner(ModelRunner&&) = default; ModelRunner& operator=(ModelRunner&&) = default; ModelRunner(const ModelRunner&) = delete; ModelRunner& operator=(const ModelRunner&) = delete; ~ModelRunner() = default; c10::IValue run( const std::vector& args, const std::unordered_map& kwargs); /** * A low level API which expects user to always pass in flattened inputs. * The ownership of the entire input list must be transferred to the * executor via std::move or in-place construction. */ std::vector runWithFlatInputsAndOutputs( std::vector flatInputs); uint64_t numOutputs() const; std::shared_ptr loadWeightsDefault( Graph& graph, const std::shared_ptr& reader); private: std::unordered_map getPayloadConfig( const std::shared_ptr& pytorchStreamReader, std::string_view configFormat, const std::string& modelName); // original non-delegated graph from torch.export() std::shared_ptr graph_; std::unique_ptr executor_; ITreeSpec inputSpec_; ITreeSpec outputSpec_; torch::_export::ExportedProgram exportedProgram_; std::unordered_map tensorPaths_; std::unordered_map constantPaths_; }; } // namespace torch::nativert