PyDP silently truncates and converts `np.float32` into `int64`, leading to sensitivity underestimation
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 83/100
Hướng nghiên cứu
Bắt đầu với các khai báo binding trong src/bindings/PyDP/mechanisms/mechanism.cpp quanh dòng 52 và xem lại cách đăng ký các overload integer và double. Tái hiện hành vi bằng ví dụ np.float32 được cung cấp, sau đó xác minh rằng các giá trị np.float32 chọn binding double và không bị cắt cụt; chạy lại các bài kiểm thử liên quan đến mechanism bindings.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In the code that registers the bindings with the C++ building blocks library, the int64 binding is defined before the double binding. This has a surprising consequence: pybind11, after doing a pass that sees if the input type matches the declared type, it then tries overloads in order with an implicit conversion path. The int caster apparently accepts a np.float32 and silently truncates its input, so values of this type automatically use the int64 binding.
Silent truncation predictably negative consequences on the sensitivity analysis: 0.95 becomes 0 and 1.05 becomes 1, so sensitivity increases unexpectedly. This is observable in PyDP:
import numpy as np
from pydp.algorithms.numerical_mechanisms import LaplaceMechanism
mechanism = LaplaceMechanism(epsilon=1.0, sensitivity=0.1)
print("np.float32, D :", [mechanism.add_noise(np.float32(0.95)) for _ in range(10)])
print("np.float32, D':", [mechanism.add_noise(np.float32(1.05)) for _ in range(10)])
and also affects PipelineDP via add_dp_noise, or VECTOR_SUM with float32 values. This happens even though the value is multiplied by 1.0, maybe to try and cast it to float? Sadly this doesn't work, since 1.0 * np.float32(1.7) still has type np.float32.
Here's a repro for add_dp_noise:
import numpy as np
import pipeline_dp
for name, value in (("D ", np.float32(0.95)), ("D'", np.float32(1.05))):
releases = []
for _ in range(10):
accountant = pipeline_dp.NaiveBudgetAccountant(total_epsilon=1, total_delta=0)
engine = pipeline_dp.DPEngine(accountant, pipeline_dp.LocalBackend())
params = pipeline_dp.aggregate_params.AddDPNoiseParams(noise_kind=pipeline_dp.NoiseKind.LAPLACE, l0_sensitivity=1,
linf_sensitivity=0.1)
result = engine.add_dp_noise([("partition", value)], params)
accountant.compute_budgets()
releases.append(list(result)[0][1])
print(name, releases)
other PipelineDP aggregations (sum, mean, variance) convert to float64 and so aren't vulnerable to this.
This issue doesn't happen with np.float64, because np.float64 is a subclass of Python's native floats (while np.float32 is not). Therefore, the right binding is selected by pybind11 during the first pass.
Registering the double binding first would fix it.
- Ngôn ngữ chính
- Python
- Star
- 551
- Fork
- 142
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của OpenMined/PyDP
-
Type: New Feature :heavy_plus_sign:
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
-
Type: Question :grey_question:
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
-
Type: Question :grey_question:
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 32/100
-
Raise different errors based on the error code returned from the DP LibraryCó thể đã có người làm @kalra-mohit đã nhận 88 ngày trước. Đang mởType: Improvement :chart_with_upwards_trend:
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
Type: New Feature :heavy_plus_sign:
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
Tất cả issue của OpenMined/PyDP
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
FavioVazquez/showtime#101 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
rossant/awesome-math#199 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
nautechsystems/nautilus_trader#5365 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Examples say cnxĐang mởdocumentation embedded
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày