-
Notifications
You must be signed in to change notification settings - Fork 108
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
[Feature]: 如何看到SPU DeviceObject的具体shares的值? #963
Comments
print(xs[0].share_chunks)
print(xs[1].share_chunks) 这两个都是secret shares,因为你使用的是"ref2k.Sec",每方的数据都是一样的(code ref)。另外,在c++转python过程中,会对 |
谢谢,参考您的建议和代码ValueChunkProto、heu.py后,在本问题所述代码中添加:
执行后,得到结果:
此时,x=4。另外,为了简单,我将share_max_chunk_size改为了8,这样share_chunks中只有一块数据。这是正确的吗? |
转成ValueChunkProto只是其中一小段,需要拼接起来的: import spu.api as ppapi
import spu.spu_pb2 as spu_pb2
import numpy as np
config = spu_pb2.RuntimeConfig(
protocol=spu_pb2.ProtocolKind.REF2K,
field=spu_pb2.FieldType.FM64,
fxp_fraction_bits=18,
share_max_chunk_size=4,
)
wsize = 2
io = ppapi.Io(wsize, config)
x = np.random.randint(-100, 100, size=());
xs = io.make_shares(x, spu_pb2.Visibility.VIS_SECRET)
print(x)
for xss in xs:
value = bytearray()
for chk in xss.share_chunks:
rt = spu_pb2.ValueChunkProto()
rt.ParseFromString(chk)
value += rt.content # <---- follow ValueFromPyBindShare
print(value)
print(int.from_bytes(value, "little", signed=True)) |
这个做法是非常trick的,仅仅用于debug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature Request Type
Usability
Have you searched existing issues?
Yes
Is your feature request related to a problem?
这里似乎给出了使用secretflow看到SPU DeviceObject具体shares值的方法:#908
但是在不使用secretflow而仅仅使用spu的情况下,如何获取secret shares的值?
我参照https://github.com/secretflow/spu/blob/main/spu/tests/spu_io_test.py
写了如下代码:
import spu.api as ppapi
import spu.spu_pb2 as spu_pb2
def _bytes_to_pb(msg: bytes):...与spu_io_test.py中函数定义相同
config = spu_pb2.RuntimeConfig(
protocol=spu_pb2.ProtocolKind.REF2K,
field=spu_pb2.FieldType.FM64,
fxp_fraction_bits=18,
share_max_chunk_size=4,
)
wsize=2
io = ppapi.Io(wsize, config)
x = np.random.randint(10, size=())
xs = io.make_shares(x, spu_pb2.Visibility.VIS_SECRET)
print(_bytes_to_pb(xs[0].meta))
print(xs[0].share_chunks)
print(xs[1].share_chunks)
print(x)
执行后的结果为:
data_type: DT_I64
visibility: VIS_SECRET
storage_type: "ref2k.Sec"
[b'\x08\x08\x1a\x04\x07\x00\x00\x00', b'\x08\x08\x10\x04\x1a\x04\x00\x00\x00\x00']
[b'\x08\x08\x1a\x04\x07\x00\x00\x00', b'\x08\x08\x10\x04\x1a\x04\x00\x00\x00\x00']
7
请问哪一项是secret shares?或者需要用到其他的函数?
Describe features you want to add to SPU
A clear and concise description of what you want to happen.
Describe features you want to add to SPU
A clear and concise description of any alternative solutions or features you've considered.
The text was updated successfully, but these errors were encountered: