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

fix: outputs order is wrong when more than 1 outputs #54

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

mhchia
Copy link
Member

@mhchia mhchia commented Jun 19, 2024

What's wrong?

With computation returning more than 1 outputs, we get the wrong order of outputs. For example, the computation like this

def computation(state: State, args: list[torch.Tensor]):
    x = args[0]
    y = args[1]
    return state.mean(x), state.median(y)

results in outputs like

51.5, 1, 46.25

where 1 is the boolean for verifiers to check the result is accurate enough. It is wrong since 1 should always be the first return value of a computation

The issue is that we return is_precise_aggregated, op.result+(x[0]-x[0])[0][0] for the last operation. However, the return value of a computation is not necessarily the return value of the last operation. For example,

def computation(state: State, args: list[torch.Tensor]):
    x = args[0]
    y = args[1]
    return state.mean(x), state.median(y)

the last operation is state.median(y) but the return value is state.mean(x), state.median(y). In our original approach, we'll return res_mean, is_precise_aggregated, res_median.

How it's fixed?

Instead of returning the is_precise_aggregated in State.call_ops, we do it in the Model.forward

def forward(self, *x: list[torch.Tensor]) -> tuple[IsResultPrecise, torch.Tensor]:
            result = computation(state, x)
            is_computation_result_accurate = state.bools[0]()
            for op_precise_check in state.bools[1:]:
                is_op_result_accurate = op_precise_check()
                is_computation_result_accurate = torch.logical_and(is_computation_result_accurate, is_op_result_accurate)
            return is_computation_result_accurate, result

@mhchia mhchia merged commit f0a28ea into main Jun 21, 2024
1 check passed
@mhchia mhchia deleted the fix/wrong-return-value-when-more-than-one-outputs branch June 21, 2024 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant