webonnx / wonnx

A WebGPU-accelerated ONNX inference run-time written 100% in Rust, ready for native and the web
Other
1.54k stars 54 forks source link

Integration of HardSigmoid Operation #185

Closed ariaghora closed 6 months ago

ariaghora commented 10 months ago

This pull request introduces the HardSigmoid operation into the existing framework.

Motivation:

Several recent and good-performing OCR models (such as those found in PaddleOCR) utilize ConvTranspose and HardSigmoid. The ConvTranspose PR (#182) is currently in progress, and with anticipation for its completion, I decided to help implementing HardSigmoid part.

Changes:

Please review the changes and merge if you're OK. Feel free to request any modifications if necessary.

pixelspark commented 10 months ago

@ariaghora looks good to me! Two things before I can merge this:

ariaghora commented 10 months ago

@pixelspark nice! Few things to clarify:

pixelspark commented 10 months ago

@pixelspark nice! Few things to clarify:

  • Should I put checkmark indicating support only on "Implemented" column, or should I put it on "Shape inference supported" column as well? I'm not sure about the second one (since I didn't explicitly implement shape inference stuff).

  • By "enable the HardSigmoid test(s)" do you mean modifying wonnx-py/tests/test_onnx_backend.py and adding something like backend_test.include(f"test_hard_sigmoid_[a-z,_]*")? I'll check if they have tests for this op, anyway.

Yes and yes! (And no need to enable the test if there is none of course. If it fails for some reason but the op is still useful, just leave the test disabled and make a note somewhere)

Shape inference is not too difficult to implement, I assume you can just add this op in the list with other ops that take one input and provide one output with exactly the same shape. Then of course you can insert two checkmarks in the readme.

ariaghora commented 10 months ago

@pixelspark Yes, it gives an output with the same shape as the input. I put two checkmarks.

One more thing: some tests failed due to unimplemented CastLike node. Is it a known issue?

==================================================================================== short test summary info ====================================================================================
FAILED tests/test_specific_op.py::OnnxBackendNodeModelTest::test_hardsigmoid_default_expanded_ver18_cpu - pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: GpuError(CompileError { node: "CastLike", error: UnimplementedOp("CastLike") })
FAILED tests/test_specific_op.py::OnnxBackendNodeModelTest::test_hardsigmoid_example_expanded_ver18_cpu - pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: GpuError(CompileError { node: "CastLike", error: UnimplementedOp("CastLike") })
FAILED tests/test_specific_op.py::OnnxBackendNodeModelTest::test_hardsigmoid_expanded_ver18_cpu - pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: GpuError(CompileError { node: "CastLike", error: UnimplementedOp("CastLike") })
===================================================================== 3 failed, 3 passed, 2628 skipped, 1 warning in 2.51s ======================================================================

Other than that, I guess it is ready.

pixelspark commented 8 months ago

@pixelspark Yes, it gives an output with the same shape as the input. I put two checkmarks.

One more thing: some tests failed due to unimplemented CastLike node. Is it a known issue?

==================================================================================== short test summary info ====================================================================================
FAILED tests/test_specific_op.py::OnnxBackendNodeModelTest::test_hardsigmoid_default_expanded_ver18_cpu - pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: GpuError(CompileError { node: "CastLike", error: UnimplementedOp("CastLike") })
FAILED tests/test_specific_op.py::OnnxBackendNodeModelTest::test_hardsigmoid_example_expanded_ver18_cpu - pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: GpuError(CompileError { node: "CastLike", error: UnimplementedOp("CastLike") })
FAILED tests/test_specific_op.py::OnnxBackendNodeModelTest::test_hardsigmoid_expanded_ver18_cpu - pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: GpuError(CompileError { node: "CastLike", error: UnimplementedOp("CastLike") })
===================================================================== 3 failed, 3 passed, 2628 skipped, 1 warning in 2.51s ======================================================================

Other than that, I guess it is ready.

I think CastLike is not implemented - just disable these tests for now. I will then merge this PR (finally :-))

ariaghora commented 8 months ago

I disabled the tests.

(off-topic: is CastLike being implemented now? I might be able to help on this.)

pixelspark commented 7 months ago

I disabled the tests.

OK, will run CI and then merge. Thanks!

(off-topic: is CastLike being implemented now? I might be able to help on this.)

Not as far as I know, feel free to go ahead!