Skip to content

Conversation

@viv-eth
Copy link
Contributor

@viv-eth viv-eth commented May 9, 2025

This PR fixes a minor issue when inferring the input type. If the data range fits both the unsigned and signed version of a certain data type, it will pick first the signed version due to the current sorting mechanism. This is changed to prefer unsigned over signed datatypes.

Added

  • Introduced a sorted_types list in the integer branch to capture integer types ordered by (typeWidth, isSigned).

Changed

  • Replaced the old sorted(IntegerDataTypes, key=lambda x: x.typeWidth) loop with:
sorted_types = sorted(
    IntegerDataTypes,
    key=lambda t: (t.typeWidth, t.typeMin < 0),
)
for _type in sorted_types:
    …

Fixed

  • Arrays with only non-negative values were previously inferred as signed if that happened to appear first; now they first try unsigned data types. This avoids errors when the input data sample is not "representative enough" to infer the type correctly.

PR Merge Checklist

  1. The PR is rebased on the latest devel commit and pointing to devel.
  2. Your PR reviewed and approved.
  3. All checks are passing.
  4. The CHANGELOG.md file has been updated.

@viv-eth
Copy link
Contributor Author

viv-eth commented May 12, 2025

After some investigation, I discovered that the following check fails:

    def typeCheckNodeInputs(self, ctxt: NetworkContext, node: gs.Node) -> bool:
        """DONT OVERRIDE - Type checks all input nodes to confirm they either already are assigned the correct type or their type can be statically upcast to the rule's input types

        Parameters
        ----------
        ctxt : NetworkContext
            Current NetworkContext
        node : gs.Node
            Node whose inputs should be analyzes

        Returns
        -------
        bool
            Whether the input's types match the rule's requirements

        """
        retCheck = True

        for inputNode, _type in zip(node.inputs, self.input_types):
            reference = ctxt.lookup(inputNode.name)

            if not isinstance(reference, VariableBuffer):
                return False

            if hasattr(reference, "values"):
                retCheck &= _type.referencedType.checkPromotion(reference.values)
            else:
                if ctxt.is_global(inputNode.name):
                    retCheck &= _type.referencedType.partialOrderUpcast(reference._type.referencedType)

                    if retCheck:
                        reference._type = _type
                        reference._instance = _type(inputNode.name, ctxt)
                else:
                    retCheck &= reference._type.referencedType == _type.referencedType
        return retCheck

Specifically, in this line:

retCheck &= reference._type.referencedType == _type.referencedType

, as reference._type.referencedType evaluates to <class 'Deeploy.CommonExtensions.DataTypes.uint8_t'> and _type.referencedType evaluates to <class 'Deeploy.CommonExtensions.DataTypes.int8_t'>. This means we run in the exact opposite case as before. Interestingly, it does not fail for the other platforms.

@Victor-Jung Victor-Jung added the Bug Something isn't working label May 18, 2025
@Victor-Jung Victor-Jung added this to the Release xxx milestone May 22, 2025
@Xeratec Xeratec added this to Deeploy May 22, 2025
@Victor-Jung Victor-Jung moved this to In progress in Deeploy May 22, 2025
@viv-eth viv-eth force-pushed the vivianep/typeMatching branch from d72dcd0 to 79f647a Compare June 7, 2025 01:00
@viv-eth
Copy link
Contributor Author

viv-eth commented Jun 10, 2025

I fixed the failing test by generating input data for the Adder containing negative values, such that the test input is not in the range of uint8 anymore.

Warning: This is a lazy fix, however, could potentially lead to problems later. This is because the type inference inherently assumes some sort of type matching order.

Happy to discuss how to tackle this issue (potentially introducing some flags as hints for the compiler), but I think for now it's okay.

@viv-eth viv-eth marked this pull request as ready for review June 10, 2025 06:18
@Xeratec Xeratec moved this from In progress to In review in Deeploy Jun 10, 2025
@Xeratec Xeratec modified the milestones: Release xxx, Release 0.2.0 Jun 10, 2025
@Victor-Jung
Copy link
Member

Victor-Jung commented Jun 10, 2025

Does it make more sense to infer an unsigned first instead of a signed? There is no "good answer" if the input sample is biased (fundamentally, both answers are correct). Can you add an interface for the user to bypass the auto-inference system?

@Xeratec
Copy link
Member

Xeratec commented Jun 10, 2025

Does it make more sense to infer an unsigned first instead of a signed? There is no "good answer" if the input sample is biased (fundamentally, both answers are correct). Can you just add an interface for the user to bypass the auto-inference system?

Our assumption is that we can infer the minimum required type based on the input sample. For the bitwidth, this is obvious, and I argue it is more logical to infer an unsigned datatype if there are no negative numbers in the inputs. In summary, I agree with Vivi's changes, but I am also in favor of adding a flag to bypass the auto-inference.
(btw. If I remember correctly, this existed in the early days of Deeploy)

@Victor-Jung
Copy link
Member

Does it make more sense to infer an unsigned first instead of a signed? There is no "good answer" if the input sample is biased (fundamentally, both answers are correct). Can you just add an interface for the user to bypass the auto-inference system?

Our assumption is that we can infer the minimum required type based on the input sample. For the bitwidth, this is obvious, and I argue it is more logical to infer an unsigned datatype if there are no negative numbers in the inputs. In summary, I agree with Vivi's changes, but I am also in favor of adding a flag to bypass the auto-inference.

(btw. If I remember correctly, this existed in the early days of Deeploy)

Okay I see the point of putting unsigned type first in the matching list. Let's get this flag setup and this PR rolling then @viv-eth 😁

@Xeratec Xeratec moved this from In review to In progress in Deeploy Jun 16, 2025
@Xeratec
Copy link
Member

Xeratec commented Jun 19, 2025

@viv-eth Any plans to work on this in the next 2 weeks? Alternatively, I can offer to take it over, but will most likely include it in the next release.

Copy link
Member

@Xeratec Xeratec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing the suggested changes. Please rebase the PR and address the remaining small comments and make sure all tests pass. Let me know if I should take over.

@viv-eth viv-eth force-pushed the vivianep/typeMatching branch from 343700f to cc8f8ec Compare August 16, 2025 21:44
Copy link
Member

@Xeratec Xeratec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes were added under v0.2.0 in the Changelog and not under v0.2.1. I will change it, rebase it after merging #93, and merge it once the tests succeed. Thanks for your effort!

- Add GitHub tests
- Remove outdated GitLab CI file
- Add support for `--shouldFail` for network generation
@Xeratec Xeratec force-pushed the vivianep/typeMatching branch from 56b7a31 to 214f8da Compare August 22, 2025 15:24
@Xeratec Xeratec self-assigned this Aug 23, 2025
Copy link
Member

@Xeratec Xeratec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue this is okay and ready for merge but please either @viv-eth or @lukamac give it a quick review.

@Xeratec Xeratec moved this from Ready for Merge to Need Reviewer in Deeploy Aug 23, 2025
@Xeratec Xeratec mentioned this pull request Aug 25, 2025
5 tasks
Copy link
Contributor

@lukamac lukamac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the comments on the code, I have a question regarding the change of the Adder test. I saw in the beginning of the PR conversation that the change of the Adder test was a kind of stop-gap solution. Is it still necessary to change it? If not, I would revert it.

Also, I would mention in the changelog the new testTypeInferenceDifferentTypes and the deletion of the .gitlab-ci.yml.

@Xeratec
Copy link
Member

Xeratec commented Aug 27, 2025

Besides the comments on the code, I have a question regarding the change of the Adder test. I saw in the beginning of the PR conversation that the change of the Adder test was a kind of stop-gap solution. Is it still necessary to change it? If not, I would revert it.

Also, I would mention in the changelog the new testTypeInferenceDifferentTypes and the deletion of the .gitlab-ci.yml.

I’ve implemented all the requested changes, except for reverting the Adder test. The reason is that it still fails on the Snitch platform: the inputs are unsigned, but we currently don’t have an unsigned Add kernel in Snitch, nor do we support bias hoisting for the signed kernel.

coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as outdated.

@Xeratec Xeratec force-pushed the vivianep/typeMatching branch from abdfaba to 96febcf Compare August 27, 2025 11:54
@Xeratec Xeratec force-pushed the vivianep/typeMatching branch from 96febcf to 4b5b792 Compare August 27, 2025 11:59
@lukamac
Copy link
Contributor

lukamac commented Aug 27, 2025

I’ve implemented all the requested changes, except for reverting the Adder test. The reason is that it still fails on the Snitch platform: the inputs are unsigned, but we currently don’t have an unsigned Add kernel in Snitch, nor do we support bias hoisting for the signed kernel.

Thanks for the effort :)

I'm thinking that it might make more sense to rename the current Adder test to AdderUnsigned and add this one as a new AdderSigned test and have the snitch platform only check the AdderSigned. I'm kinda reluctant to replace a test just because it fails on a specific platform because we kinda lose that information then.

@Xeratec Xeratec force-pushed the vivianep/typeMatching branch from cd6b4b0 to 37d4ca2 Compare August 27, 2025 15:22
@Xeratec Xeratec requested a review from lukamac August 27, 2025 15:23
@Xeratec
Copy link
Member

Xeratec commented Aug 27, 2025

I'm thinking that it might make more sense to rename the current Adder test to AdderUnsigned and add this one as a new AdderSigned test and have the snitch platform only check the AdderSigned. I'm kinda reluctant to replace a test just because it fails on a specific platform because we kinda lose that information then.

As discussed offline, we will keep the new test, which tests a signed addition.

Copy link
Contributor

@lukamac lukamac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@Xeratec Xeratec merged commit f4cce77 into pulp-platform:devel Aug 27, 2025
121 checks passed
@github-project-automation github-project-automation bot moved this from Need Reviewer to Done in Deeploy Aug 27, 2025
diaconuccalin pushed a commit to Aldrago98/Deeploy that referenced this pull request Oct 17, 2025
* [DeeployTest] Change order of typeMatching entries

* [Tests] Add negative values to correctly match type

* [ci] Add tests for manual type inference

* [DeeployTest] Add manual type inference feature

* [CHANGELOG] Update with manual type inference feature

* [DeeployTest] Align command line args with network generator

* [CHANGELOG] Add PR to list of PRs

* [DeeployTest] Remove non-ASCII chars

* [DeeployTest] Move to Numpy-style docs

* [DeeployTest] Fix input/output indexing error by zipping input names and arrays

* Fix CI Tests
- Add GitHub tests
- Remove outdated GitLab CI file
- Add support for `--shouldFail` for network generation

* Fix Changelog

* Improve debugging and implement CodeRabbit suggestions

* Implement PR feedback for Luka

* Fix CI

---------

Co-authored-by: viv-eth <[email protected]>
Co-authored-by: Philip Wiese <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request Oct 17, 2025
5 tasks
diaconuccalin pushed a commit to diaconuccalin/Deeploy that referenced this pull request Oct 27, 2025
* [DeeployTest] Change order of typeMatching entries

* [Tests] Add negative values to correctly match type

* [ci] Add tests for manual type inference

* [DeeployTest] Add manual type inference feature

* [CHANGELOG] Update with manual type inference feature

* [DeeployTest] Align command line args with network generator

* [CHANGELOG] Add PR to list of PRs

* [DeeployTest] Remove non-ASCII chars

* [DeeployTest] Move to Numpy-style docs

* [DeeployTest] Fix input/output indexing error by zipping input names and arrays

* Fix CI Tests
- Add GitHub tests
- Remove outdated GitLab CI file
- Add support for `--shouldFail` for network generation

* Fix Changelog

* Improve debugging and implement CodeRabbit suggestions

* Implement PR feedback for Luka

* Fix CI

---------

Co-authored-by: viv-eth <[email protected]>
Co-authored-by: Philip Wiese <[email protected]>
This was referenced Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants