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

InvertSqrt not working for higher precision #1560

Open
hiddely opened this issue Dec 20, 2024 · 0 comments
Open

InvertSqrt not working for higher precision #1560

hiddely opened this issue Dec 20, 2024 · 0 comments

Comments

@hiddely
Copy link

hiddely commented Dec 20, 2024

Hi Marcel,

The InvertSqrt implementation seems to have stopped working for custom precisions. I used the same script when reporting the correctness bug in InvertSqrt last May.

InvertSqrt example script
# test mpc_math.InvertSqrt and compare with ground truth

import numpy as np
from Compiler import mpc_math, util

# with these two commented out the script works
cfix.set_precision(32, 62)
sfix.set_precision(32, 62)

def InvertSqrtGroundTruth(x):
    return 1.0 / np.sqrt(x)

input_value = 0.001

# ground truth
ground_truth = InvertSqrtGroundTruth(input_value)
test = mpc_math.InvertSqrt(sfix(input_value))
test_sfix = 1 / mpc_math.sqrt(sfix(input_value))

print_ln("ground_truth %s == InvertSqrt %s", ground_truth, test.reveal())
print_ln("1 / sqrt() %s == InvertSqrt %s", test_sfix.reveal(), test.reveal())

The script runs successfully for the version after the fix (a44132e), but in a newer version of MP-SPDZ (6b2f4e54) it gives the following compiler error:

Traceback (most recent call last):
  File "./Scripts/compile-run.py", line 14, in <module>
    prog = compiler.compile_file()
  File "./Scripts/../Compiler/compilerLib.py", line 496, in compile_file
    return self.finalize_compile()
  File "./Scripts/../Compiler/compilerLib.py", line 529, in finalize_compile
    self.prog.finalize()
  File "./Scripts/../Compiler/program.py", line 558, in finalize
    tape.optimize(self.options)
  File "./Scripts/../Compiler/program.py", line 1038, in wrapper
    return function(self, *args, **kwargs)
  File "./Scripts/../Compiler/program.py", line 1127, in optimize
    self.expand_cisc()
  File "./Scripts/../Compiler/program.py", line 1038, in wrapper
    return function(self, *args, **kwargs)
  File "./Scripts/../Compiler/program.py", line 1291, in expand_cisc
    expanded = block.expand_cisc()
  File "./Scripts/../Compiler/program.py", line 966, in expand_cisc
    inst.expand_merged(skip)
  File "./Scripts/../Compiler/instructions_base.py", line 650, in expand_merged
    self.expand_to_tape(size, new_regs)
  File "./Scripts/../Compiler/instructions_base.py", line 605, in expand_to_tape
    res = util.tuplify(f(*(arg.load() for arg in in_args)))
  File "./Scripts/../Compiler/library.py", line 459, in __call__
    self.on_first_call(wrapped_function, key, my_args)
  File "./Scripts/../Compiler/library.py", line 469, in on_first_call
    assert tape_handle == program.new_tape(
  File "./Scripts/../Compiler/program.py", line 351, in new_tape
    function(*args)
  File "./Scripts/../Compiler/library.py", line 452, in wrapped_function
    self.result = self.function(*actual_call_args,
  File "./Scripts/../Compiler/instructions_base.py", line 599, in f
    self.new_instructions(size, my_args)
  File "./Scripts/../Compiler/instructions_base.py", line 502, in new_instructions
    self.function(*args, **self.kwargs)
  File "./Scripts/../Compiler/instructions_base.py", line 735, in instruction
    res.mov(res, function(sfix._new(arg, k=k, f=f), *args).v)
  File "./Scripts/../Compiler/mpc_math.py", line 943, in InvertSqrt
    u, z = Sep(x, sfix=my_sfix)
  File "./Scripts/../Compiler/mpc_math.py", line 908, in Sep
    bb.insert(0, type(b[0])(0))
  File "./Scripts/../Compiler/GC/types.py", line 460, in __init__
    bits.__init__(self, *args, **kwargs)
  File "./Scripts/../Compiler/GC/types.py", line 148, in __init__
    self.load_other(value)
  File "./Scripts/../Compiler/GC/types.py", line 519, in load_other
    super(sbits, self).load_other(other)
  File "./Scripts/../Compiler/GC/types.py", line 168, in load_other
    self.set_length(self.n or util.int_len(other))
  File "./Scripts/../Compiler/GC/types.py", line 152, in set_length
    if n > self.n:
TypeError: '>' not supported between instances of 'int' and 'NoneType'

Thanks in advance, any pointers would be greatly appreciated!

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

No branches or pull requests

1 participant