Skip to content

Commit 398a78a

Browse files
Pyre Bot Jr.meta-codesync[bot]
authored andcommitted
batch_91
Reviewed By: maggiemoss Differential Revision: D101008119
1 parent a6fe1c2 commit 398a78a

33 files changed

Lines changed: 119 additions & 26 deletions

privacy_guard/analysis/code_similarity/code_bleu_node.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
from privacy_guard.analysis.code_similarity.code_similarity_analysis_input import (
3131
CodeBleuAnalysisInput,
3232
)
33-
34-
# pyre-ignore[21]: tree-sitter doesn't have properly exposed type stubs
3533
from tree_sitter import Node
3634

3735
logger: logging.Logger = logging.getLogger(__name__)
@@ -73,7 +71,6 @@ def __init__(self, analysis_input: CodeBleuAnalysisInput) -> None:
7371
super().__init__(analysis_input=analysis_input)
7472

7573
@staticmethod
76-
# pyre-ignore[11]: Annotation `Node` is not defined as a type.
7774
def syntax_match(target_tree: Node, generated_tree: Node) -> float:
7875
def _node_sexp(node: Node) -> str:
7976
"""Build a position-independent s-expression string for a subtree."""

privacy_guard/analysis/extraction/text_inclusion_analysis_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def word_level_lcs_result_formatted(self) -> pd.DataFrame:
106106
num_matched_words=num_matched_words,
107107
matched_string=matched_string,
108108
augmented_row=augmented_row,
109-
analysis_input=self.analysis_input, # pyre-ignore
109+
analysis_input=self.analysis_input,
110110
)
111111
)
112112

@@ -166,7 +166,7 @@ def lcs_result_formatted(self, display_lcs_match: bool) -> pd.DataFrame:
166166
lcs_dict=lcs_dict,
167167
augmented_row=augmented_row,
168168
display_lcs_match=display_lcs_match,
169-
analysis_input=self.analysis_input, # pyre-ignore
169+
analysis_input=self.analysis_input,
170170
)
171171
)
172172

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ 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
7172

7273
metric_mean = metric_array.mean()
7374
metric_mean_lb, metric_mean_ub = 0, 0
7475
try:
75-
# pyre-ignore: Module `scipy.stats` has no attribute `bootstrap`.
7676
metric_mean_lb, metric_mean_ub = bootstrap(
7777
(metric_array,), statistic=np.mean, method="BCa"
7878
).confidence_interval
@@ -181,6 +181,7 @@ def run_analysis(self) -> BaseAnalysisOutput:
181181

182182
return outputs
183183

184+
# pyrefly: ignore [bad-specialization]
184185
def _make_acc_auc_epsilon_array(self) -> NDArray[float]:
185186
"""
186187
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def compute_metric_mean_with_ci(
4040
metric_mean = metric_array.mean()
4141
metric_mean_lb, metric_mean_ub = 0, 0
4242
try:
43-
# pyre-ignore: Module `scipy.stats` has no attribute `bootstrap`.
4443
metric_mean_lb, metric_mean_ub = bootstrap(
4544
(metric_array,), statistic=np.mean, method="BCa"
4645
).confidence_interval
@@ -128,6 +127,7 @@ def _compute_metrics_and_eps_fpr_array(
128127
f"An exception occurred when computing acc/auc/epsilon metrics: {e}"
129128
)
130129

130+
# pyrefly: ignore [bad-return]
131131
return metrics_results, eps_fpr_results
132132

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

0 commit comments

Comments
 (0)