Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PT FE] Fix issue with aten.copy in FX graph #23711

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/frontends/pytorch/src/op/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ OutputVector translate_copy_(const NodeContext& context) {
return {res};
};

OutputVector translate_copy_fx(const NodeContext& context) {
// copy = torch.ops.aten.copy.default(slice_4);
// copy = torch.ops.aten.copy.default(slice_4, clone);
num_inputs_check(context, 1, 2);
auto self = context.get_input(0);
if (context.input_is_none(1)) {
return {self};
} else {
auto src = context.get_input(1);
auto src_converted = context.mark_node(std::make_shared<v1::ConvertLike>(src, self));
auto self_shape = context.mark_node(std::make_shared<v3::ShapeOf>(self));
Output<Node> res = context.mark_node(std::make_shared<v3::Broadcast>(src_converted, self_shape));
return {res};
}
};

OutputVector translate_alias_copy(const NodeContext& context) {
// aten::alias_copy(Tensor self) -> Tensor
// aten::alias_copy.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)
Expand Down
9 changes: 5 additions & 4 deletions src/frontends/pytorch/src/op/rand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ OutputVector make_random_normal(const NodeContext& context,
}; // namespace

OutputVector translate_rand(const NodeContext& context) {
num_inputs_check(context, 2, 6);
num_inputs_check(context, 1, 6);
auto sizes = context.get_input(0);
if (context.get_input_type(0).is<type::List>()) {
sizes = concat_list_construct(sizes);
Expand All @@ -57,14 +57,15 @@ OutputVector translate_rand(const NodeContext& context) {
size_t out_id = 1;
if (context.get_input_size() == 3) {
PYTORCH_OP_CONVERSION_CHECK(context.input_is_none(1),
"aten::randn conversion with generator does not supported");
"aten::rand conversion with generator does not supported");
out_id = 2;
}
// aten::rand.out(SymInt[] size, *, Tensor(a!) out) -> Tensor(a!)
// aten::rand.generator_out(SymInt[] size, *, Generator? generator, Tensor(a!) out) -> Tensor(a!)
if (context.get_input_size() == 2 || context.get_input_size() == 3) {
if (context.get_input_size() <= 3) {
auto res = context.mark_node(std::make_shared<v8::RandomUniform>(sizes, low, high, dtype));
context.mutate_input(out_id, res);
if (context.get_input_size() >= 2)
context.mutate_input(out_id, res);
return {res};
}
// aten::rand(SymInt[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool?
Expand Down
4 changes: 3 additions & 1 deletion src/frontends/pytorch/src/op_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ OP_CONVERTER(translate_batch_norm_legit_no_training_fx);
OP_CONVERTER(translate_batch_norm_legit_no_stats_fx);
OP_CONVERTER(translate_cat_fx);
OP_CONVERTER(translate_constant_pad_nd_fx);
OP_CONVERTER(translate_copy_fx);
OP_CONVERTER(translate_cumsum_fx);
OP_CONVERTER(translate_chunk_fx);
OP_CONVERTER(translate_div_fx);
Expand Down Expand Up @@ -779,7 +780,7 @@ const std::map<std::string, CreatorFunction> get_supported_ops_fx() {
{"aten.clone.default", op::skip_node}, // ignore clone operators that are inserted by PyTorch autograd
{"aten.constant_pad_nd.default", op::translate_constant_pad_nd_fx},
{"aten.convolution.default", op::translate_convolution},
{"aten.copy.default", op::skip_node},
{"aten.copy.default", op::translate_copy_fx},
{"aten.copy_.default", op::translate_copy_},
{"aten.cos.default", op::translate_1to1_match_1_inputs_with_fp32_type_alignment<opset10::Cos>},
{"aten.cosh.default", op::translate_1to1_match_1_inputs_with_fp32_type_alignment<opset10::Cosh>},
Expand Down Expand Up @@ -886,6 +887,7 @@ const std::map<std::string, CreatorFunction> get_supported_ops_fx() {
{"aten.pow.Tensor_Tensor", op::translate_pow},
{"aten.pixel_shuffle.default", op::translate_pixel_shuffle},
{"aten.pixel_unshuffle.default", op::translate_pixel_unshuffle},
{"aten.rand.default", op::translate_rand},
{"aten.reciprocal.default", op::translate_reciprocal},
{"aten.reflection_pad1d.default", op::translate_reflection_pad_nd_fx},
{"aten.reflection_pad2d.default", op::translate_reflection_pad_nd_fx},
Expand Down
17 changes: 17 additions & 0 deletions tests/layer_tests/pytorch_tests/test_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ def forward(self, x):
return y


class aten_alias_tensor(torch.nn.Module):
def forward(self, x):
y = x.clone()
n,c,h,w = x.shape
ones = torch.ones([2,h,w]).to(x.dtype)
y[:, 1:, :, :] = ones
return y


class aten_loop_alias(torch.nn.Module):
def forward(self, x):
y = x.clone()
Expand All @@ -36,6 +45,14 @@ def test_alias(self, ie_device, precision, ir_version):
"aten::copy_"],
ie_device, precision, ir_version)

@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_alias_tensor(self, ie_device, precision, ir_version):
self._test(aten_alias_tensor(), None, ["aten::slice",
"aten::copy_"],
ie_device, precision, ir_version, freeze_model=False)

@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
Expand Down
3 changes: 1 addition & 2 deletions tests/model_hub_tests/pytorch/hf_transformers_models
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ facebook/opt-125m,opt
facebook/rag-token-nq,rag,skip,Load problem
facebook/sam-vit-large,sam,xfail,No node with name original_sizes
facebook/timesformer-base-finetuned-k400,timesformer
facebook/vit-mae-base,vit_mae,xfail,Accuracy validation failed
facebook/vit-mae-base,vit_mae
facebook/wmt19-ru-en,fsmt,xfail,Tracing problem
facebook/xlm-roberta-xl,xlm-roberta-xl
facebook/xmod-base,xmod
Expand Down Expand Up @@ -201,7 +201,6 @@ kiddothe2b/hierarchical-transformer-base-4096-v2,hat,skip,Load problem
k-l-lambda/clip-text-generator,clip_text_generator,skip,Load problem
k-l-lambda/stable-diffusion-v1-4-inv-embed,inv_word_embed,skip,Load problem
KoboldAI/fairseq-dense-13B-Janeway,xglm,skip,Large Model
konverner/qdq-camembert-apolliner,qdqbert,xfail,Repository not found
krasserm/perceiver-ar-clm-base,perceiver-ar-causal-language-model,skip,Load problem
krasserm/perceiver-ar-sam-giant-midi,perceiver-ar-symbolic-audio-model,skip,Load problem
krasserm/perceiver-io-img-clf,perceiver-io-image-classifier,skip,Load problem
Expand Down
Loading