Skip to content

Commit db0a6da

Browse files
Pyre Bot Jr.facebook-github-bot
authored andcommitted
batch_91 (#126)
Summary: Pull Request resolved: #126 Reviewed By: maggiemoss Differential Revision: D101008119
1 parent a6fe1c2 commit db0a6da

27 files changed

Lines changed: 112 additions & 2 deletions

privacy_guard/analysis/lia/lia_analysis_input.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@
2222
class LIAAnalysisInput(BaseAnalysisInput):
2323
def __init__(
2424
self,
25+
# pyrefly: ignore [bad-specialization]
2526
predictions: NDArray[float],
27+
# pyrefly: ignore [bad-specialization]
2628
predictions_y1_generation: NDArray[float],
29+
# pyrefly: ignore [bad-specialization]
2730
true_bits: NDArray[int],
31+
# pyrefly: ignore [bad-specialization]
2832
y0: NDArray[int],
33+
# pyrefly: ignore [bad-specialization]
2934
y1: NDArray[int],
35+
# pyrefly: ignore [bad-specialization]
3036
received_labels: NDArray[int],
3137
) -> None:
3238
"""

privacy_guard/analysis/lia/lia_analysis_node.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ def compute_scores(self, i: int) -> Tuple[torch.Tensor, torch.Tensor]:
125125
Tuple[torch.Tensor, torch.Tensor]: scores for samples with training labels and reconstructed labels
126126
"""
127127

128+
# pyrefly: ignore [missing-attribute]
128129
received_labels = self._analysis_input.received_labels[i]
130+
# pyrefly: ignore [missing-attribute]
129131
y1_probs = self._analysis_input.predictions_y1_generation
132+
# pyrefly: ignore [missing-attribute]
130133
predictions = self._analysis_input.predictions
131134

132135
if self.score_computation_function is not None:
@@ -142,6 +145,7 @@ def compute_scores(self, i: int) -> Tuple[torch.Tensor, torch.Tensor]:
142145
np.log(prob_train + 1e-8) - np.log(prob_reconstruct + 1e-8)
143146
) * prob_diff_label**self._power
144147

148+
# pyrefly: ignore [missing-attribute]
145149
true_bits = self._analysis_input.true_bits[i]
146150
scores_train = torch.tensor(scores[true_bits == 0])
147151
scores_test = torch.tensor(scores[true_bits == 1])
@@ -152,7 +156,9 @@ def run_analysis(self) -> BaseAnalysisOutput:
152156
"""Run LIA analysis"""
153157

154158
error_thresholds = np.linspace(0.01, 1, 100)
159+
# pyrefly: ignore [missing-attribute]
155160
num_resampling = self._analysis_input.y1.shape[0]
161+
# pyrefly: ignore [missing-attribute]
156162
num_samples = self._analysis_input.y1.shape[1]
157163

158164
# run analysis for each game instance
@@ -221,9 +227,12 @@ def run_analysis(self) -> BaseAnalysisOutput:
221227
eps_at_tpr_bounds=(list(eps_tpr_lb), list(eps_tpr_ub)),
222228
eps_at_fpr_bounds=(list(eps_fpr_lb), list(eps_fpr_ub)),
223229
data_size=num_samples,
230+
# pyrefly: ignore [missing-attribute]
224231
label_mean=np.mean(self._analysis_input.y0),
232+
# pyrefly: ignore [missing-attribute]
225233
prediction_mean=np.mean(self._analysis_input.predictions),
226234
prediction_y1_generation_mean=np.mean(
235+
# pyrefly: ignore [missing-attribute]
227236
self._analysis_input.predictions_y1_generation
228237
),
229238
)

privacy_guard/analysis/mia/analysis_node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def _calculate_one_off_eps(self) -> float:
235235
return eps_cp
236236

