mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
[JIT] adding torch.jit.isinstance support (#46062)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/46062 Adds support for torch.jit.isinstance in both eager and script mode Example use: ``` import torch from typing import Any, List class TestModule(torch.nn.Module): def __init__(self): super(TestModule, self).__init__() def call(self, input1: str, input2: str) -> str: return input1 def forward(self, input: Any) -> None: if torch.jit.isinstance(input, List[str]): for el in input: print(el) TestModule().forward(["1","2"]) scripted_module = torch.jit.script(TestModule()) scripted_module(["1", "2"]) ``` Test Plan: Imported from OSS Reviewed By: bertmaher, zou3519 Differential Revision: D24264415 Pulled By: Lilyjjo fbshipit-source-id: 039c95bddd854c414027ac8332832e6bc830b5b9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fdc5261a20
commit
f83cf2dab3
@ -918,6 +918,9 @@ std::shared_ptr<SugaredValue> toSugaredValue(
|
||||
} else if (
|
||||
obj.ptr() == py::module::import("torch.jit").attr("annotate").ptr()) {
|
||||
return SpecialFormValue::create(prim::annotate);
|
||||
} else if (
|
||||
obj.ptr() == py::module::import("torch.jit").attr("isinstance").ptr()) {
|
||||
return SpecialFormValue::create(prim::isinstance);
|
||||
#ifdef USE_RPC
|
||||
// RPC module is only avaialble when build flag "USE_DISTRIBUTED" is on.
|
||||
} else if (
|
||||
|
Reference in New Issue
Block a user