Lecture 10 · 差分隐私 · Differential Privacy

Trustworthy Machine Learning · Lecture 10。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

对应 Maps to:Stanford CS329T Spring 2022 第 8 周(2022-05-17 Datta & Mitchell 的 “Privacy” slides:ML 中的隐私风险、“sanitize the database”及其局限、Sweeney 的病历链接、Netflix–IMDb 去匿名化、differential privacy:“Released statistic stays about the same if any individual’s record is removed from the database”[Dwork, McSherry, Nissim & Smith 2006]、interactive vs non-interactive 两种发布方式、课堂讨论”均值 vs 最大值查询有多难私有化”与 Terry Gross 的例子、membership inference)。阅读材料:Dwork 2006 “Differential Privacy”(ICALP);Dwork 2008 “Differential Privacy: A Survey of Results”;McSherry & Mironov 2009 “Differentially Private Recommender Systems: Building Privacy into the Netflix Prize Contenders”;Kifer & Machanavajjhala 2011 “No Free Lunch in Data Privacy”。第 9 周的”隐私与解释的联系”在 §8.5。HW4(先实现 Shokri 的 shadow-model 成员推断攻击 —— 2021 年的作业文本就是这一部分 —— 再用基于 DP 的防御、评估它把成员推断风险降低了多少)对应代码 04 演示 2。攻击本身(linkage、model inversion、Shokri / Yeom / LiRA、低 FPR 下的 TPR、memorization 与训练数据提取)是第 9 讲的内容。 配套代码 Code:code/lecture10/(numpy;5 个脚本 + 1 个工具模块;04 约 20 秒、03 约 10 秒,其余都在 5 秒以内;导入第 1 讲的 trust_data.py 和 trust_tools.py) 预计阅读时间:3 小时(含运行代码)


0. 本讲导航 · How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. 解释为什么”去掉名字”(anonymization)和”只发布统计量”(aggregate-only release)都保护不了个人:linkage 攻击、差分攻击,以及 Dinur–Nissim 的重建攻击 —— “对太多问题给出太准确的回答,隐私一定会被摧毁”。
  2. State the definition of (ε,δ)(\varepsilon, \delta)-differential privacy precisely — neighboring datasets, the probability ratio, the role of δ\delta — and translate it into hypothesis-testing terms: any membership inference test satisfies TPR≤eε FPR+δ\text{TPR} \le e^\varepsilon\,\text{FPR} + \delta, so its advantage is at most (eε−1+2δ)/(eε+1)(e^\varepsilon - 1 + 2\delta)/(e^\varepsilon + 1).
  3. 说出 DP 不承诺什么(No Free Lunch):相关的记录、从群体规律对个人做的推断(“吸烟致癌”)、群体层面的隐私;以及为什么 DP 是算法的性质、不是输出的性质。
  4. Build the basic mechanisms (randomized response, Laplace, Gaussian, exponential), calibrate them to sensitivity, and explain why sums and means must be clipped first.
  5. 用组合定理(basic、advanced、Rényi DP)和子采样放大给一个多步算法记账,并解释为什么更紧的记账 = 更少的噪声 = 更高的效用。
  6. 从零实现 DP-SGD(逐样本裁剪 + Gaussian 噪声 + Poisson 采样 + RDP 记账),说出噪声乘子 σ、采样率 q、步数 T、裁剪范数 C 各自控制什么,以及 DP 的代价为什么大约 ∝d/(nε)\propto \sqrt d/(n\varepsilon)。
  7. Use membership inference to audit a DP claim: empirical lower bounds on ε vs the theoretical upper bound, and what an audit can and cannot show.
  8. 用数字说明 DP 的代价不是平均分摊的(Bagdasaryan et al. 2019):少数群体为什么付出更多。

0.2 先修与本讲范围 Prerequisites & scope

默认你已经会 Assumed本讲省略或只预告 Omitted / previewed
第 1 讲 §5.4(loss-threshold MIA、advantage、噪声地板)、§7.2(隐私 vs 效用”先免费、后付费”)advanced composition、子采样 RDP 公式的完整证明(只讲思路,给出处)
第 9 讲:linkage、model inversion、shadow models(Shokri)、LiRA、为什么看低 FPR 下的 TPRf-DP / Gaussian DP 的完整理论;PLD / PRV 数值记账(§4.5 只介绍)
逻辑回归、SGD、per-example loss(第 1、4 讲)DP 合成数据、DP 的联邦学习、machine unlearning(第 9 讲提到)
概率:Laplace 与 Gaussian 分布、似然比、二项分布DP 训练大语言模型的工程细节(§5.6 只给方向)

第 9 讲展示了”模型会泄露什么”。本讲回答另一半:怎样给出一个对任何攻击都成立的保证,以及它的代价。第 1 讲 §7.2 已经说过结论的轮廓 —— DP 住在”付费区”:它保护每一条训练记录,包括那些泛化良好的模型也会记住的离群点,所以总要付出一些效用;换来的是”任何攻击都不会超过某个上界”,而不只是”这一个攻击失败了”。

0.3 本讲地图 Map

§1  为什么匿名化和"只发布统计量"不够:linkage、差分、重建攻击、2010 年人口普查     ← 代码 02 演示 1
§2  定义:相邻数据集、(ε, δ)、似然比、假设检验视角与 MIA 上界、DP 不承诺什么        ← 代码 04 演示 1
§3  机制:随机回答(local DP)、Laplace、Gaussian、指数机制、post-processing       ← 代码 01
§4  组合与记账:basic、advanced、Rényi DP、子采样放大、和已发表数字的对照          ← 代码 02 演示 2–3
§5  DP-SGD:算法、一步的解剖、代价 ∝ √d/(nε)、裁剪范数与批大小、哪些操作会悄悄破坏保证 ← 代码 03
§6  用成员推断审计 DP:HW4 的"先攻击再防御"、canary 审计、上界与下界                ← 代码 04 演示 2–3
§7  DP 的不成比例影响:少数群体为什么付出更多                                    ← 代码 05
§8  实践与联系:人口普查、Apple / Google、Netflix 推荐、PATE、隐私与解释、怎样报告 ε
§9–13 小结、误区、练习、延伸阅读、下一讲预告

0.4 Notation

符号含义
D,D′D, D'相邻数据集(neighboring):相差一条记录(增加或删除一条,add/remove;全讲统一用这个定义)
M\mathcal M随机化算法(机制,mechanism):输入数据集,输出一个随机的结果(一个数、一组数、一个模型)
ε,δ\varepsilon, \delta隐私参数:ε\varepsilon 越小越私密;δ\delta 是允许”失败”的概率,取得远小于 1/n1/n(本讲默认 δ=10−5\delta = 10^{-5})
Δ1,Δ2\Delta_1, \Delta_2L1 / L2 灵敏度(sensitivity):一条记录最多能让查询结果(向量)改变多少
μ=Δ/σ\mu = \Delta/\sigmaGaussian 机制的”信噪比”;两个相邻输出分布是相距 μ\mu 的两个标准正态
C,σ,q,T,BC, \sigma, q, T, BDP-SGD 的裁剪范数、噪声乘子(noise multiplier,噪声标准差 = σC\sigma C)、Poisson 采样率、步数、期望批大小 B=qnB = qn
α\alphaRényi 散度的阶(order);ε(α)\varepsilon(\alpha) 是 RDP 曲线
TPR, FPR成员推断攻击把成员判为成员、把非成员判为成员的比例;advantage = TPR − FPR
gapgroup 0 的值 − group 1 的值(同第 1、6 讲;第 5 讲用的是 group 1 − group 0)

0.5 关于数字 · About the numbers

所有实验数字都来自配套代码的实际输出(固定随机种子,同一台机器上重复运行逐字相同)。数据是第 1 讲的合成信贷世界:两个群体、真实还款概率已知、group 1 有 thin-file 效应。为了让很多实验能在几秒内跑完,DP-SGD 在逻辑回归上实现,并用矩阵并行训练几十到几千个模型(审计、LiRA、多种子平均都需要)。记账部分和已发表的数字对照过(§4.4)。数字只说明机制,不代表任何真实系统或真实人群。


1. 为什么”匿名化”和”只发布统计量”都不够 · Why the obvious fixes fail

1.1 Sanitize the database

The 2022 privacy lecture starts from the obvious approach: before releasing health records, census data or tracking logs, sanitize them — delete names, drop fields you don’t need, replace exact values by ranges, add a little noise. The slide’s verdict is blunt: “beware: these methods do not usually add much privacy”.

为什么?因为”能不能认出一个人”不取决于你删掉了什么,而取决于剩下的东西和外部信息合起来能不能定位到 TA:

  • Linkage:Latanya Sweeney 用公开的选民名册(邮编、性别、出生日期)把马萨诸塞州”已匿名”的州雇员病历和州长 William Weld 对上;她估计约 87% 的美国人可以被”5 位邮编 + 性别 + 出生日期”唯一识别。
  • Sparse, high-dimensional data:Narayanan & Shmatikov(2008)只用少量带噪声的、来自 IMDb 的公开评分,就在 Netflix Prize 的匿名数据里认出了用户 —— 稀有的属性恰恰最能区分人。

这些攻击的细节在第 9 讲。这里只需要一个教训:“匿名”不是数据集的性质,而是”数据集 + 攻击者知道的一切”的性质,而我们不知道攻击者知道什么。

1.2 只发布统计量也不行 · Aggregates leak too

那就不发布记录,只回答统计问题(interactive setting:分析者提问,可信的管理者 trusted curator 回答)?两个问题:

  1. 差分攻击(differencing):“数据库里有多少人患病 X?“和”除了 Bob 以外有多少人患病 X?“两个答案一减,就是 Bob 的病情。每个问题单独看都是”无害的聚合统计”。
  2. 重建攻击(reconstruction):即使每个回答都加了一点噪声,问题足够多时,噪声会被平均掉。Dinur & Nissim(2003)证明:如果每个回答的误差远小于 n\sqrt n,攻击者用多项式个随机子集的计数,就能用线性规划恢复几乎所有人的秘密比特。

代码 02 演示 1 在 100 个申请人上做了这件事。秘密比特是”近两年有没有逾期”(52% 的人有)。每个问题是”某个随机子集里有几个人有逾期?“,攻击者用最小二乘解出每个人的比特再四舍五入:

问题数 mσ = 1σ = 3σ = 10 = √nDP,总预算 ε = 1(Gaussian,精确组合)每次 σ
2000.9890.8090.6070.51052.8
4001.0000.9300.6510.50574.6
16001.0001.0000.8400.520149.2
64001.0001.0000.9810.528298.5

每个计数只差 ±1 人,看起来”很安全”,但 200 个问题后 98.9% 的比特被恢复。噪声大到 n\sqrt n,6400 个问题后也恢复了 98.1%。Dwork & Roth 把这叫作信息恢复的基本定律(Fundamental Law of Information Recovery):overly accurate answers to too many questions will destroy privacy。最后两列是解法的预告:如果总的隐私预算固定,问题越多每个回答的噪声越大(§4),同一个攻击就停在 0.51–0.53 附近 —— 和”不看任何回答、全猜多数值”的 0.52 一样。

1.3 一个真实的重建:2010 年美国人口普查 · The 2010 Census experiment

The US Census Bureau ran this attack on itself. Using only tables it had already published from the 2010 Census (about 6.2 billion statistics), it used linear programming to reconstruct a record (block, sex, age, race, ethnicity) for every resident of the 6.3 million inhabited blocks. By the Bureau’s figures, 46% of the population was reconstructed exactly; linking to commercial data produced putative re-identifications for 45%, of which 38% — 17% of the whole population — were confirmed correct. This was a main motivation for adopting differential privacy in 2020 (Abowd 2018).

The experiment was also criticized, and the criticism is a theme of this course — the noise floor. Ruggles & Van Riper (2022) argued that the Bureau never compared against a baseline that uses no data: random age–sex combinations plus each block’s most common race and ethnicity already match 40.9% of people, not far below 46%. 上面的表里,DP 列之所以要和”全猜多数值”的 0.52 比,是同一个道理。

1.4 我们到底想要什么 · What should “privacy” mean?

Dalenius(1977)提出过一个很自然的目标:访问统计数据库之后,关于任何个人,你不应该能学到”不访问就学不到”的东西。Dwork(2006)证明这在有辅助信息时不可能做到。她的例子(slides 里的 Terry Gross 讨论题):假设一个人的身高是敏感信息,而攻击者知道”Terry Gross 比立陶宛女性的平均身高矮 2 英寸”。那么一个完全正确、只关于群体的统计 —— 立陶宛女性的平均身高 —— 就泄露了 Terry Gross 的身高。而且不管 Terry Gross 在不在这个数据库里都会泄露。

这个例子决定了 DP 的设计:既然”什么都学不到”做不到(也不应该做到 —— 学到群体规律正是统计的意义),那就换一个可以做到的目标:比较”有你”和”没有你”两个世界。如果你的数据在不在数据库里,发布的结果几乎一样,那么你参与与否不会给你带来额外的风险。2022 年的 slide 用一句话概括:Released statistic stays about the same if any individual’s record is removed from the database.


2. 定义 · The definition

2.1 ε-DP

A randomized mechanism M\mathcal M is ε\varepsilon-differentially private if for every pair of neighboring datasets D,D′D, D' (differing in one record) and every set of outputs SS:

