Skip to content

Commit

Permalink
lower sigmoid to mlir, and adding test with varying shapes of inputs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dgolubovicTT authored Sep 9, 2024
1 parent 43f671e commit 25b4466
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions forge/csrc/passes/lower_to_mlir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ class MLIRGenerator
lowering_handler_map["greater_equal"] = &MLIRGenerator::emit_mlir_ttforge_op<mlir::tt::ttir::GreaterEqualOp>;
lowering_handler_map["unsqueeze"] = &MLIRGenerator::emit_mlir_ttforge_op<mlir::tt::ttir::UnsqueezeOp>;
lowering_handler_map["conv2d"] = &MLIRGenerator::emit_mlir_ttforge_op<mlir::tt::ttir::Conv2dOp>;
lowering_handler_map["sigmoid"] = &MLIRGenerator::emit_mlir_ttforge_op<mlir::tt::ttir::SigmoidOp>;
}
};
}
Expand Down
30 changes: 30 additions & 0 deletions forge/test/mlir/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,33 @@ def forward(self, x):

co_out = [co.to("cpu") for co in co_out]
assert compare_with_golden_pcc(golden=fw_out, calculated=co_out[0], pcc=0.99)


@pytest.mark.parametrize("shape", [
(7,), # 1D tensor
(32,), # 1D tensor
(7, 32), # 2D tensor
(32, 41), # 2D tensor
(1, 7, 32), # 3D tensor
(1, 32, 41), # 3D tensor
(1, 7, 32, 41), # 4D tensor
(2, 7, 32, 41) # 4D tensor
])
def test_sigmoid(shape):
class Sigmoid(nn.Module):
def __init__(self):
super().__init__()
def forward(self, x):
return torch.sigmoid(x)

inputs = [
torch.rand(*shape),
]
framework_model = Sigmoid()
fw_out = framework_model(*inputs)

compiled_model = forge.compile(framework_model, sample_inputs=inputs)
co_out = compiled_model(*inputs)

co_out = [co.to("cpu") for co in co_out]
assert compare_with_golden_pcc(golden=fw_out, calculated=co_out[0], pcc=0.99)

0 comments on commit 25b4466

Please sign in to comment.