237237
@staticmethod
238+
# pyrefly: ignore [bad-specialization]
238239
def _compute_ci(array: NDArray[float], axis: int = 0) -> tuple[NDArray, NDArray]:
239240
"""Compute confidence intervals (used for eps, auc, accuracy)"""
240241
# Sort along the specified axis
@@ -269,6 +270,7 @@ def _compute_bootstrap_sample_indexes(
269270
Returns:
270271
A list of indexes (with duplicates)
271272
"""
273+
# pyrefly: ignore [bad-return]
272274
return np.random.randint(0, num_users, sample_size)
273275

274276
def run_analysis(self) -> BaseAnalysisOutput:

privacy_guard/analysis/mia/fdp_analysis_node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import numpy as np
1818
from privacy_guard.analysis.base_analysis_node import BaseAnalysisNode
1919
from privacy_guard.analysis.base_analysis_output import BaseAnalysisOutput
20+
21+
# pyrefly: ignore [missing-module-attribute]
2022
from scipy.stats import norm
2123

2224

privacy_guard/analysis/mia/fpr_lower_bound_analysis_node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class FPRLowerBoundAnalysisNodeOutput(BaseAnalysisOutput):
6565

6666

6767
def compute_metric_mean_with_ci(
68+
# pyrefly: ignore [bad-specialization]
6869
metric_array: NDArray[float],
6970
) -> tuple[float, float, float]:
7071
# TODO: Identify descriptive values for mean, lb, ub when bootstrap fails
@@ -181,6 +182,7 @@ def run_analysis(self) -> BaseAnalysisOutput:
181182

182183
return outputs
183184

185+
# pyrefly: ignore [bad-specialization]
184186
def _make_acc_auc_epsilon_array(self) -> NDArray[float]:
185187
"""
186188
Make list of tuples metrics at error thresholds, each of which contains the

privacy_guard/analysis/mia/mia_results.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import numpy as np
1616
import torch
1717
from numpy.typing import NDArray
18+
19+
# pyrefly: ignore [missing-module-attribute]
1820
from scipy.stats import beta
1921
from sklearn.metrics import auc, roc_curve
2022

@@ -41,9 +43,12 @@ def __init__(self, scores_train: torch.Tensor, scores_test: torch.Tensor) -> Non
4143

4244
def _get_indices_of_error_at_thresholds(
4345
self,
46+
# pyrefly: ignore [bad-specialization]
4447
error_rates: NDArray[float],
48+
# pyrefly: ignore [bad-specialization]
4549
error_thresholds: NDArray[float],
4650
error_type: str,
51+
# pyrefly: ignore [bad-specialization]
4752
) -> NDArray[int]:
4853
"""
4954
Get indices where error values are greater/smaller than error thresholds.
@@ -80,6 +85,7 @@ def _get_indices_of_error_at_thresholds(
8085
else:
8186
raise ValueError(f"Invalid error type: {error_type}")
8287

88+
# pyrefly: ignore [bad-specialization]
8389
def get_tpr_fpr(self) -> tuple[NDArray[float], NDArray[float]]:
8490
"""
8591
Computes true positive rate and true negative rate given scores and labels indicating membership.
@@ -213,6 +219,7 @@ def compute_acc_auc_ci_epsilon(self, delta: float) -> tuple[float, float, float]
213219
def compute_metrics_at_error_threshold(
214220
self,
215221
delta: float,
222+
# pyrefly: ignore [bad-specialization]
216223
error_threshold: NDArray[float],
217224
cap_eps: bool = True,
218225
verbose: bool = False,

privacy_guard/analysis/mia/parallel_analysis_node.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def _compute_metrics_array(
123123
f"An exception occurred when computing acc/auc/epsilon metrics: {e}"
124124
)
125125

126+
# pyrefly: ignore [bad-return]
126127
return metrics_results
127128

128129
def _parallel_compute_chunk_sizes(self, task_num: int) -> list[int]:

privacy_guard/analysis/mia/parallel_fpr_lower_bound_analysis_node.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def _compute_metrics_and_eps_fpr_array(
128128
f"An exception occurred when computing acc/auc/epsilon metrics: {e}"
129129
)
130130

131+
# pyrefly: ignore [bad-return]
131132
return metrics_results, eps_fpr_results
132133

133134
def _parallel_compute_chunk_sizes(self, task_num: int) -> list[int]:

privacy_guard/analysis/scripts/probabilistic_memorization_analysis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
def dump_augmented_df(df: pd.DataFrame, jsonl_output_path: str) -> None:
3131
jsonl_data = df.to_json(orient="records", lines=True)
3232
with open(jsonl_output_path, "w") as f:
33+
# pyrefly: ignore [bad-argument-type]
3334
f.write(jsonl_data)
3435

3536

privacy_guard/analysis/scripts/reference_model_comparison.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def dump_augmented_df(df: pd.DataFrame, jsonl_output_path: str) -> None:
3232
jsonl_data = df.to_json(orient="records", lines=True)
3333
# Save JSONL data to file
3434
with open(jsonl_output_path, "w") as f:
35+
# pyrefly: ignore [bad-argument-type]
3536
f.write(jsonl_data)
3637

3738

0 commit comments

Comments
 (0)