P[M(D)∈S]  ≤  eε P[M(D′)∈S].P[\mathcal M(D) \in S] \;\le\; e^{\varepsilon}\, P[\mathcal M(D') \in S].

Since neighbors are symmetric, the ratio is also bounded below by e−εe^{-\varepsilon}. For small ε, eε≈1+εe^\varepsilon \approx 1 + \varepsilon: no outcome becomes more than about (1+ε)(1+\varepsilon) times more or less likely because of any one person.

Each design choice has a reason:

  • Why a ratio, not a difference? A requirement like ∣P[M(D)∈S]−P[M(D′)∈S]∣≤1/n|P[\mathcal M(D) \in S] - P[\mathcal M(D') \in S]| \le 1/n is satisfied by “pick a random person and publish their whole record” (each person is published with probability only 1/n1/n) — and the person picked has no privacy at all. The ratio forces every outcome to become only slightly more likely for every person.
  • Why must the mechanism be randomized? A deterministic, non-constant algorithm has two datasets with different outputs; walk from one to the other changing one record at a time, and some neighboring pair must change the output. For that pair some outcome goes from probability 0 to 1, an infinite ratio.
  • Why “for all D,D′D, D'”? It is a worst-case guarantee: it holds for the most unusual person and the least favorable dataset, so it doesn’t depend on what the attacker knows (every other record may be known to them). This matters when we interpret experiments in §6.
  • DP is a property of the algorithm, not of an output. You cannot inspect a released number and check whether “it is DP”; you can only check the process that produced it.

2.2 (ε, δ)-DP

P[M(D)∈S]  ≤  eε P[M(D′)∈S]+δ.P[\mathcal M(D) \in S] \;\le\; e^{\varepsilon}\, P[\mathcal M(D') \in S] + \delta .

The additive δ\delta (Dwork, Kenthapadi, McSherry, Mironov & Naor 2006) allows the ratio bound to fail on events of probability at most δ. It is what makes the Gaussian mechanism (and therefore DP-SGD) possible. But δ must be much smaller than 1/n1/n: the “publish one random person’s record” mechanism above is essentially (0,1/n)(0, 1/n)-DP — perfect ε, catastrophic privacy. Typical choices are δ=10−5\delta = 10^{-5} for nn in the thousands to hundreds of thousands, and smaller for larger datasets — always δ≪1/n\delta \ll 1/n.

2.3 怎样理解 ε · Reading ε as odds

一个贝叶斯的读法:攻击者对”你在不在数据集里”有任何先验,看到输出之后,后验几率(odds)和先验几率之比被限制在 [e−ε,eε][e^{-\varepsilon}, e^{\varepsilon}] 之内(纯 ε-DP 时严格成立):

εeεe^\varepsilon含义
0.11.105几率最多变 10%:几乎什么都学不到
12.72先验 50% 的猜测,最多变成 73%
27.3950% → 最多 88%
454.650% → 最多 98%
82981几乎没有限制

这张表已经预告了 §6 的一个争论:机器学习里常见的 ε = 8,从这个角度看几乎不保证什么。

2.4 假设检验视角:DP 给成员推断的上界 · DP as a bound on any membership test

Now connect DP to the attacks of L9. A membership inference attacker sees the output (a released statistic, a trained model) and must decide between “the training set was DD” (you are not in it) and “it was D′D'” (you are). Any attack is a rejection region SS: guess “member” when the output lands in SS. Then FPR=P[M(D)∈S]\text{FPR} = P[\mathcal M(D) \in S] and TPR=P[M(D′)∈S]\text{TPR} = P[\mathcal M(D') \in S], and the DP inequality says exactly (Wasserman & Zhou 2010; Kairouz, Oh & Viswanath 2015):

TPR  ≤  eε FPR+δ,and, applied to the complement of S,1−FPR  ≤  eε(1−TPR)+δ.\text{TPR} \;\le\; e^{\varepsilon}\,\text{FPR} + \delta, \qquad\text{and, applied to the complement of } S,\qquad 1 - \text{FPR} \;\le\; e^{\varepsilon}(1 - \text{TPR}) + \delta .

两条直线围出一个”可行区域”,任何攻击的 (FPR, TPR) 都在里面。advantage = TPR − FPR 在两条直线的交点处最大。解交点:eεF+δ=1−e−ε(1−F−δ)e^\varepsilon F + \delta = 1 - e^{-\varepsilon}(1 - F - \delta),得 F∗=(1−δ)/(eε+1)F^* = (1-\delta)/(e^\varepsilon + 1),于是

advantage  ≤  eε−1+2δeε+1→  δ=0  tanh⁡(ε/2),balanced accuracy=1+advantage2≤eε1+eε  (δ=0).\text{advantage} \;\le\; \frac{e^{\varepsilon} - 1 + 2\delta}{e^{\varepsilon} + 1} \quad\xrightarrow{\;\delta = 0\;}\quad \tanh(\varepsilon/2), \qquad \text{balanced accuracy} = \frac{1 + \text{advantage}}{2} \le \frac{e^\varepsilon}{1 + e^\varepsilon}\;(\delta = 0).

(Yeom et al. 2018 给过一个更简单但更松的界 eε−1e^\varepsilon - 1;上面这个是紧的,下面的表会看到随机回答恰好达到它。)

Two readings matter for practice:

  • At low FPR the bound is a ratio. TPR≤eε⋅FPR+δ\text{TPR} \le e^\varepsilon \cdot \text{FPR} + \delta is precisely the “TPR at low FPR” metric that L9 argues is the right way to measure membership leakage. With ε = 1 and FPR = 1%, no attack can exceed TPR ≈ 2.7%.
  • The bound is over the worst-case individual and the worst-case pair of datasets. A real attacker usually doesn’t know all other records, and most records are not outliers — so real attacks typically land far below the bound (§6).

代码 04 演示 1 精确计算了上界,以及三个机制(都按同一个 ε 标定)实际能被攻击到什么程度:

εadvantage 上界随机回答LaplaceGaussian(δ = 1e-5)TPR@1% 上界LaplaceGaussian
0.50.2450.2450.2210.0570.01650.01650.0145
10.4620.4620.3930.1070.02720.02720.0198
20.7620.7620.6320.1980.07390.07390.0340
40.9640.9640.8650.3560.54600.54210.0805
80.9990.9990.9820.5950.99970.99160.2545
  • 随机回答(§3.1)恰好达到 advantage 上界:它是 ε-DP 里”最会泄露”的机制(Kairouz et al. 2015 证明它在这个意义上是极端的)。Laplace 在低 FPR 处恰好达到 TPR 上界(ε ≤ 2 时 TPR@1% 与上界完全相同):攻击者在分布的尾部看到的似然比正好是 eεe^\varepsilon。所以对纯 ε-DP,这个上界不是松的数学游戏,而是会被真的达到。
  • 按 (ε, δ) 标定的 Gaussian 远在上界之下:ε = 8 时 advantage 只有 0.595、TPR@1% 只有 0.2545。一对数字 (ε, δ) 只是 Gaussian 机制真实”隐私曲线”上的一个切点,丢掉了大量信息。f-DP / Gaussian DP(Dong, Roth & Su 2022)主张直接报告整条 trade-off 曲线:对 Gaussian 机制,最优检验的曲线恰好是 TPR=Φ(Φ−1(FPR)+μ)\text{TPR} = \Phi(\Phi^{-1}(\text{FPR}) + \mu)。

2.5 三个让 DP 好用的性质 · Properties that make DP composable

  1. Post-processing immunity. If M\mathcal M is (ε,δ)(\varepsilon, \delta)-DP, then f(M(D))f(\mathcal M(D)) is too, for any ff that doesn’t look at the data again. Rounding, clamping negative counts, fitting a model on DP statistics, publishing a plot — all free. This is why “DP model → any use of that model” is still DP.
  2. Group privacy. For datasets differing in kk records, an ε-DP mechanism gives kεk\varepsilon. 一个家庭、一个用户的很多条记录,保护会按人数线性变弱 —— 所以要想清楚”一条记录”指什么(§8.6 的 privacy unit)。
  3. Composition. Running several DP mechanisms on the same data is still DP, with the ε’s adding up (at worst). §4 is about doing this accounting tightly.

2.6 DP 不承诺什么 · No Free Lunch

DP 的承诺很精确,所以它不承诺的东西也很精确。课程阅读材料 Kifer & Machanavajjhala(2011)专门讨论这一点:

  • 从群体规律对你的推断。 Dwork & Roth 的例子:一项研究证明”吸烟致癌”,保险公司因此提高了吸烟者的保费。吸烟者 Bob 确实受到了伤害 —— 但这个伤害不管 Bob 在不在研究里都会发生。DP 保证的是”伤害不是因为你参与而产生的”。Terry Gross 的例子也是这一类。从群体规律学到东西是统计的目的;能不能用某个推断(比如按基因定保费)是法律和伦理问题,不是隐私算法能解决的。
  • 相关的记录。 “删掉一条记录”不等于”删掉一个人的影响”。Kifer & Machanavajjhala 的 No Free Lunch 定理说:不对数据如何产生做任何假设,就不可能同时得到隐私和效用;DP 的”有没有这条记录”语义隐含地假设记录之间(大致)独立。社交网络里,Bob 的存在会影响他朋友的记录;基因数据里,你的兄弟姐妹的记录泄露了你。这时 DP 对”Bob 参与与否”的保证要按 group privacy(§2.5)打折,或者改用 Pufferfish 这类明确建模相关性的框架。
  • 群体的隐私。 DP 保护个人,不保护群体。一个 DP 的模型完全可以准确地学到”某个邮编的人违约率高”—— 那正是它该学的。
  • 属性推断(model inversion)。 如果一个人的敏感属性和其他属性高度相关,一个准确的模型(无论是否 DP)就能用来推断它。Fredrikson et al.(2014)在华法林剂量模型上发现:DP 的 ε 要小到能阻止 model inversion 时,模拟的临床效果已经差到会增加中风和出血的风险。

Takeaway: DP answers one question very well — does my participation change what can be learned? — and is silent on what can be learned from everyone else.


3. 机制 · Mechanisms

所有机制都遵循同一个配方:先算出一个人最多能把答案改变多少(灵敏度),再加与之成比例、与 ε 成反比的随机性。

3.1 随机回答与 local DP · Randomized response

The oldest DP mechanism predates DP by 40 years (Warner 1965): to ask a sensitive yes/no question, let each respondent flip a coin and tell the truth with probability p=eε/(1+eε)p = e^\varepsilon/(1+e^\varepsilon), otherwise lie. Whatever the true answer, the probability of reporting “yes” changes by at most a factor p/(1−p)=eεp/(1-p) = e^\varepsilon — so each person’s report is ε-DP on its own. No trusted curator is needed: this is local DP (Kasiviswanathan et al. 2008). The population rate is still estimable, because the noise is known: π^=(λ^−(1−p))/(2p−1)\hat\pi = (\hat\lambda - (1 - p))/(2p - 1), where λ^\hat\lambda is the fraction of “yes”.

代码 01 演示 1:一万个申请人,敏感比特是”近两年有过逾期”(真实比例 0.548):

ε说真话概率 pP(有逾期 | 答”是”)RR 估计的 SDcentral Laplace 的 SD倍数
0.10.5250.5720.10250.0014173
0.50.6220.6660.02120.0002875
10.7310.7670.01010.0001472
20.8810.8990.00440.0000762
  • 可否认性(plausible deniability):ε = 1 时,一个回答”是”的人真有逾期的后验概率是 0.767(先验 0.548);ε = 0.1 时只有 0.572。收集者对每个人都没有把握。
  • 但群体比例照样估得出来:ε = 1 时标准差 0.0101。
  • 代价:同样的 ε,local DP 的误差是 central DP(可信的管理者先精确计数、再加一次 Laplace 噪声,§3.2)的约 72 倍。ε 小时 local 的误差 ≈1/(εn)\approx 1/(\varepsilon\sqrt n),central 的误差 ≈2/(εn)\approx \sqrt2/(\varepsilon n),比值 ≈n/2=71\approx\sqrt{n/2} = 71 —— 用户越多差距越大。这就是 local DP 只用于用户量极大的场景(§8.2)的原因。

3.2 Laplace 机制与灵敏度 · The Laplace mechanism

For a numeric query ff, the L1 sensitivity is Δ1=max⁡D,D′∥f(D)−f(D′)∥1\Delta_1 = \max_{D, D'} \lVert f(D) - f(D')\rVert_1 over neighboring datasets. The Laplace mechanism (Dwork, McSherry, Nissim & Smith 2006) releases

M(D)=f(D)+Lap(0, Δ1/ε),\mathcal M(D) = f(D) + \text{Lap}(0,\, \Delta_1/\varepsilon),

and is ε-DP: the Laplace density ∝e−∣z∣/b\propto e^{-|z|/b} changes by at most eΔ1/b=eεe^{\Delta_1/b} = e^\varepsilon when its center moves by Δ1\Delta_1. A count has Δ1=1\Delta_1 = 1, so the expected absolute error is 1/ε1/\varepsilon — independent of nn. That is why central DP is so much more accurate than local DP for large populations: the relative error of a count shrinks like 1/(εn)1/(\varepsilon n).

Slides 的讨论题问:“均值和最大值,哪个难私有化?“答案藏在灵敏度里:

  • 最大值:一个人就能把最大收入从 20 万改成 1000 万 —— 灵敏度没有上界。
  • 均值:也没有上界,除非先把每个人的值截断(clip)到 [0,B][0, B]。截断后,和的灵敏度是 BB,计数的灵敏度是 1;各用 ε/2 加 Laplace 噪声,再相除(除法是 post-processing)。

截断界 BB 是一个偏差–方差权衡。代码 01 演示 2(b),1000 个申请人的平均收入(真实 61.33k,最大 208.1k),ε = 1:

截断界 B(k$)被截断的比例截断带来的偏差噪声 SDRMSE
300.932−31.690.1231.68
800.212−4.540.284.55
2000.002−0.020.590.59
5000.0000.001.431.43
20000.0000.005.665.66

最好的 BB 只截断 0.2% 的人。截断界必须事先定好(领域知识或公开数据):如果取私有数据的最大值(208.1k),这个最大值本身就泄露了收入最高的那个人。§5 的梯度裁剪范数 CC 是完全相同的权衡。

3.3 Gaussian 机制 · The Gaussian mechanism

The Gaussian mechanism adds N(0,σ2I)\mathcal N(0, \sigma^2 I) calibrated to the L2 sensitivity Δ2\Delta_2. The textbook calibration σ=Δ22ln⁡(1.25/δ)/ε\sigma = \Delta_2\sqrt{2\ln(1.25/\delta)}/\varepsilon (Dwork & Roth 2014, Thm A.1) is only proven for ε < 1 and is conservative. Balle & Wang (2018) gave the exact condition: with μ=Δ2/σ\mu = \Delta_2/\sigma, the mechanism is (ε,δ)(\varepsilon, \delta)-DP iff

δ  ≥  Φ ⁣(−εμ+μ2)−eε Φ ⁣(−εμ−μ2).\delta \;\ge\; \Phi\!\left(-\frac{\varepsilon}{\mu} + \frac{\mu}{2}\right) - e^{\varepsilon}\,\Phi\!\left(-\frac{\varepsilon}{\mu} - \frac{\mu}{2}\right).

代码 01 演示 2(a)(计数查询,Δ = 1,δ = 1e-5):

εLaplace E|误差|Gaussian σ(经典公式)Gaussian σ(精确)Gaussian E|误差|
0.110.0048.4530.7524.53
0.52.009.697.035.61
11.00(不适用)3.732.98
40.25(不适用)1.080.86

对单个计数,Gaussian 比 Laplace 差(ε = 1 时误差 2.98 vs 1.00)。那为什么 DP-SGD 用 Gaussian?两个原因:

  1. 高维:一个 dd 维向量,每个坐标最多变 1,L1 灵敏度是 dd,L2 灵敏度只有 d\sqrt d。梯度的灵敏度天然是用 L2 范数裁剪出来的(§5)。
  2. 组合:Gaussian 机制组合起来仍然是 Gaussian 机制(kk 次 μ0\mu_0 的组合恰好是 μ0k\mu_0\sqrt k),记账可以做得非常紧(§4)。

3.4 指数机制 · The exponential mechanism

Some outputs aren’t numbers: which threshold, which category, which model. The exponential mechanism (McSherry & Talwar 2007) picks candidate rr with probability ∝exp⁡(ε u(D,r)/(2Δu))\propto \exp(\varepsilon\, u(D, r)/(2\Delta u)), where uu is a utility score and Δu\Delta u its sensitivity. 代码 01 演示 3 用它在 500 个私有申请人上选审批阈值(25 个候选,效用 = 做对的人数,Δu = 1;分数来自一个在公开数据上训练的模型):

εP(选中私有数据上最好的)期望私有准确率期望测试准确率
0.010.0430.7400.746
0.20.0930.7550.757
10.3010.7620.758
50.9170.7660.753
均匀乱选0.0400.7380.745

ε = 0.01 时它等于乱选;ε = 5 时几乎总选中私有数据上最好的阈值(0.325)。意外的一点:ε = 1 的测试准确率比 ε = 5 高。在 500 人上挑出的”最好”阈值过拟合了这 500 人(测试集上最好的是 0.500,准确率 0.770);指数机制的随机性让选择不那么依赖这 500 人的偶然性。这不是巧合:DP 限制了”一个人能影响多少结论”,所以 DP 的选择过程自带泛化保证(Dwork et al. 2015 的 adaptive data analysis / reusable holdout)—— 第 1 讲 §8.2 的赢家诅咒是它的反面。

3.5 Post-processing 是免费的 · Post-processing is free

代码 01 演示 2(c):一个真实值是 6 的小计数,用 ε = 0.5 的 Laplace 发布,有 2.3% 的输出是负数。把负数截到 0 再取整,RMSE 从 2.858 降到 2.725,不花任何隐私预算。但 post-processing 可以引入偏差:小格子会被系统性地往上推。2020 年人口普查的后处理(让所有计数是非负整数、上下级地理单元一致)正是因此受到批评(§8.1)。


4. 组合与记账 · Composition and privacy accounting

4.1 Basic composition and the privacy budget

If M1,…,Mk\mathcal M_1, \dots, \mathcal M_k are (εi,δi)(\varepsilon_i, \delta_i)-DP, running all of them is (∑εi,∑δi)(\sum\varepsilon_i, \sum\delta_i)-DP. This turns ε into a budget: decide a total once, then spend it across queries, training steps, hyperparameter searches. It is also why §1.2’s reconstruction attack fails under DP — with a fixed budget, each of mm answers gets only ε/m, and its noise grows with mm.

4.2 Advanced composition: √k instead of k

Basic composition is a worst case in which every step’s privacy loss lines up. The privacy loss of one output oo, L(o)=ln⁡P[M(D)=o]P[M(D′)=o]L(o) = \ln\frac{P[\mathcal M(D) = o]}{P[\mathcal M(D') = o]}, is a random variable with magnitude at most ε0\varepsilon_0 and mean at most ε0(eε0−1)≈ε02\varepsilon_0(e^{\varepsilon_0} - 1) \approx \varepsilon_0^2; summed over kk independent steps it concentrates, deviating from its mean by about k ε0\sqrt k\,\varepsilon_0. Allowing a failure probability δ′ gives (Dwork, Rothblum & Vadhan 2010)

εtotal=2kln⁡(1/δ′) ε0+kε0(eε0−1),δtotal=kδ0+δ′.\varepsilon_{\text{total}} = \sqrt{2k\ln(1/\delta')}\,\varepsilon_0 + k\varepsilon_0(e^{\varepsilon_0} - 1), \qquad \delta_{\text{total}} = k\delta_0 + \delta'.

4.3 Rényi DP 与 moments accountant

Advanced composition works for any mechanism and ignores the shape of the noise. Rényi DP (Mironov 2017) tracks a whole curve instead of one number: M\mathcal M is (α,ε(α))(\alpha, \varepsilon(\alpha))-RDP if the Rényi divergence Dα(M(D) ∥ M(D′))≤ε(α)D_\alpha(\mathcal M(D)\,\Vert\,\mathcal M(D')) \le \varepsilon(\alpha) for all neighbors. Three facts make it the workhorse of DP-SGD:

  1. For the Gaussian mechanism, ε(α)=αμ2/2\varepsilon(\alpha) = \alpha\mu^2/2 — exact and simple.
  2. Composition adds the curves: kk steps give k ε(α)k\,\varepsilon(\alpha) at every α.
  3. Convert once at the end: ε=min⁡α[ε(α)+ln⁡(1/δ)/(α−1)]\varepsilon = \min_\alpha\big[\varepsilon(\alpha) + \ln(1/\delta)/(\alpha - 1)\big] (classic, Mironov 2017), or the tighter min⁡α[ε(α)+ln⁡α−1α−ln⁡δ+ln⁡αα−1]\min_\alpha\big[\varepsilon(\alpha) + \ln\frac{\alpha-1}{\alpha} - \frac{\ln\delta + \ln\alpha}{\alpha - 1}\big] (Balle et al. 2020). This code uses the tighter one by default.

Abadi et al.’s (2016) moments accountant is the same idea expressed through the moment generating function of the privacy loss; it was later absorbed into the RDP framework.

代码 02 演示 2 用一个有精确答案的例子检查各种记账有多松:同一个 Gaussian 机制(μ0=0.01\mu_0 = 0.01,即 σ = 100Δ,单次几乎不泄露)用 kk 次。精确答案来自 Gaussian DP 的组合定理:kk 次组合恰好是 μ0k\mu_0\sqrt k 的 Gaussian 机制。

kbasicadvancedRDP精确 exactbasic / 精确RDP / 精确
100.340.340.110.103.51.11
1003.932.190.380.3411.51.10
100044.299.281.311.2036.91.09
10000488.6650.604.754.38111.61.09

反过来,给 kk 个问题分总预算 (ε = 1, δ = 1e-5),每个回答需要的 σ(以灵敏度为单位):

kbasicadvancedRDP精确 exact
100362.0201.640.537.3
1000036190.52259.6404.5373.1
  • basic 的 ε 随 kk 线性增长;advanced、RDP、精确值都随 k\sqrt k 增长。
  • advanced 在 k≤10k \le 10 时没有帮助,k=104k = 10^4 时仍比精确值差 10 倍以上。RDP 只比精确值多 9%–11%(k=1k = 1 时 19%)。
  • 同样的隐私,记账越紧,可以加的噪声越少,效用越高:同样是 10000 个问题、ε = 1,basic 要求 σ = 36190.5,RDP 只要 404.5。记账方法改变的是我们能证明的 ε,不改变算法本身。

4.4 子采样放大 · Privacy amplification by subsampling

DP-SGD doesn’t touch all the data at each step: each record enters a step’s batch independently with probability qq (Poisson sampling). If you are not in the batch, the step reveals nothing about you — and the attacker doesn’t even know whether you were. For the subsampled Gaussian mechanism with noise multiplier σ, the outputs with and without you are N(0,σ2)\mathcal N(0, \sigma^2) and the mixture (1−q)N(0,σ2)+q N(1,σ2)(1-q)\mathcal N(0, \sigma^2) + q\,\mathcal N(1, \sigma^2) (in units of CC). For integer α the RDP has a closed form (Mironov, Talwar & Zhang 2019):

ε(α)=1α−1ln⁡∑k=0α(αk)(1−q)α−kqkexp⁡ ⁣(k2−k2σ2),\varepsilon(\alpha) = \frac{1}{\alpha - 1}\ln \sum_{k=0}^{\alpha}\binom{\alpha}{k}(1-q)^{\alpha-k}q^{k}\exp\!\left(\frac{k^2 - k}{2\sigma^2}\right),

roughly q2q^2 times smaller than without subsampling for small qq. dp_tools.py implements it in log space and checks it against numerical integration (agreement to 6 decimals). 代码 02 演示 3(σ = 1,δ = 1e-5):

qT = 1T = 100T = 1000010 个 epoch 后(T = 10/q)
14.75110.1310010.1319.80
0.12.137.97180.507.97
0.010.961.226.722.11
0.0010.610.640.790.79

不子采样时 10000 步后 ε 超过一万(毫无保护);q = 0.01 时只有 6.72。单步的放大没那么夸张(4.75 → 0.96),子采样的威力在很多步组合之后才显现。

和已发表的数字对照(用 classic 换算,和这些论文一致):

来源qσT发表的 ε本模块 classic本模块 improved
Abadi et al. 2016 的例子0.014.0100001.261.261.04
Bu et al. 2020,MNIST 15 epochs256/600001.335161.191.190.95
Bu et al. 2020,MNIST 60 epochs256/600001.1140633.013.012.60
Bu et al. 2020,MNIST 45 epochs256/600000.7105477.107.126.37
Bu et al. 2020,MNIST 62 epochs256/600000.61453213.2714.0613.10

ε ≤ 7 的几行与发表值相差 ≤ 0.02。ε 更大时我们偏大几个百分点:那里最优的 Rényi 阶小于 2,而本模块只用整数阶(仍然是合法的上界,只是不够紧;练习见代码 README)。同一个 Abadi 的例子,strong composition 给出 ε ≈ 9.34 —— 这正是 moments accountant 被提出的动机。

4.5 比 RDP 更紧 · Beyond RDP

RDP’s conversion to (ε, δ) is itself slightly loose: 02 demo 2 at k=104k = 10^4 and demo 3 at q=1,T=1q = 1, T = 1 are both a single μ=1\mu = 1 Gaussian mechanism in disguise, and RDP reports 4.75 where the exact answer is 4.38. Modern accountants compute the privacy loss distribution numerically — PLD via FFT (Koskela, Jälkö & Honkela 2020) or the PRV accountant (Gopi, Lee & Wutschitz 2021) — and get within a hair of the exact (ε, δ). Opacus and TF Privacy ship such accountants. The lesson of §4 is unchanged: an accountant is part of the algorithm; a looser one forces you to add more noise for the same promise.


5. DP-SGD

5.1 The algorithm, and why each piece

Earlier private ERM work (Song, Chaudhuri & Sarwate 2013; Bassily, Smith & Thakurta 2014) established noisy gradient descent; Abadi et al. (2016) made it practical for deep networks with the moments accountant. One step:

1. Poisson sampling      每条记录独立地以概率 q 进入这一批
2. per-example gradient  gᵢ = ∇θ ℓ(θ; xᵢ, yᵢ)
3. per-example clipping  ḡᵢ = gᵢ · min(1, C / ‖gᵢ‖)
4. noisy sum             G = Σᵢ ḡᵢ + N(0, σ²C² I)
5. step                  θ ← θ − η · G / B          (B = q·n 是事先固定的期望批大小)
accounting               (q, σ, T) → ε at δ        (§4.4 的 RDP 记账)

每一步都有不可省略的理由:

  • 逐样本裁剪(第 3 步):DP 需要灵敏度。梯度本身没有上界(离群点的梯度可以任意大);裁剪后,有没有某个人,加和最多差 CC —— L2 灵敏度 = CC。必须逐样本裁剪:裁剪整个批的平均梯度,限制不了单个人的影响。
  • 噪声 ∝ C(第 4 步):所以 σ 是一个和 CC 无关的”相对噪声”。隐私只由 (q,σ,T)(q, \sigma, T) 决定,和 CC、学习率、模型结构都无关。
  • 除以固定的 BB(第 5 步):如果除以这一批实际的人数,分母本身就依赖”这个人在不在”,灵敏度分析就失效了。(§6.2 会看到一个真实的 bug 正出在类似的地方。)
  • Poisson 采样(第 1 步):记账公式假设的就是它。

逻辑回归的 per-example 梯度是 (pi−yi) ai(p_i - y_i)\,a_i,范数就是 ∣pi−yi∣⋅∥ai∥|p_i - y_i|\cdot\lVert a_i\rVert,所以 train_dpsgd 里的裁剪只是给每个残差乘一个系数;再把 M 个模型的参数放成矩阵的 M 列,一次矩阵乘法训练所有模型。

5.2 一步里发生了什么 · Anatomy of one step

代码 03 演示 1 在两个设置上取一步 DP-SGD(ε = 1,C = 1,期望批大小 50,训练 20 个 epoch 所需的 σ),比较信号(裁剪后梯度和 / B)和噪声(σCd/B\sigma C\sqrt d/B),以及加噪后的更新和”全数据、不裁剪的真梯度”的余弦(θ∗\theta^* 是非私有最优解):

设置dσ被裁剪‖信号‖/B‖噪声‖/Bcos(更新, 真梯度)
linear, n = 4000, θ = 062.190.670.2700.1070.821
linear, n = 4000, θ = θ*/262.190.310.1610.1070.607
cubic, n = 500, θ = 0565.890.960.2340.8810.182
cubic, n = 500, θ = θ*/2565.890.530.1610.8810.133

Same ε, same batch size, completely different situations. The noise norm σCd/B\sigma C\sqrt d / B hurts the cubic model three ways: d\sqrt d is 3× larger; with 8× less data, the same number of epochs needs an 8× larger sampling rate, and the accountant then demands a larger σ (5.89 vs 2.19); and the signal is bounded by CC per example. Signal grows with BB; noise doesn’t. That one sentence explains §5.3 and §5.4.

5.3 隐私的代价 · The cost of privacy ∝ √d / (nε)

代码 03 演示 2(测试准确率,5 个种子的均值 ± 标准差;批大小 50,20 个 epoch,C = 1):

设置Newton(非私有)不加噪声ε = 8ε = 2ε = 1ε = 0.5
linear, n = 40000.7660.766 ± 0.0010.765 ± 0.0010.766 ± 0.0010.765 ± 0.0010.763 ± 0.003
linear, n = 5000.7590.758 ± 0.0020.757 ± 0.0020.756 ± 0.0040.753 ± 0.0040.745 ± 0.009
cubic, n = 40000.7650.765 ± 0.0010.764 ± 0.0010.762 ± 0.0030.755 ± 0.0020.742 ± 0.007
cubic, n = 5000.7370.747 ± 0.0010.748 ± 0.0020.737 ± 0.0040.720 ± 0.0130.666 ± 0.028
  • 6 个参数、4000 人:DP 几乎免费,ε = 0.5 时只掉 0.003。
  • 56 个参数、500 人:ε = 0.5 时掉到 0.666,而且种子之间波动很大。DP 学习的误差理论上大约 ∝d/(nε)\propto \sqrt d/(n\varepsilon)(Bassily, Smith & Thakurta 2014 一类的结果),表格就是这个形状。
  • 基线要选对:cubic, n = 500 这一行,Newton(几乎不正则化,过拟合)只有 0.737,而”同样的裁剪 SGD、不加噪声”是 0.747,ε = 8 是 0.748。这不说明 DP 噪声提高了准确率 —— 20 个 epoch 的裁剪 SGD 本身就是正则化。衡量 DP 的代价,要和”同样的训练流程、不加噪声”比。

Tramèr & Boneh (2021) put the practical consequence in their title: differentially private learning needs better features (or much more data). Fewer parameters to learn from private data — e.g., via public pre-training — is the most effective lever.

5.4 超参数:C 与批大小 · Clipping norm and batch size

裁剪范数 C。 The update is ηC (∑igˉi/C+N(0,σ2I))/B\eta C\,(\sum_i \bar g_i/C + \mathcal N(0, \sigma^2 I))/B, so ηC\eta C sets the step size and CC by itself only decides who gets clipped. Holding ηC=0.5\eta C = 0.5 fixed isolates that effect(代码 03 演示 3,cubic,n = 500,10 个种子):

C不加噪声:acclog lossε = 2:acclog loss被裁剪
0.010.7451.4430.7401.5470.57
0.10.7481.0480.7431.1540.49
10.7480.6930.7380.8260.34
30.7470.5650.7280.7290.13
300.7490.5280.6600.8170.00

C 太大是灾难:没人被裁剪,信号 ∑gi\sum g_i 远小于 BCBC,噪声却仍是 σC\sigma C(ε = 2 时 0.660)。C 很小时准确率最好,但每个样本都被裁成长度 CC、“一人一票”地推动模型,不管它是否已经被拟合好 —— 概率被推向极端,log loss 变差(1.547)。所以 C 要按你在乎的指标选:准确率偏好小 C(大规模 DP 训练的经验也是”C 小一点、学习率相应放大”,De et al. 2022),概率的质量(校准,第 13 讲)偏好让大多数样本不被裁剪的 C。

批大小。 代码 03 演示 4(ε = 1,cubic,n = 500):

qB(a) 固定 20 个 epoch:Tσ/Bacc(b) 固定 400 步:σ/Bacc
0.01520000.3960.6710.2440.681
0.05254000.1680.6990.1680.696
0.21001000.0830.7300.1630.695
0.5250400.0520.7450.1620.707
  • (a) 同样的计算量(epoch 数):批越大越好(0.671 → 0.745)。批大小翻倍,记账要求的 σ 只增加约 1.4 倍,于是”噪声 / 批大小”下降。
  • (b) 同样的步数:q ≥ 0.05 时 σ/B 几乎相同(0.162–0.168),准确率也几乎相同。固定步数时,效果主要由 σ/B 决定(Sander, Stock & Sablayrolles 2023 称之为 total amount of noise)。实用含义:用小批便宜地调其他超参数,再把 B 和 σ 按比例放大。
  • 和 §4.4 对照:从记账看,同样的 epoch 数,小批(多步)ε 更小;从效用看,同样的 ε,大批更好。DP-SGD 调参就是在这两者之间找平衡(Ponomareva et al. 2023 的 “How to DP-fy ML” 有系统的指南)。

5.5 会悄悄破坏保证的操作 · Things that silently void the guarantee

The ε printed by the accountant only covers what the accountant modeled. Common gaps:

  • 用私有数据做预处理:用训练集的均值 / 标准差标准化、用训练集的最大值定截断界。本讲的 PublicScaler 用一份公开样本;也可以用领域知识,或者单独花一点预算。
  • 在私有数据上调超参数:每试一组 (C, η, σ, epoch) 都在读数据。只给最后一个模型记账,整体就不是 DP 的(Papernot & Steinke 2022 给出了把调参也纳入 RDP 记账的方法)。01 演示 3 的指数机制就是”私有地选择”的一个例子。
  • 采样方式不符:记账假设 Poisson 采样,很多实现却是”打乱后按顺序切批”。Chua et al.(2024)指出两者的隐私可能差很多。
  • “只发布最终模型”:标准分析假设攻击者看到每一步的带噪梯度。只发布最终模型时真实的泄露通常更小(凸问题上有 privacy amplification by iteration,Feldman et al. 2018),但一般情况下没有更好的证明 —— §6 的审计会测这个差距。
  • privacy unit:一条记录 ≠ 一个人。同一个用户有很多条记录时,example-level 的 ε 要按 group privacy 打折;需要 user-level DP(每个用户的所有数据一起裁剪,McMahan et al. 2018)。

5.6 深度网络上的 DP-SGD · On deep networks

The algorithm is identical; what changes is engineering. Per-example gradients are not a by-product of standard backprop, so libraries compute them with vectorized maps (torch.func.vmap over torch.func.grad), hooks (Opacus), or tricks like ghost clipping that get per-example norms without materializing per-example gradients. The empirical picture: training from scratch under DP is expensive in accuracy, but public pre-training + private fine-tuning works remarkably well — on images with very large batches and careful tuning (De et al. 2022) and on language models (Li, Tramèr, Liang & Hashimoto 2022; Yu et al. 2022). This is the deep-learning version of §5.3: reduce what must be learned from private data.


6. 用成员推断审计 DP · Auditing DP with membership inference

6.1 HW4:先攻击,再防御 · Attack, then defend

HW4 asks you to mount Shokri’s shadow-model attack and then evaluate a DP-based defense. 代码 04 演示 2 是同一个流程的缩小版:第 1 讲 §5.4 那个会过拟合的三次模型;一个 300 人的数据池,训练 128 个模型,每个模型用随机的一半(约 150 人),每个模型轮流当攻击目标、其余当 shadow models。两种攻击:全局 loss 阈值(第 1 讲 §5.4;对二分类模型,Shokri 的按类别攻击模型的输入只有 p(y∣x)p(y \mid x) 一个数,学到的通常就是一个阈值),和逐样本建模的 LiRA(Carlini et al. 2022,第 9 讲)。DP-SGD:q = 0.2,T = 500,C = 1,δ = 1e-5。

模型traintestloss: advloss: TPR@1%LiRA: AUCLiRA: TPR@1%LiRA: [email protected]%DP 上界 TPR@1%
Newton, λ = 1e-4(第 1 讲的过拟合模型)0.9270.6780.2610.0090.6800.0670.0101—
Newton, λ = 1e-20.8640.7370.1320.0090.6790.0680.0191—
SGD,裁剪、不加噪声0.8650.7370.1480.0090.6750.0570.0124—
DP-SGD, ε = 80.8270.7110.1140.0100.6000.0180.00211.000
DP-SGD, ε = 40.7780.6820.0960.0110.5630.0120.00050.546
DP-SGD, ε = 20.7230.6560.0680.0100.5320.0110.00070.074
DP-SGD, ε = 10.6650.6140.0490.0100.5100.0080.00100.027
噪声地板(打乱成员标签)0.0060.0090.4950.0090.0013

Four lessons:

  1. Measure with the strongest attack, at low FPR. On the overfit model, the loss attack’s advantage (0.261) looks alarming, but its TPR@1% (0.009) equals the noise floor — it cannot confidently identify anyone. LiRA reaches 0.067, seven times the floor.
  2. Regularization is not privacy. λ = 1e-2 and clipped SGD generalize better (test 0.737) and halve the loss attack’s advantage, yet LiRA’s TPR@1% barely moves (0.068, 0.057).
  3. DP works, at a price. LiRA’s TPR@1% falls to 0.018 at ε = 8 and is indistinguishable from the floor at ε ≤ 2; test accuracy falls from 0.737 to 0.711, 0.682, 0.656, 0.614.
  4. Empirical leakage sits far below the bound. At ε = 2 the bound allows TPR@1% = 0.074; LiRA gets 0.011. At ε = 8 the bound is vacuous (1.000), yet LiRA’s TPR@1% has already dropped from 0.067 to 0.018. The bound is for the worst-case record and an attacker who sees every training step; our attacker sees only the final model and targets ordinary records.

第 4 点就是”ε = 8 够不够”争论的核心。支持者说:实际攻击远达不到上界,ε = 8 已经挡住了现有最强的攻击。批评者说:你得到的保护来自攻击者不够强,不是来自证明;明天出现更强的攻击,或者有人专门针对离群点,保证就只剩那个空洞的上界。两种说法都对,所以报告 ε 时应该同时说明它是在什么假设下的(§8.6)。

6.2 审计:从攻击推出 ε 的下界 · Auditing: a lower bound on ε

Turn §2.4 around. If some attack achieves FPR and FNR on a pair of neighboring datasets, then (ε, δ)-DP requires FPR+eε FNR≥1−δ\text{FPR} + e^\varepsilon\,\text{FNR} \ge 1 - \delta (and the same with FPR and FNR swapped), hence

ε  ≥  ln⁡1−δ−FPRFNR.\varepsilon \;\ge\; \ln\frac{1 - \delta - \text{FPR}}{\text{FNR}} .

Jagielski, Ullman & Oprea (2020) made this an audit: insert a canary (a record chosen to be as detectable as possible), train many models with and without it, estimate FPR and FNR, and plug in their Clopper–Pearson upper confidence bounds so the resulting ε lower bound holds with 95% confidence. The threshold is chosen on half the trials and evaluated on the other half (otherwise “pick the best threshold” inflates the result — L1 §8.2 again).

代码 04 演示 3:150 人的基础训练集 + 1 个 canary(收入 250k、负债率 0.05、信用历史 25 年、零逾期 —— 却违约了),每边训练 1000 次(共 2000 个模型),超参数同 §6.1。两种攻击者:black-box 只看最终模型对 canary 的 logit;white-box 是 DP-SGD 分析所假设的最强对手(Nasr et al. 2021):能在一个没有别人使用的方向上放一个梯度 canary,并看到每一步的带噪梯度,用逐步的精确似然比打分。

训练方式理论 ε(上界)black-box 下界(每边 1000)white-box(每边 1000)white-box(每边 20000)
裁剪 SGD,不加噪声∞4.91——
DP-SGD81.852.274.09
DP-SGD40.930.901.84
DP-SGD20.270.130.93
DP-SGD10.000.000.34
  • 试验次数给审计设了天花板。 不加噪声时攻击完美(FPR = FNR = 0),下界却只有 4.91 —— 每边 500 次评估试验最多只能证明这么多:0 次失败也只能说明失败率”大概不超过 3.7/500”。每边 10000 次评估试验的天花板是 7.90。
  • 下界远低于上界。 20000 次试验的 white-box 攻击者大约到达理论值的一半。原因有二:δ = 1e-5 描述的是十万分之一量级的罕见事件,几万次试验看不到;RDP 换算出的 ε 本身也略大于真实值(§4.3)。Nasr et al.(2021)用更多试验和这类最强对手证明:在它假设的威胁模型下,DP-SGD 的分析(几乎)是紧的;随着对手能力变弱(只看最终模型、只能插入自然样本),下界迅速下降。
  • 这里 black-box 和同样试验次数的 white-box 差不多(1.85 vs 2.27):线性模型的最终参数几乎就是所有带噪更新的和,而这个极端 canary 的方向上没有别人。对深度网络,只看最终模型通常弱得多。

What an audit can and cannot do. It can find bugs: Tramèr et al. (2022) audited an open-source DP training method that claimed ε = 0.21 and certified ε > 2.79; the cause was a per-layer sensitivity mistakenly divided by the batch size, so the noise was too small by that factor. It cannot prove privacy: a low lower bound only means this attack and this many trials were not enough. Proofs come only from upper bounds. Auditing has become much cheaper since — e.g., with many canaries in a single training run (Steinke, Nasr & Jagielski 2023).


7. DP 的代价落在谁身上 · Disparate impact

Bagdasaryan, Poursaeed & Shmatikov (2019) trained DP-SGD models on tasks with under-represented groups (e.g., face attributes across skin tones, sentiment of different English dialects, species with few examples) and found that accuracy drops most for groups that were already doing worst — “the poor get poorer”. 第 1 讲 §7.4 引用过这个结论;代码 05 用第 1 讲的世界把它做出来。

设定:1000 个训练样本,少数群体 group 1 只占 10%(92 人);模型可以看群体(group 截距 + group × history 交互项),所以它有能力学到 thin-file 效应。20 个种子并行训练取平均,测试集 40000 人。

训练方式acc g0acc g1Δacc g0Δacc g1TPR gap
SGD,不裁剪、不加噪声0.7860.734——+0.141
裁剪 C = 1、不加噪声0.7880.733−0.0020.002+0.151
DP-SGD, ε = 40.7880.730−0.0020.005+0.161
DP-SGD, ε = 20.7870.726−0.0010.008+0.166
DP-SGD, ε = 10.7860.723−0.0000.012+0.142
DP-SGD, ε = 0.50.7820.7040.0040.031+0.160

多数群体几乎不受影响;少数群体一路下降,ε = 0.5 时下降是多数群体的 8.5 倍(group 1 的标准误 ±0.001–0.008,远小于这些差别)。但 TPR gap 在 +0.141 到 +0.166 之间摆动,没有清楚的趋势:在这个世界里,不成比例的影响表现为少数群体的准确率下降,而不是某一个公平指标的系统性恶化。“DP 会让公平指标变差多少”要具体测,不能想当然。

Two mechanisms (code 05 demo 2):

  1. Clipping. The minority is fit worse (mean loss 0.527 vs 0.456), so its gradients are larger (mean norm 1.004 vs 0.688) and get clipped more often at C = 1 (0.408 vs 0.248). In the summed gradient, their pull on the model is weakened more than everyone else’s. In this linear model, clipping alone barely moves accuracy (second row above), but it does change what is learned (the history coefficient goes from +0.60 to +0.96).
  2. Noise. DP-SGD adds the same amount of noise to every parameter, but each parameter’s signal comes from different people. The history weight is supported by all 1000 people and has a seed-to-seed standard deviation of 0.33 at ε = 0.5; the group intercept and the group × history interaction are supported only by the 92 group-1 members, with standard deviations of 1.07 and 0.89 — about three times larger. Minority-specific parameters drown first, and the model’s predictions for them become “the majority pattern plus a lot of noise”.

对照(代码 05 演示 3,ε = 0.5 时 group 1 与 group 0 的准确率下降之比):少数群体占 10% 且模型看群体:7.9(用新的噪声重跑演示 1 的配置);占 30%:2.1;占 10% 但模型不看群体:2.6。群体越小、它的模式越需要专门的参数,DP 的代价越集中在它身上;不看群体也躲不开。

这和 memorization 的理论一致:Feldman(2020)论证,对长尾分布,学好稀有的子群体需要记住个别样本 —— 而 DP 恰恰禁止记住个别样本。缓解方法(按群体自适应裁剪,如 Xu, Du & Wu 2021;分析裁剪造成的梯度方向偏差,Esipova et al. 2023;更多少数群体数据;更好的特征)都有代价,而且按群体调整需要群体标签 —— 收集它本身又是隐私问题(第 1 讲 §7.4 的”fairness → privacy”)。


8. 实践与联系 · DP in practice, and connections

8.1 2020 年美国人口普查 · The 2020 US Census

The Census Bureau’s TopDown Algorithm adds noise to counts at the national level, then state, county, tract, block group and block, and post-processes everything into non-negative integers that are consistent across levels (Abowd et al. 2022). Its accounting was done in zero-concentrated DP; for the 2020 redistricting data the Bureau announced a total of ε = 19.61 (17.14 for the persons file, 2.47 for housing units). The debate it sparked is a good summary of this lecture: demographers worried about accuracy for small areas and about biases introduced by the post-processing (§3.5); privacy researchers pointed out that a large ε is still a quantified, composable promise that the previous swapping-based methods never offered; the National Academies’ 2023 assessment noted that how much protection such large parameter values actually deliver is hard to know.

8.2 Local DP in industry

Google’s RAPPOR (Erlingsson, Pihur & Korolova 2014) collected statistics from Chrome users with randomized response; Apple’s on-device DP (2017) collects emoji, new words and other usage statistics. Apple’s documentation listed per-donation budgets such as ε = 4 for emoji (one donation per day) and ε = 8 for QuickType (two per day). Tang et al. (2017) reverse-engineered the macOS implementation and pointed out that budgets reset daily, so the total loss grows with the number of days. Both lessons are already in §3.1 and §4.1: local DP needs huge user counts, and a per-day ε is not a total ε.

8.3 课程阅读:DP 推荐系统 · McSherry & Mironov 2009

为什么 2022 年的课程选这篇?它示范了”怎样把一个真实的 ML 系统改造成 DP 的”。思路是把算法拆成两部分:

  1. 聚合 / 学习阶段(DP):只从所有用户的数据里学习低灵敏度的聚合量 —— 全局效应(各电影的平均分)和电影–电影的协方差矩阵,并做了精心的加噪与降噪处理;
  2. 个人推荐阶段(不需要 DP 记账):把学到的聚合量和某个用户自己的评分结合,给 TA 做推荐。这一步只影响 TA 自己。

他们把 Netflix Prize 的几个领先方法(kNN、SVD 类因子分解)改造成这样,报告说准确率下降不大,并且仍然优于 Netflix 自己的 Cinematch 基线。一个需要注意的细节:后来的工作指出,这篇论文的保证是在”单条评分”的层面,比”一个用户的全部评分”的层面弱得多 —— 又是 §5.5 的 privacy unit 问题。

8.4 Private prediction 与 PATE

Sometimes you don’t need to release a model at all — only its predictions. PATE (Papernot, Abadi, Erlingsson, Goodfellow & Talwar 2017) trains an ensemble of “teachers” on disjoint partitions of the private data; each query is answered by a noisy vote of the teachers (one person affects only one teacher, so the vote count has sensitivity 1); a “student” model is trained on public unlabeled data labeled by these noisy votes, and only the student is released. Privacy is spent only on the queries the student needs, and when teachers agree strongly the data-dependent cost is small. More generally, private prediction (Dwork & Feldman 2018) asks for DP at the level of each answered query.

8.5 隐私与解释 · Privacy meets explanations (Week 9)

2022 年第 9 周讨论了隐私和可解释性的联系,三条线:

  • 解释会泄露成员身份。 Shokri, Strobel & Zick(2021)发现,基于梯度的解释(第 3 讲)可以被用来做成员推断和重建训练数据:解释给了攻击者模型在这个点附近的局部信息。DP 的模型 + post-processing 意味着由它算出的任何解释也是 DP 的;Patel, Shokri & Zick(2022)研究了直接给解释加 DP 的方法。
  • 影响与记忆(第 4 讲)。 训练数据归因问的正是”去掉一个样本,模型变多少”—— 而 DP 恰好限制这个量对训练结果分布的影响。例如 Feldman(2020)定义的 memorization(包含与不包含某个样本时,模型在它上面答对的概率之差)在 (ε, δ)-DP 下不超过 eε−1+δe^\varepsilon - 1 + \delta。这和”DP 抵御成员推断”是同一件事的两面;第 4 讲 §10.4 说过,自影响大的样本最容易被成员推断认出。
  • DP ⇒ 泛化。 “去掉一个人,结论几乎不变”是一种稳定性,稳定性推出泛化。Dwork et al.(2015)用它解决了”在同一个 holdout 集上反复调整”(adaptive data analysis)的问题;01 演示 3 的指数机制在测试集上反而更好,是同一个现象的小例子。

8.6 怎样选 ε、怎样报告 · Choosing and reporting ε

There is no universal ε. Rough conventions: ε ≤ 1 is a strong guarantee; ε in the single digits is common in ML deployments; double digits are hard to interpret (§2.3). More important than the number is what it refers to. A useful DP report (Ponomareva et al. 2023 propose a checklist) states:

要报告的例子
privacy unit一条训练样本?一个用户的全部数据?(§5.5)
(ε, δ) 和 δ 相对于 n 的大小ε = 2,δ = 1e-5,n = 60000
记账方法RDP、PLD;整数阶还是分数阶;采样方式是否和记账假设一致
覆盖了哪些计算预处理?超参数搜索?还是只有最后一次训练?
威胁模型假设攻击者看到所有中间步骤还是只看最终模型
审计结果(如果有)用什么攻击、多少次试验、得到的下界

9. 小结 · Summary

概念一句话本讲的数字
为什么需要 DP匿名化挡不住 linkage;统计量挡不住差分和重建±1 的噪声,200 个问题后泄露 98.9% 的比特
定义有没有你,任何结果的概率最多变 eεe^\varepsilon 倍(再加 δ)—
MIA 上界TPR ≤ eεe^\varepsilon·FPR + δ;advantage ≤ (eε−1+2δ)/(eε+1)(e^\varepsilon - 1 + 2\delta)/(e^\varepsilon + 1)ε = 1:advantage ≤ 0.462,TPR@1% ≤ 0.0272
机制噪声 ∝ 灵敏度 / ε;求和要先截断local DP 的误差是 central 的约 72 倍
记账basic 线性,advanced / RDP √k;记账越紧噪声越少k = 10⁴:488.66 / 50.60 / 4.75,精确 4.38
子采样每步只用一小部分数据,ε 大幅缩小σ = 1、10⁴ 步:q = 1 时 10010,q = 0.01 时 6.72
DP-SGD逐样本裁剪 + Gaussian 噪声 + Poisson 采样 + RDP代价 ∝ √d/(nε):cubic、500 人、ε = 0.5 时 0.666
审计攻击给下界,证明给上界20000 次试验的 white-box 到达理论值的约一半
不成比例的影响小群体、需要专门参数的模式先被噪声淹没ε = 0.5:少数群体的准确率下降是多数的 8.5 倍

Six takeaways:

  1. Privacy is a property of the release process, not of the data. Removing names, releasing only aggregates, adding “a little noise” — none of these bound what an attacker with side information can learn.
  2. DP compares two worlds, with you and without you. It cannot stop inferences from population-level facts, and it weakens with correlated records and multi-record users (No Free Lunch).
  3. ε is a bound on every membership test, and it is attained by real mechanisms (randomized response, Laplace). (ε, δ) compresses a whole trade-off curve into two numbers.
  4. Accounting is part of the algorithm. RDP and subsampling turn hopeless budgets into usable ones; a looser accountant means more noise for the same promise.
  5. DP-SGD’s cost grows with the number of parameters and shrinks with data and batch size; clipping norm and batch size are privacy hyperparameters, and tuning them on private data costs privacy too.
  6. Empirical attacks and audits complement, but never replace, the proof. And the cost of privacy is not shared equally: small groups pay more.

10. 常见误区 · Common pitfalls

  • “We removed names and IDs, so the data are anonymous.” Quasi-identifiers and sparse attributes re-identify people (§1.1; L9).
  • “We only publish aggregate statistics.” Differencing and reconstruction attacks recover individuals from enough aggregates (§1.2–1.3).
  • “We add noise, so it’s DP.” DP is about noise calibrated to sensitivity and accounted across all releases. Fixed noise on unlimited queries is not DP (02 demo 1).
  • “Our model is DP with ε = 8, so membership inference is impossible.” At ε = 8 the bound is vacuous (TPR@1% ≤ 1.000); the protection you observe comes from weak attackers (§6.1).
  • “Our MIA audit found ε ≥ 0.3, so the model is about ε = 0.3-private.” An audit gives a lower bound; it can find bugs but not prove privacy (§6.2).
  • “We standardized with the training set and tuned on it — but training was DP.” The preprocessing and tuning also read private data (§5.5).
  • “DP protects people from any harm caused by the analysis.” It protects against harm caused by participation; population-level inferences (smoking causes cancer) are untouched (§2.6).
  • “DP costs 1% accuracy on average, so it’s fair.” The cost concentrates on small groups (§7).
  • “Clipping alone gives privacy.” Clipping bounds sensitivity; without noise there is no guarantee — the un-noised clipped model was perfectly distinguishable in the audit (04 demo 3).

11. 练习 · Exercises

练习 1(随机回答达到上界). 随机回答以概率 p=eε/(1+eε)p = e^\varepsilon/(1+e^\varepsilon) 说真话。(a) 证明它是 ε-DP 的。(b) 一个攻击者看到某人的回答,猜”TA 的真实比特 = 回答”。在”真实比特各占一半”的先验下,这个攻击的 TPR、FPR 和 advantage 是多少?(c) 和 §2.4 的上界 tanh⁡(ε/2)\tanh(\varepsilon/2) 比较,并解释为什么任何 ε-DP 机制的 advantage 都不能更大。

参考答案

(a) 只有两种输出。对输出”1”:真实比特为 1 时概率 pp,为 0 时 1−p1-p,比值 p/(1−p)=eεp/(1-p) = e^\varepsilon;输出”0”同理。所有输出集合的概率比都 ≤ eεe^\varepsilon。(b) 把”真实比特 = 1”看作”成员”:TPR = pp,FPR = 1−p1 - p,advantage = 2p−1=(eε−1)/(eε+1)=tanh⁡(ε/2)2p - 1 = (e^\varepsilon - 1)/(e^\varepsilon + 1) = \tanh(\varepsilon/2)。(c) 恰好等于上界。上界来自两个约束 TPR ≤ eεe^\varepsilonFPR、1 − FPR ≤ eεe^\varepsilon(1 − TPR) 的交点;随机回答的 (FPR, TPR) = (1−p,p)(1-p, p) 代入两个约束都取等号,正好落在交点上。04 演示 1 的表格里 RR 一列和上界一列逐位相同。

练习 2(截断界与灵敏度). 你要私有地发布 1000 个人的平均收入,打算用”截断到 [0,B][0, B],和与人数各用 ε/2 的 Laplace”。(a) 和的灵敏度为什么是 BB?如果相邻数据集的定义是”替换一条记录”(人数不变),灵敏度是多少?(b) 一个同事建议”用数据里的最大收入作为 BB,这样就没有截断偏差了”。这为什么破坏了 DP?给出一个具体的泄露场景。(c) 01 演示 2(b) 里 B = 2000k 时噪声 SD 是 5.66,B = 200k 时是 0.59。为什么大约是 10 倍?

参考答案

(a) 增加或删除一个人,截断后的和最多变化 BB(那个人的值在 [0,B][0, B] 内)。替换一条记录时,和最多变化 BB(从 0 换成 BB),灵敏度仍然是 BB;但人数不变,可以把 nn 当作公开常数,直接发布”和 / n”,灵敏度是 B/nB/n,不用再给人数加噪声。(b) BB 本身由数据决定:如果有一个人的收入是 1000 万,BB 就是 1000 万,发布的噪声尺度直接暴露了”数据库里有一个收入 1000 万的人”;有没有这个人,噪声的分布完全不同,比值无界。(c) 均值的噪声主要来自”和”的 Laplace 噪声,尺度 B/(ε/2)B/(\varepsilon/2),再除以 nn,所以和 BB 成正比:BB 大 10 倍,噪声大约大 10 倍(5.66 / 0.59 ≈ 9.6;人数的噪声和截断偏差造成了一点偏离)。

练习 3(组合定理的量级). 一个 Gaussian 机制,μ0=0.01\mu_0 = 0.01,组合 k=104k = 10^4 次,δ = 1e-5。(a) 用 Gaussian DP 的组合定理说明精确的 ε 等于单个 μ=1\mu = 1 的 Gaussian 机制的 ε。(b) 用 RDP:ε(α)=kαμ02/2=α/2\varepsilon(\alpha) = k\alpha\mu_0^2/2 = \alpha/2,classic 换算 ε=min⁡α[α/2+ln⁡(105)/(α−1)]\varepsilon = \min_\alpha[\alpha/2 + \ln(10^5)/(\alpha - 1)]。对 α 求导,估计最优 α 和 ε。(c) 02 演示 2 的表格里 RDP 给出 4.75(improved 换算)、精确 4.38。你的 (b) 是多少?为什么比 4.75 大?

参考答案

(a) kk 次 μ0\mu_0-GDP 的组合是 μ0k\mu_0\sqrt k-GDP,0.01×100=10.01 \times 100 = 1。(b) 令 f(α)=α/2+L/(α−1)f(\alpha) = \alpha/2 + L/(\alpha - 1),L=ln⁡105≈11.51L = \ln 10^5 \approx 11.51。f′(α)=1/2−L/(α−1)2=0f'(\alpha) = 1/2 - L/(\alpha-1)^2 = 0 ⇒ α−1=2L≈4.80\alpha - 1 = \sqrt{2L} \approx 4.80,α≈5.8\alpha \approx 5.8。f≈5.8/2+11.51/4.80≈2.90+2.40=5.30f \approx 5.8/2 + 11.51/4.80 \approx 2.90 + 2.40 = 5.30(取整数阶 α = 6 时 3+11.51/5=5.303 + 11.51/5 = 5.30)。(c) 5.30 比 4.75 大,因为 classic 换算比 improved 松:improved 多了 ln⁡((α−1)/α)−ln⁡(α)/(α−1)\ln((\alpha-1)/\alpha) - \ln(\alpha)/(\alpha - 1) 这两项负的修正。两者都是精确值 4.38 的上界。

练习 4(DP-SGD 的实现错误). 下面是三个 DP-SGD 的”实现”。对每一个,说明它是否仍然满足记账给出的 (ε, δ),如果不满足,错在哪里:(a) 先算整批的平均梯度,再把平均梯度裁剪到 CC,加 N(0,σ2C2I)\mathcal N(0, \sigma^2C^2 I);(b) 逐样本裁剪、加噪声,但除以这一批实际的样本数;(c) 逐样本裁剪到 CC,加 N(0,σ2I)\mathcal N(0, \sigma^2 I)(忘了乘 CC),且 C=10C = 10。

参考答案

(a) 不满足。裁剪平均梯度只限制了”整批”的梯度范数,一个人对平均梯度的影响可以占满整个 CC(如果其他人的梯度互相抵消),而加和的灵敏度分析需要每个人的贡献 ≤ CC。Tramèr et al. 2022 报告的 bug 和 Nasr et al. 2023 讨论的”先聚合后裁剪”都属于这一类。(b) 严格说不满足标准分析:分母依赖于”这个人在不在批里”,输出不再是”灵敏度 CC 的和 + 噪声”的 post-processing。实践中影响往往不大,但记账的证明不再适用;正确做法是除以事先固定的 B=qnB = qn。(c) 不满足:噪声标准差是 σ\sigma 而不是 σC=10σ\sigma C = 10\sigma,相当于噪声乘子只有 σ/10\sigma/10。记账应该用 σ/10\sigma/10 重新算 ε,会大得多。

练习 5(读懂审计的天花板). 一次审计每边做了 NN 次评估试验,攻击完美(0 个 FP、0 个 FN)。(a) Clopper–Pearson 95%(双侧)给出的 FPR 上界约为 1−0.0251/N≈3.7/N1 - 0.025^{1/N} \approx 3.7/N。推出这次审计能证明的最大 ε(δ ≈ 0)。(b) 代入 N=500N = 500 和 N=10000N = 10000,和 04 演示 3 的 4.91、7.90 比较。(c) 要证明 ε ≥ 8,大约需要多少次试验?这对”用审计证明一个模型不私密”意味着什么?

参考答案

(a) ε ≥ ln((1 − FPR_u)/FNR_u) ≈ ln(1/(3.7/N)) = ln(N/3.7)。(b) N = 500:ln(135) ≈ 4.91;N = 10000:ln(2703) ≈ 7.90。和代码完全一致。(c) 需要 N/3.7≥e8≈2981N/3.7 \ge e^8 \approx 2981,即 N ≥ 约 11000 次每边的评估试验(加上选阈值的那一半,总共要训练约 44000 个模型)。审计的统计功效随试验次数只按 ln N 增长:要证明大的 ε,需要指数多的训练。这也是”一次训练、很多 canary”的审计方法(Steinke et al. 2023)被提出的原因。

练习 6(隐私预算的设计题). 一家银行想用 DP 发布三样东西:(i) 每个邮编的违约率(50 个邮编),(ii) 一个用 DP-SGD 训练的信用评分模型,(iii) 模型的超参数(从 20 组里选最好的)。总预算 ε = 3,δ = 1e-5。(a) 如何在三者之间分配预算?说明你的理由。(b) 每个邮编的违约率用什么机制、灵敏度是多少?哪些邮编的结果会不可靠?(c) 选超参数这一步,有哪两种做法(参考 01 演示 3 和 §5.5)?(d) 如果一个客户在银行有 5 笔贷款(5 条记录),TA 得到的保证是什么?

参考答案

一种合理的答案:(a) 用 basic composition 分配(或用 RDP 统一记账更紧):模型最重要,给 2.0;邮编统计 0.7;超参数选择 0.3。理由:模型参数最多(§5.3 的代价 ∝ √d),统计量是 50 个低灵敏度的计数,选择只需要从 20 个里挑一个。(b) 一个人只属于一个邮编,所以 50 个邮编的”违约人数”向量的 L1 灵敏度是 1(parallel composition:不相交的子集上各用 ε 也只花 ε)。违约人数和总人数各用 0.35 的预算,即各加 Laplace(1/0.35) 噪声,比例 = 两者相除(post-processing);人数少的邮编(比如 < 30 人)比例的误差会很大,应该合并或标注不可靠。(c) 一种是指数机制 / report-noisy-max,以验证集上的准确率为效用(灵敏度 1/n_val);另一种是把整个调参过程纳入 RDP 记账(Papernot & Steinke 2022),例如随机次数的重复训练。最差的做法是在私有数据上随便调、只给最终模型记账。(d) example-level 的保证按 group privacy 变成大约 5ε = 15,几乎没有意义;应该把 privacy unit 定为”客户”,把一个客户的所有记录一起裁剪(user-level DP)。

代码相关的练习(“动手改一改”)见 code/lecture10/README.md。


12. 延伸阅读 · Further reading

课程阅读材料(Spring 2022 Week 8)

  • Dwork, “Differential Privacy”, ICALP 2006 —— 定义、Dalenius 目标不可能实现的证明、Terry Gross 的例子。
  • Dwork, “Differential Privacy: A Survey of Results”, TAMC 2008。
  • McSherry & Mironov, “Differentially Private Recommender Systems: Building Privacy into the Netflix Prize Contenders”, KDD 2009。
  • Kifer & Machanavajjhala, “No Free Lunch in Data Privacy”, SIGMOD 2011;后续的 Pufferfish 框架(TODS 2014)。

基础

  • Dwork, McSherry, Nissim & Smith, “Calibrating Noise to Sensitivity in Private Data Analysis”, TCC 2006;Dwork, Kenthapadi, McSherry, Mironov & Naor, “Our Data, Ourselves”, Eurocrypt 2006((ε, δ))。
  • Dwork & Roth, The Algorithmic Foundations of Differential Privacy, 2014(免费在线;本讲的大部分定理都在里面)。
  • Dinur & Nissim, “Revealing Information while Preserving Privacy”, PODS 2003;Warner, “Randomized Response”, JASA 1965;McSherry & Talwar, “Mechanism Design via Differential Privacy”, FOCS 2007。
  • Wasserman & Zhou, JASA 2010;Kairouz, Oh & Viswanath, “The Composition Theorem for Differential Privacy”, ICML 2015(假设检验视角)。
  • Dong, Roth & Su, “Gaussian Differential Privacy”, JRSS-B 2022;Balle & Wang, “Improving the Gaussian Mechanism”, ICML 2018。

记账与 DP-SGD

  • Abadi et al., “Deep Learning with Differential Privacy”, CCS 2016;Mironov, “Rényi Differential Privacy”, CSF 2017;Mironov, Talwar & Zhang, “Rényi Differential Privacy of the Sampled Gaussian Mechanism”, 2019;Balle et al., “Hypothesis Testing Interpretations and Rényi Differential Privacy”, AISTATS 2020。
  • Bu, Dong, Long & Su, “Deep Learning with Gaussian Differential Privacy”, HDSR 2020;Gopi, Lee & Wutschitz, “Numerical Composition of Differential Privacy”, NeurIPS 2021。
  • Tramèr & Boneh, “Differentially Private Learning Needs Better Features (or Much More Data)”, ICLR 2021;De et al., “Unlocking High-Accuracy Differentially Private Image Classification through Scale”, 2022;Li, Tramèr, Liang & Hashimoto, “Large Language Models Can Be Strong Differentially Private Learners”, ICLR 2022。
  • Ponomareva et al., “How to DP-fy ML: A Practical Guide to Machine Learning with Differential Privacy”, JAIR 2023;Papernot & Steinke, “Hyperparameter Tuning with Rényi Differential Privacy”, ICLR 2022;Sander, Stock & Sablayrolles, “TAN Without a Burn”, ICML 2023。

审计与攻击

  • Jagielski, Ullman & Oprea, “Auditing Differentially Private Machine Learning: How Private is Private SGD?”, NeurIPS 2020;Nasr, Song, Thakurta, Papernot & Carlini, “Adversary Instantiation: Lower Bounds for Differentially Private Machine Learning”, IEEE S&P 2021;Tramèr et al., “Debugging Differential Privacy: A Case Study for Privacy Auditing”, 2022;Steinke, Nasr & Jagielski, “Privacy Auditing with One (1) Training Run”, NeurIPS 2023。
  • Carlini et al., “Membership Inference Attacks From First Principles”, IEEE S&P 2022(LiRA,第 9 讲);Yeom et al., CSF 2018。

公平、实践与联系

  • Bagdasaryan, Poursaeed & Shmatikov, “Differential Privacy Has Disparate Impact on Model Accuracy”, NeurIPS 2019;Feldman, “Does Learning Require Memorization? A Short Tale about a Long Tail”, STOC 2020;Esipova et al., “Disparate Impact in Differential Privacy from Gradient Misalignment”, ICLR 2023。
  • Abowd et al., “The 2020 Census Disclosure Avoidance System TopDown Algorithm”, HDSR 2022;Ruggles & Van Riper, “The Role of Chance in the Census Bureau Database Reconstruction Experiment”, 2022;National Academies, Assessing the 2020 Census: Final Report, 2023。
  • Erlingsson, Pihur & Korolova, “RAPPOR”, CCS 2014;Apple Differential Privacy Team, “Learning with Privacy at Scale”, 2017;Tang et al., “Privacy Loss in Apple’s Implementation of Differential Privacy on MacOS 10.12”, 2017。
  • Papernot et al., “Semi-supervised Knowledge Transfer for Deep Learning from Private Training Data”(PATE), ICLR 2017;Dwork & Feldman, “Privacy-preserving Prediction”, COLT 2018。
  • Shokri, Strobel & Zick, “On the Privacy Risks of Model Explanations”, AIES 2021;Patel, Shokri & Zick, “Model Explanations with Differential Privacy”, FAccT 2022;Dwork et al., “The Reusable Holdout”, Science 2015。

13. 下一讲预告 · Next lecture

Lecture 11:评估 LLM 应用 —— RAG triad 与 LLM-as-a-judge(Evaluating LLM Applications)。

第 2–10 讲研究的是模型:一个从特征到标签的函数,有标准答案,可以精确地问”它依赖什么、对谁不公平、在什么扰动下失败、泄露了什么”。从第 11 讲开始,被信任的对象变成应用:基础模型 + prompt + 检索到的上下文,输出是开放式的文本,常常没有标准答案。我们会看到 RAG 的三条边(context relevance、groundedness、answer relevance)怎样把”这个回答对不对”拆成可以分别检查的问题,以及当评估者本身是另一个 LLM 时,怎样验证它、修正它的偏差 —— 第 1 讲 §8.3 的”谁来评估评估者”会被展开。本讲的一个想法会以新的形式回来:一个漂亮的分数可能来自评估方法的弱点,而不是系统真的好(这里是”攻击者不够强”,那里是”judge 有偏差”)。

← 返回课程目录