SHARK icon indicating copy to clipboard operation
SHARK copied to clipboard

Adding facebook dlrm in SHARK/tank

Open vidsinghal opened this issue 3 years ago • 8 comments

WIP: dlrm lowering through shark. Failing to lower to Torch right now. Exception: Lowering TorchScript IR -> Torch Backend IR failed with the following diagnostics: error: found a non-value tensor type, this is likely due to a missing case in the MaximizeValueSemantics pass note: see current operation: %25 = "torch.copy.to_tensor"(%24) : (!torch.vtensor) -> !torch.tensor

vidsinghal avatar Jul 14 '22 15:07 vidsinghal

Hi @vid-999 I saw in the torch IR that there are some lowering of the OPs missing like %32:4 = torch.operator "aten.embedding_bag.padding_idx"(%31, %30, %29, %false, %int0, %true, %none, %false, %none) : (!torch.tensor<[4,2],f32>, !torch.tensor<[3],si64>, !torch.tensor<[1],si64>, !torch.bool, !torch.int, !torch.bool, !torch.none, !torch.bool, !torch.none) -> (!torch.tensor<[1,2],f32>, !torch.tensor<[0],si64>, !torch.tensor<[1],si64>, !torch.tensor<[1],si64>) and hence the above issue is common. Could you add all the missing lowerings and then try? I see there are two torch.operator s.

pashu123 avatar Jul 21 '22 05:07 pashu123

Hi @pashu123 thanks for pointing that out. I am actually in the process of writing the linalg lowering for the aten.embedding_bag.padding_idx op. The only other torch.operator that I see is aten.to.device which I think I should be able to remove from the model code.

Also, maybe I misunderstood but when you say "try" you mean try to lower from TORCH to LINALG ?

vidsinghal avatar Jul 21 '22 12:07 vidsinghal

Hi @pashu123 thanks for pointing that out. I am actually in the process of writing the linalg lowering for the aten.embedding_bag.padding_idx op. The only other torch.operator that I see is aten.to.device which I think I should be able to remove from the model code.

Also, maybe I misunderstood but when you say "try" you mean try to lower from TORCH to LINALG ?

Yes, I mean torch to linalg. Also, since torch.operator is present, that op is not even registered in torch-mlir so the lowering means first adding it to torch-mlir and then lowering to linalg.

pashu123 avatar Jul 21 '22 14:07 pashu123

Yup. I have already registered it. I'm working on a branch. Here is a draft PR. Haven't pushed the latest changes here though. https://github.com/llvm/torch-mlir/pull/1066

vidsinghal avatar Jul 21 '22 14:07 vidsinghal

Yup. I have already registered it. I'm working on a branch. Here is a draft PR. Haven't pushed the latest changes here though. llvm/torch-mlir#1066

Cool!

pashu123 avatar Jul 21 '22 15:07 pashu123

We can save the generated linalg, input, and golden output in the shark tank and then enable the tests.

pashu123 avatar Jul 28 '22 05:07 pashu123

We can save the generated linalg, input, and golden output in the shark tank and then enable the tests.

should just add to the gen_shark_tank.py script right ? the upload should happen via @dan-garvey nightly build change.

powderluv avatar Jul 28 '22 15:07 powderluv

I added 2 manual tests for QrEmbedding and PrEmbedding modes. It was not straightforward to make artificial inputs for dlrm that would run those modes. But the code is representative of the code in the actual model (from the function create_emb)

For the QrEmbedding mode, one more op needs to be implemented: torch.operator "aten.remainder.Scalar"

vidsinghal avatar Jul 28 '22 15:07 vidsinghal