Update logbook: Reproduction: Adaptive Personalized Federated Learning via Multi-task Averaging of Kernel Mean Embeddings
Browse files- README.md +14 -5
- bucket-icon.svg +5 -0
- index.html +82 -17
- logbook.css +2142 -0
- logbook.js +0 -0
- logbook.json +87 -0
- pages/claim-1-theorem-4-4-finite-sample-kme-guarantee/page.md +22 -0
- pages/claim-2-corollary-4-6-downstream-excess-risk-transfer/page.md +22 -0
- pages/claim-3-example-4-5-automatic-adaptive-collaboration/page.md +22 -0
- pages/claim-4-theorem-5-2-random-fourier-feature-tradeoff/page.md +302 -0
- pages/claim-5-section-6-1-100-agent-synthetic-concept-shift/page.md +1310 -0
- pages/claim-6-section-6-3-femnist-192-agent-benchmark/page.md +298 -0
- pages/conclusion/page.md +19 -0
- pages/executive-summary/page.md +0 -0
- pages/index.md +16 -0
- trackio-logo-light.png +0 -0
- trackio-logo.png +0 -0
- trackio-wordmark-dark.png +0 -0
- workspace.json +29 -0
README.md
CHANGED
|
@@ -1,10 +1,19 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: "Reproduction: Adaptive Personalized Federated Learning via Multi-task Averaging of Kernel Mean Embeddings"
|
| 3 |
+
emoji: 🎯
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: red
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- trackio
|
| 10 |
+
- trackio-logbook
|
| 11 |
+
- open-experiment
|
| 12 |
+
- icml2026-repro
|
| 13 |
+
- paper-ADHGbxsREr
|
| 14 |
+
- arxiv:2603.02233
|
| 15 |
---
|
| 16 |
|
| 17 |
+
# Reproduction: Adaptive Personalized Federated Learning via Multi-task Averaging of Kernel Mean Embeddings
|
| 18 |
+
|
| 19 |
+
An open experiment logbook, published with [Trackio](https://github.com/gradio-app/trackio).
|
bucket-icon.svg
ADDED
|
|
index.html
CHANGED
|
@@ -1,19 +1,84 @@
|
|
| 1 |
<!doctype html>
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
+
<title>Reproduction: Adaptive Personalized Federated Learning via Multi-task Averaging of Kernel Mean Embeddings</title>
|
| 7 |
+
<link rel="stylesheet" href="./logbook.css" />
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<div id="app">
|
| 11 |
+
<aside id="sidebar">
|
| 12 |
+
<div id="book-head">
|
| 13 |
+
<img id="book-wordmark" src="./trackio-wordmark-dark.png" alt="" />
|
| 14 |
+
<div id="book-title" class="sr-only">Logbook</div>
|
| 15 |
+
</div>
|
| 16 |
+
<nav id="tree"></nav>
|
| 17 |
+
<div id="sidebar-foot" hidden>
|
| 18 |
+
<button id="connect-btn" type="button">
|
| 19 |
+
<span class="ico">ⓘ</span> Collaborate with your agent
|
| 20 |
+
</button>
|
| 21 |
+
</div>
|
| 22 |
+
</aside>
|
| 23 |
+
<main id="content">
|
| 24 |
+
<nav id="view-tabs" aria-label="Logbook views">
|
| 25 |
+
<a data-view="code" href="#/view/code/index">
|
| 26 |
+
<svg viewBox="0 0 24 24" aria-hidden="true">
|
| 27 |
+
<path d="m18 16 4-4-4-4" />
|
| 28 |
+
<path d="m6 8-4 4 4 4" />
|
| 29 |
+
<path d="m14.5 4-5 16" />
|
| 30 |
+
</svg>
|
| 31 |
+
<span>Logbook</span>
|
| 32 |
+
</a>
|
| 33 |
+
<a data-view="trace" href="#/view/trace">
|
| 34 |
+
<svg viewBox="0 0 24 24" aria-hidden="true">
|
| 35 |
+
<path d="M8 5h13" />
|
| 36 |
+
<path d="M13 12h8" />
|
| 37 |
+
<path d="M13 19h8" />
|
| 38 |
+
<path d="M3 10a2 2 0 0 0 2 2h3" />
|
| 39 |
+
<path d="M3 5v12a2 2 0 0 0 2 2h3" />
|
| 40 |
+
</svg>
|
| 41 |
+
<span>Traces</span>
|
| 42 |
+
</a>
|
| 43 |
+
<a data-view="workspace" href="#/view/workspace">
|
| 44 |
+
<svg viewBox="0 0 24 24" aria-hidden="true">
|
| 45 |
+
<path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" />
|
| 46 |
+
</svg>
|
| 47 |
+
<span>Workspace</span>
|
| 48 |
+
</a>
|
| 49 |
+
</nav>
|
| 50 |
+
<header id="logbook-header">
|
| 51 |
+
<h1 id="logbook-title"></h1>
|
| 52 |
+
<div id="logbook-cli"></div>
|
| 53 |
+
</header>
|
| 54 |
+
<div id="page"></div>
|
| 55 |
+
</main>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
<div id="modal" hidden>
|
| 59 |
+
<div class="modal-backdrop"></div>
|
| 60 |
+
<div class="modal-card" role="dialog" aria-modal="true">
|
| 61 |
+
<div class="modal-head">
|
| 62 |
+
<div class="modal-title">
|
| 63 |
+
<img class="modal-logo" src="./trackio-logo.png" alt="" />
|
| 64 |
+
Collaborate with your agent
|
| 65 |
+
</div>
|
| 66 |
+
<div class="modal-actions">
|
| 67 |
+
<button id="copy-agent" class="btn">Copy for agent</button>
|
| 68 |
+
<button id="modal-close" class="btn icon" aria-label="Close">×</button>
|
| 69 |
+
</div>
|
| 70 |
+
</div>
|
| 71 |
+
<div class="modal-body">
|
| 72 |
+
<p class="modal-intro">
|
| 73 |
+
Point your coding agent at this logbook. It reads a compact,
|
| 74 |
+
token-efficient version — and if you've given it write access to this
|
| 75 |
+
Space, it can add findings that sync back automatically.
|
| 76 |
+
</p>
|
| 77 |
+
<ol id="connect-steps"></ol>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
<script src="./logbook.js"></script>
|
| 83 |
+
</body>
|
| 84 |
</html>
|
logbook.css
ADDED
|
@@ -0,0 +1,2142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root {
|
| 2 |
+
--bg: #ffffff;
|
| 3 |
+
--paper: #ffffff;
|
| 4 |
+
--panel: #ffffff;
|
| 5 |
+
--ink: #1f2937;
|
| 6 |
+
--muted: #6b7280;
|
| 7 |
+
--line: #e5e7eb;
|
| 8 |
+
--accent: #f97316;
|
| 9 |
+
--accent-strong: #ea580c;
|
| 10 |
+
--accent-soft: #fff7ed;
|
| 11 |
+
--accent-line: rgba(249, 115, 22, 0.16);
|
| 12 |
+
--grid-line: rgba(31, 41, 55, 0.02);
|
| 13 |
+
--code-bg: #f3f4f6;
|
| 14 |
+
--radius: 12px;
|
| 15 |
+
--sidebar-width: 280px;
|
| 16 |
+
--content-gutter: 40px;
|
| 17 |
+
--serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
|
| 18 |
+
--sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
|
| 19 |
+
sans-serif;
|
| 20 |
+
--mono: "SFMono-Regular", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas,
|
| 21 |
+
ui-monospace, monospace;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
* {
|
| 25 |
+
box-sizing: border-box;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
html,
|
| 29 |
+
body {
|
| 30 |
+
margin: 0;
|
| 31 |
+
padding: 0;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
html {
|
| 35 |
+
scroll-behavior: smooth;
|
| 36 |
+
scrollbar-gutter: stable;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
body {
|
| 40 |
+
background: var(--bg);
|
| 41 |
+
color: var(--ink);
|
| 42 |
+
font-family: var(--sans);
|
| 43 |
+
font-size: 13px;
|
| 44 |
+
line-height: 1.65;
|
| 45 |
+
-webkit-font-smoothing: antialiased;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
#app {
|
| 49 |
+
display: flex;
|
| 50 |
+
min-height: 100vh;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
body[data-view="trace"] #sidebar-foot,
|
| 54 |
+
body[data-view="workspace"] #sidebar-foot {
|
| 55 |
+
display: none;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* ---- sidebar (composition-book cover) ---- */
|
| 59 |
+
#sidebar {
|
| 60 |
+
width: var(--sidebar-width);
|
| 61 |
+
flex: 0 0 var(--sidebar-width);
|
| 62 |
+
background: #17181c;
|
| 63 |
+
color: #e7e7ea;
|
| 64 |
+
position: sticky;
|
| 65 |
+
top: 0;
|
| 66 |
+
height: 100vh;
|
| 67 |
+
overflow-y: auto;
|
| 68 |
+
padding: 22px 16px;
|
| 69 |
+
display: flex;
|
| 70 |
+
flex-direction: column;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
#book-head {
|
| 74 |
+
display: flex;
|
| 75 |
+
align-items: center;
|
| 76 |
+
gap: 10px;
|
| 77 |
+
padding: 8px;
|
| 78 |
+
margin-bottom: 12px;
|
| 79 |
+
border-radius: 10px;
|
| 80 |
+
cursor: pointer;
|
| 81 |
+
transition: background 0.12s;
|
| 82 |
+
}
|
| 83 |
+
#book-head:hover {
|
| 84 |
+
background: rgba(255, 255, 255, 0.05);
|
| 85 |
+
}
|
| 86 |
+
#book-wordmark {
|
| 87 |
+
width: 154px;
|
| 88 |
+
height: auto;
|
| 89 |
+
object-fit: contain;
|
| 90 |
+
}
|
| 91 |
+
.sr-only {
|
| 92 |
+
position: absolute;
|
| 93 |
+
width: 1px;
|
| 94 |
+
height: 1px;
|
| 95 |
+
padding: 0;
|
| 96 |
+
margin: -1px;
|
| 97 |
+
overflow: hidden;
|
| 98 |
+
clip: rect(0, 0, 0, 0);
|
| 99 |
+
white-space: nowrap;
|
| 100 |
+
border: 0;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
#tree {
|
| 104 |
+
flex: 1;
|
| 105 |
+
padding-top: 8px;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
#tree .tree-label {
|
| 109 |
+
padding: 6px 10px 8px;
|
| 110 |
+
color: #777a83;
|
| 111 |
+
font-size: 10px;
|
| 112 |
+
font-weight: 700;
|
| 113 |
+
letter-spacing: 0.12em;
|
| 114 |
+
text-transform: uppercase;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
#tree a {
|
| 118 |
+
display: block;
|
| 119 |
+
padding: 6px 10px;
|
| 120 |
+
border-radius: 8px;
|
| 121 |
+
color: #c3c4cb;
|
| 122 |
+
text-decoration: none;
|
| 123 |
+
font-size: 14px;
|
| 124 |
+
transition: background 0.12s, color 0.12s;
|
| 125 |
+
overflow: hidden;
|
| 126 |
+
text-overflow: ellipsis;
|
| 127 |
+
white-space: nowrap;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
#tree a:hover {
|
| 131 |
+
background: rgba(255, 255, 255, 0.06);
|
| 132 |
+
color: #ffffff;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
#tree a.active {
|
| 136 |
+
background: rgba(249, 115, 22, 0.16);
|
| 137 |
+
color: #fdba74;
|
| 138 |
+
font-weight: 600;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
#tree a .tree-mark {
|
| 142 |
+
color: #6b6d76;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
#tree a:hover .tree-mark,
|
| 146 |
+
#tree a.active .tree-mark {
|
| 147 |
+
color: inherit;
|
| 148 |
+
opacity: 0.6;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
#tree .depth-1 {
|
| 152 |
+
padding-left: 22px;
|
| 153 |
+
}
|
| 154 |
+
#tree .depth-2 {
|
| 155 |
+
padding-left: 34px;
|
| 156 |
+
}
|
| 157 |
+
#tree .depth-3 {
|
| 158 |
+
padding-left: 46px;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
/* ---- content ---- */
|
| 163 |
+
#content {
|
| 164 |
+
flex: 1;
|
| 165 |
+
min-width: 0;
|
| 166 |
+
padding: 24px
|
| 167 |
+
clamp(
|
| 168 |
+
var(--content-gutter),
|
| 169 |
+
calc(100vw - 960px),
|
| 170 |
+
calc(var(--sidebar-width) + var(--content-gutter))
|
| 171 |
+
)
|
| 172 |
+
120px var(--content-gutter);
|
| 173 |
+
background-color: var(--paper);
|
| 174 |
+
background-image:
|
| 175 |
+
linear-gradient(var(--grid-line) 1px, transparent 1px),
|
| 176 |
+
linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
|
| 177 |
+
background-size: 26px 26px;
|
| 178 |
+
background-position: center top;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
#logbook-header {
|
| 182 |
+
width: 100%;
|
| 183 |
+
max-width: 1080px;
|
| 184 |
+
margin: 0 auto 20px;
|
| 185 |
+
}
|
| 186 |
+
#logbook-title {
|
| 187 |
+
font-family: var(--serif);
|
| 188 |
+
font-size: 34px;
|
| 189 |
+
line-height: 1.15;
|
| 190 |
+
letter-spacing: -0.02em;
|
| 191 |
+
margin: 0 0 10px;
|
| 192 |
+
overflow-wrap: anywhere;
|
| 193 |
+
}
|
| 194 |
+
#logbook-cli {
|
| 195 |
+
display: grid;
|
| 196 |
+
gap: 7px;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
#page {
|
| 200 |
+
width: 100%;
|
| 201 |
+
min-width: 0;
|
| 202 |
+
max-width: 1080px;
|
| 203 |
+
margin: 0 auto;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.page-section {
|
| 207 |
+
scroll-margin-top: 40px;
|
| 208 |
+
padding: 0 0 35px;
|
| 209 |
+
margin: 0 0 32px;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
.page-section:last-child {
|
| 213 |
+
margin-bottom: 0;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
.page-layout {
|
| 217 |
+
display: block;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
.page-body {
|
| 221 |
+
min-width: 0;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
.resource-anchor {
|
| 225 |
+
display: block;
|
| 226 |
+
height: 0;
|
| 227 |
+
overflow: hidden;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
/* ---- pinned notes ---- */
|
| 231 |
+
.pinned-notes {
|
| 232 |
+
margin: 30px 0 32px;
|
| 233 |
+
}
|
| 234 |
+
.pinned-notes-list .cell {
|
| 235 |
+
margin: 0;
|
| 236 |
+
}
|
| 237 |
+
.pinned-notes-list .cell-title {
|
| 238 |
+
display: flex;
|
| 239 |
+
align-items: center;
|
| 240 |
+
gap: 7px;
|
| 241 |
+
}
|
| 242 |
+
.pin-ico {
|
| 243 |
+
flex: 0 0 auto;
|
| 244 |
+
width: 14px;
|
| 245 |
+
height: 14px;
|
| 246 |
+
fill: var(--accent);
|
| 247 |
+
stroke: none;
|
| 248 |
+
}
|
| 249 |
+
.pinned-notes-list .cell + .cell {
|
| 250 |
+
margin-top: 12px;
|
| 251 |
+
}
|
| 252 |
+
.book-intro.has-pinned-notes {
|
| 253 |
+
border-bottom: none;
|
| 254 |
+
padding-bottom: 22px;
|
| 255 |
+
margin-bottom: 30px;
|
| 256 |
+
}
|
| 257 |
+
.book-intro.book-intro-tight {
|
| 258 |
+
border-bottom: none;
|
| 259 |
+
padding-bottom: 4px;
|
| 260 |
+
margin-bottom: 20px;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
#page h1 {
|
| 264 |
+
font-family: var(--serif);
|
| 265 |
+
font-size: 34px;
|
| 266 |
+
line-height: 1.15;
|
| 267 |
+
letter-spacing: -0.02em;
|
| 268 |
+
margin: 0 0 8px;
|
| 269 |
+
overflow-wrap: anywhere;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
#page .page-section:not(.book-intro) h1 {
|
| 273 |
+
font-size: 26px;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
#page h2 {
|
| 277 |
+
font-family: var(--serif);
|
| 278 |
+
font-size: 24px;
|
| 279 |
+
margin: 36px 0 10px;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
#page h3 {
|
| 283 |
+
font-size: 17px;
|
| 284 |
+
font-weight: 700;
|
| 285 |
+
margin: 26px 0 2px;
|
| 286 |
+
letter-spacing: -0.01em;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
#page h3::before {
|
| 290 |
+
content: "";
|
| 291 |
+
display: inline-block;
|
| 292 |
+
width: 7px;
|
| 293 |
+
height: 7px;
|
| 294 |
+
border-radius: 2px;
|
| 295 |
+
background: var(--accent);
|
| 296 |
+
margin-right: 10px;
|
| 297 |
+
vertical-align: middle;
|
| 298 |
+
transform: translateY(-1px);
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
#page p {
|
| 302 |
+
margin: 10px 0;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
#page blockquote {
|
| 306 |
+
margin: 14px 0;
|
| 307 |
+
padding: 2px 16px;
|
| 308 |
+
border-left: 3px solid #fdba74;
|
| 309 |
+
color: var(--muted);
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
#page hr {
|
| 313 |
+
display: none;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
#page code {
|
| 317 |
+
font-family: var(--mono);
|
| 318 |
+
font-size: 0.86em;
|
| 319 |
+
background: var(--code-bg);
|
| 320 |
+
padding: 2px 6px;
|
| 321 |
+
border-radius: 6px;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
#page pre {
|
| 325 |
+
max-width: 100%;
|
| 326 |
+
background: var(--code-bg);
|
| 327 |
+
border: 1px solid var(--line);
|
| 328 |
+
border-radius: var(--radius);
|
| 329 |
+
padding: 14px 16px;
|
| 330 |
+
overflow-x: auto;
|
| 331 |
+
}
|
| 332 |
+
#page pre code {
|
| 333 |
+
background: none;
|
| 334 |
+
padding: 0;
|
| 335 |
+
font-size: 11.5px;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
/* ---- code blocks + collapsible accordion ---- */
|
| 339 |
+
#page pre.hl {
|
| 340 |
+
background: #17181c;
|
| 341 |
+
border: none;
|
| 342 |
+
color: #e7e7ea;
|
| 343 |
+
font-size: 13px;
|
| 344 |
+
line-height: 1.58;
|
| 345 |
+
}
|
| 346 |
+
#page pre.hl code {
|
| 347 |
+
color: inherit;
|
| 348 |
+
font-family: var(--mono);
|
| 349 |
+
}
|
| 350 |
+
.code-accordion {
|
| 351 |
+
border: 1px solid rgba(249, 115, 22, 0.2);
|
| 352 |
+
border-radius: 8px;
|
| 353 |
+
overflow: hidden;
|
| 354 |
+
margin: 12px 0;
|
| 355 |
+
background: #17181c;
|
| 356 |
+
}
|
| 357 |
+
.code-accordion summary {
|
| 358 |
+
list-style: none;
|
| 359 |
+
cursor: pointer;
|
| 360 |
+
display: flex;
|
| 361 |
+
align-items: center;
|
| 362 |
+
gap: 9px;
|
| 363 |
+
padding: 9px 12px;
|
| 364 |
+
font-family: var(--mono);
|
| 365 |
+
font-size: 11.5px;
|
| 366 |
+
font-weight: 700;
|
| 367 |
+
color: #e7e7ea;
|
| 368 |
+
background: #1e2027;
|
| 369 |
+
user-select: none;
|
| 370 |
+
overflow-wrap: anywhere;
|
| 371 |
+
}
|
| 372 |
+
.code-accordion summary::-webkit-details-marker {
|
| 373 |
+
display: none;
|
| 374 |
+
}
|
| 375 |
+
.code-accordion summary::after {
|
| 376 |
+
content: "▸";
|
| 377 |
+
margin-left: auto;
|
| 378 |
+
color: var(--accent);
|
| 379 |
+
transition: transform 0.12s;
|
| 380 |
+
transform: rotate(180deg);
|
| 381 |
+
}
|
| 382 |
+
.code-accordion[open] summary::after {
|
| 383 |
+
transform: rotate(90deg);
|
| 384 |
+
}
|
| 385 |
+
.code-accordion .code-ico {
|
| 386 |
+
color: var(--accent);
|
| 387 |
+
font-weight: 700;
|
| 388 |
+
}
|
| 389 |
+
.code-accordion pre.hl {
|
| 390 |
+
margin: 0;
|
| 391 |
+
border-radius: 0;
|
| 392 |
+
border: none;
|
| 393 |
+
border-top: 1px solid rgba(249, 115, 22, 0.16);
|
| 394 |
+
}
|
| 395 |
+
.tok-comment {
|
| 396 |
+
color: #7a7d87;
|
| 397 |
+
font-style: italic;
|
| 398 |
+
}
|
| 399 |
+
.tok-string {
|
| 400 |
+
color: #a5d6a7;
|
| 401 |
+
}
|
| 402 |
+
.tok-keyword {
|
| 403 |
+
color: #fdba74;
|
| 404 |
+
}
|
| 405 |
+
.tok-number {
|
| 406 |
+
color: #7fd0e0;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
#page a {
|
| 410 |
+
color: var(--accent);
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
#page ul {
|
| 414 |
+
padding-left: 20px;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
.ts {
|
| 418 |
+
font-family: var(--mono);
|
| 419 |
+
font-size: 12px;
|
| 420 |
+
color: var(--muted);
|
| 421 |
+
background: none;
|
| 422 |
+
padding: 0;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
/* ---- notebook-style cells ---- */
|
| 426 |
+
.cell {
|
| 427 |
+
max-width: 100%;
|
| 428 |
+
margin: 0 0 32px;
|
| 429 |
+
background: none;
|
| 430 |
+
border: none;
|
| 431 |
+
border-radius: 0;
|
| 432 |
+
box-shadow: none;
|
| 433 |
+
overflow: visible;
|
| 434 |
+
}
|
| 435 |
+
.cell-head {
|
| 436 |
+
display: flex;
|
| 437 |
+
justify-content: space-between;
|
| 438 |
+
gap: 16px;
|
| 439 |
+
align-items: baseline;
|
| 440 |
+
padding: 0 0 5px;
|
| 441 |
+
background: none;
|
| 442 |
+
border-bottom: none;
|
| 443 |
+
}
|
| 444 |
+
.cell-head.no-title {
|
| 445 |
+
justify-content: flex-end;
|
| 446 |
+
padding: 0 0 3px;
|
| 447 |
+
}
|
| 448 |
+
.cell-title {
|
| 449 |
+
flex: 1;
|
| 450 |
+
min-width: 0;
|
| 451 |
+
font-size: 13px;
|
| 452 |
+
font-weight: 650;
|
| 453 |
+
color: var(--ink);
|
| 454 |
+
line-height: 1.35;
|
| 455 |
+
overflow-wrap: anywhere;
|
| 456 |
+
}
|
| 457 |
+
.cell-meta {
|
| 458 |
+
flex: 0 0 auto;
|
| 459 |
+
display: flex;
|
| 460 |
+
align-items: center;
|
| 461 |
+
gap: 10px;
|
| 462 |
+
font-family: var(--sans);
|
| 463 |
+
font-size: 13px;
|
| 464 |
+
color: var(--muted);
|
| 465 |
+
}
|
| 466 |
+
.cell-open {
|
| 467 |
+
flex: 0 0 auto;
|
| 468 |
+
font-family: var(--mono);
|
| 469 |
+
font-size: 12px;
|
| 470 |
+
color: var(--accent);
|
| 471 |
+
text-decoration: none;
|
| 472 |
+
}
|
| 473 |
+
.cell-open:hover {
|
| 474 |
+
color: var(--accent-strong);
|
| 475 |
+
}
|
| 476 |
+
.cell-body {
|
| 477 |
+
min-width: 0;
|
| 478 |
+
padding: 0;
|
| 479 |
+
}
|
| 480 |
+
.cell.dashboard .cell-body {
|
| 481 |
+
padding: 0;
|
| 482 |
+
}
|
| 483 |
+
#page .cell-body h1,
|
| 484 |
+
#page .cell-body h2 {
|
| 485 |
+
font-family: var(--sans);
|
| 486 |
+
font-size: 17px;
|
| 487 |
+
font-weight: 700;
|
| 488 |
+
letter-spacing: -0.01em;
|
| 489 |
+
line-height: 1.35;
|
| 490 |
+
margin: 22px 0 6px;
|
| 491 |
+
}
|
| 492 |
+
#page .cell-body > :first-child {
|
| 493 |
+
margin-top: 0;
|
| 494 |
+
}
|
| 495 |
+
#page .cell-body > :last-child {
|
| 496 |
+
margin-bottom: 0;
|
| 497 |
+
}
|
| 498 |
+
.figure-fit {
|
| 499 |
+
position: relative;
|
| 500 |
+
overflow: hidden;
|
| 501 |
+
min-height: 160px;
|
| 502 |
+
border: 1px solid var(--line);
|
| 503 |
+
border-radius: 8px;
|
| 504 |
+
background: #fff;
|
| 505 |
+
}
|
| 506 |
+
.figure-fit[hidden] {
|
| 507 |
+
display: none;
|
| 508 |
+
}
|
| 509 |
+
.figure-fit:fullscreen,
|
| 510 |
+
.figure-fit:-webkit-full-screen {
|
| 511 |
+
width: 100%;
|
| 512 |
+
height: 100%;
|
| 513 |
+
border: none;
|
| 514 |
+
border-radius: 0;
|
| 515 |
+
}
|
| 516 |
+
.figure-frame {
|
| 517 |
+
display: block;
|
| 518 |
+
width: 100%;
|
| 519 |
+
min-height: 160px;
|
| 520 |
+
border: none;
|
| 521 |
+
background: #fff;
|
| 522 |
+
}
|
| 523 |
+
.figure-frame[hidden],
|
| 524 |
+
.figure-raw[hidden] {
|
| 525 |
+
display: none;
|
| 526 |
+
}
|
| 527 |
+
.fig-switch {
|
| 528 |
+
position: relative;
|
| 529 |
+
display: inline-flex;
|
| 530 |
+
flex: 0 0 auto;
|
| 531 |
+
border: 1px solid var(--line);
|
| 532 |
+
border-radius: 999px;
|
| 533 |
+
background: var(--code-bg);
|
| 534 |
+
padding: 2px;
|
| 535 |
+
}
|
| 536 |
+
.fig-switch button {
|
| 537 |
+
position: relative;
|
| 538 |
+
z-index: 1;
|
| 539 |
+
flex: 1;
|
| 540 |
+
min-width: 62px;
|
| 541 |
+
border: none;
|
| 542 |
+
background: none;
|
| 543 |
+
font-family: var(--sans);
|
| 544 |
+
font-size: 12px;
|
| 545 |
+
font-weight: 600;
|
| 546 |
+
color: var(--muted);
|
| 547 |
+
padding: 3px 12px;
|
| 548 |
+
border-radius: 999px;
|
| 549 |
+
cursor: pointer;
|
| 550 |
+
transition: color 0.15s;
|
| 551 |
+
}
|
| 552 |
+
.fig-switch button.active {
|
| 553 |
+
color: var(--accent-strong);
|
| 554 |
+
}
|
| 555 |
+
.fig-switch-thumb {
|
| 556 |
+
position: absolute;
|
| 557 |
+
top: 2px;
|
| 558 |
+
bottom: 2px;
|
| 559 |
+
left: 2px;
|
| 560 |
+
width: calc(50% - 2px);
|
| 561 |
+
border-radius: 999px;
|
| 562 |
+
background: var(--panel);
|
| 563 |
+
border: 1px solid rgba(249, 115, 22, 0.35);
|
| 564 |
+
box-shadow: 0 1px 4px rgba(31, 41, 55, 0.08);
|
| 565 |
+
transition: transform 0.18s ease;
|
| 566 |
+
}
|
| 567 |
+
.fig-switch.raw .fig-switch-thumb {
|
| 568 |
+
transform: translateX(100%);
|
| 569 |
+
}
|
| 570 |
+
#page .figure-raw pre {
|
| 571 |
+
margin: 0;
|
| 572 |
+
max-height: 420px;
|
| 573 |
+
overflow: auto;
|
| 574 |
+
font-family: var(--mono);
|
| 575 |
+
font-size: 13px;
|
| 576 |
+
line-height: 1.55;
|
| 577 |
+
background: var(--code-bg);
|
| 578 |
+
border: 1px solid var(--line);
|
| 579 |
+
border-radius: 8px;
|
| 580 |
+
padding: 12px 14px;
|
| 581 |
+
}
|
| 582 |
+
/* ---- figure fullscreen ---- */
|
| 583 |
+
.cell-fullscreen {
|
| 584 |
+
position: relative;
|
| 585 |
+
display: inline-flex;
|
| 586 |
+
flex: 0 0 auto;
|
| 587 |
+
}
|
| 588 |
+
.cell-fullscreen-btn {
|
| 589 |
+
display: inline-flex;
|
| 590 |
+
align-items: center;
|
| 591 |
+
justify-content: center;
|
| 592 |
+
width: 26px;
|
| 593 |
+
height: 26px;
|
| 594 |
+
padding: 0;
|
| 595 |
+
border: 1px solid var(--line);
|
| 596 |
+
border-radius: 999px;
|
| 597 |
+
background: var(--code-bg);
|
| 598 |
+
color: var(--muted);
|
| 599 |
+
cursor: pointer;
|
| 600 |
+
transition: color 0.15s, border-color 0.15s, background 0.15s;
|
| 601 |
+
}
|
| 602 |
+
.cell-fullscreen-btn:hover {
|
| 603 |
+
color: var(--accent-strong);
|
| 604 |
+
border-color: rgba(249, 115, 22, 0.35);
|
| 605 |
+
background: var(--accent-soft);
|
| 606 |
+
}
|
| 607 |
+
.cell-fullscreen-btn svg {
|
| 608 |
+
width: 14px;
|
| 609 |
+
height: 14px;
|
| 610 |
+
}
|
| 611 |
+
/* ---- copyable snippets ---- */
|
| 612 |
+
.snippet {
|
| 613 |
+
position: relative;
|
| 614 |
+
}
|
| 615 |
+
.copy-snippet {
|
| 616 |
+
position: absolute;
|
| 617 |
+
top: 7px;
|
| 618 |
+
right: 8px;
|
| 619 |
+
width: 24px;
|
| 620 |
+
height: 24px;
|
| 621 |
+
border: none;
|
| 622 |
+
border-radius: 6px;
|
| 623 |
+
background: rgba(255, 255, 255, 0.08);
|
| 624 |
+
color: #9a9da8;
|
| 625 |
+
font-size: 12px;
|
| 626 |
+
line-height: 1;
|
| 627 |
+
cursor: pointer;
|
| 628 |
+
opacity: 0;
|
| 629 |
+
transition: opacity 0.12s, color 0.12s, background 0.12s;
|
| 630 |
+
}
|
| 631 |
+
.snippet:hover .copy-snippet,
|
| 632 |
+
.jp-out:hover .copy-snippet,
|
| 633 |
+
.figure-raw:hover .copy-snippet,
|
| 634 |
+
.code-accordion summary:hover .copy-snippet {
|
| 635 |
+
opacity: 1;
|
| 636 |
+
}
|
| 637 |
+
.copy-snippet:hover {
|
| 638 |
+
color: #ffffff;
|
| 639 |
+
background: rgba(255, 255, 255, 0.16);
|
| 640 |
+
}
|
| 641 |
+
.copy-snippet.copied {
|
| 642 |
+
color: #52d08a;
|
| 643 |
+
opacity: 1;
|
| 644 |
+
}
|
| 645 |
+
.code-accordion .code-name {
|
| 646 |
+
user-select: text;
|
| 647 |
+
cursor: text;
|
| 648 |
+
}
|
| 649 |
+
.jp-out,
|
| 650 |
+
.figure-raw {
|
| 651 |
+
position: relative;
|
| 652 |
+
}
|
| 653 |
+
.jp-out .copy-snippet,
|
| 654 |
+
.figure-raw .copy-snippet {
|
| 655 |
+
background: var(--code-bg);
|
| 656 |
+
color: var(--muted);
|
| 657 |
+
border: 1px solid var(--line);
|
| 658 |
+
}
|
| 659 |
+
.jp-out .copy-snippet:hover,
|
| 660 |
+
.figure-raw .copy-snippet:hover {
|
| 661 |
+
color: var(--accent-strong);
|
| 662 |
+
background: var(--panel);
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
/* ---- jupyter-style code cells ---- */
|
| 666 |
+
.jp {
|
| 667 |
+
border: 1px solid var(--line);
|
| 668 |
+
border-radius: 10px;
|
| 669 |
+
overflow: hidden;
|
| 670 |
+
margin: 0;
|
| 671 |
+
background: var(--panel);
|
| 672 |
+
}
|
| 673 |
+
.jp-cmd {
|
| 674 |
+
display: flex;
|
| 675 |
+
align-items: baseline;
|
| 676 |
+
gap: 9px;
|
| 677 |
+
position: relative;
|
| 678 |
+
padding: 10px 16px 10px 0;
|
| 679 |
+
font-family: var(--mono);
|
| 680 |
+
font-size: 12px;
|
| 681 |
+
color: #8b8e98;
|
| 682 |
+
}
|
| 683 |
+
.jp-cmd-prompt {
|
| 684 |
+
color: var(--accent);
|
| 685 |
+
font-weight: 700;
|
| 686 |
+
}
|
| 687 |
+
#page .jp-cmd code {
|
| 688 |
+
min-width: 0;
|
| 689 |
+
color: #b6b9c2;
|
| 690 |
+
font-family: var(--mono);
|
| 691 |
+
font-size: 12px;
|
| 692 |
+
background: none;
|
| 693 |
+
padding: 0;
|
| 694 |
+
border-radius: 0;
|
| 695 |
+
overflow-wrap: anywhere;
|
| 696 |
+
}
|
| 697 |
+
.jp-cmd:hover .copy-snippet {
|
| 698 |
+
opacity: 1;
|
| 699 |
+
}
|
| 700 |
+
.jp-in-body .jp-cmd + .code-accordion,
|
| 701 |
+
.jp-in-body .jp-cmd + .snippet {
|
| 702 |
+
border-top: 1px solid rgba(255, 255, 255, 0.09);
|
| 703 |
+
}
|
| 704 |
+
.jp-gutter {
|
| 705 |
+
flex: 0 0 46px;
|
| 706 |
+
padding: 13px 0 0 13px;
|
| 707 |
+
font-family: var(--mono);
|
| 708 |
+
font-size: 10.5px;
|
| 709 |
+
letter-spacing: 0.07em;
|
| 710 |
+
text-transform: uppercase;
|
| 711 |
+
font-weight: 600;
|
| 712 |
+
user-select: none;
|
| 713 |
+
}
|
| 714 |
+
.jp-in {
|
| 715 |
+
display: flex;
|
| 716 |
+
background: #17181c;
|
| 717 |
+
}
|
| 718 |
+
.jp-in .jp-gutter {
|
| 719 |
+
color: #6f727d;
|
| 720 |
+
}
|
| 721 |
+
.jp-in-body {
|
| 722 |
+
flex: 1;
|
| 723 |
+
min-width: 0;
|
| 724 |
+
}
|
| 725 |
+
#page .jp-in-body pre.hl {
|
| 726 |
+
margin: 0;
|
| 727 |
+
border: none;
|
| 728 |
+
border-radius: 0;
|
| 729 |
+
background: none;
|
| 730 |
+
padding: 12px 16px 12px 0;
|
| 731 |
+
overflow-y: auto;
|
| 732 |
+
max-height: 26em;
|
| 733 |
+
}
|
| 734 |
+
.jp-in-body .code-accordion {
|
| 735 |
+
margin: 0;
|
| 736 |
+
border: none;
|
| 737 |
+
border-top: 1px solid rgba(255, 255, 255, 0.09);
|
| 738 |
+
border-radius: 0;
|
| 739 |
+
background: none;
|
| 740 |
+
}
|
| 741 |
+
.jp-in-body .code-accordion summary {
|
| 742 |
+
background: none;
|
| 743 |
+
padding: 9px 16px 9px 0;
|
| 744 |
+
}
|
| 745 |
+
.jp-in-body .code-accordion pre.hl {
|
| 746 |
+
border-top: 1px solid rgba(255, 255, 255, 0.09);
|
| 747 |
+
}
|
| 748 |
+
.jp-meta {
|
| 749 |
+
padding: 5px 14px;
|
| 750 |
+
font-family: var(--mono);
|
| 751 |
+
font-size: 11.5px;
|
| 752 |
+
color: var(--muted);
|
| 753 |
+
background: #fbfbfc;
|
| 754 |
+
border-top: 1px solid var(--line);
|
| 755 |
+
}
|
| 756 |
+
.jp-out {
|
| 757 |
+
display: flex;
|
| 758 |
+
border-top: 1px solid var(--line);
|
| 759 |
+
background: var(--panel);
|
| 760 |
+
}
|
| 761 |
+
.jp-out .jp-gutter {
|
| 762 |
+
color: var(--accent-strong);
|
| 763 |
+
}
|
| 764 |
+
.jp-out-body {
|
| 765 |
+
flex: 1;
|
| 766 |
+
min-width: 0;
|
| 767 |
+
}
|
| 768 |
+
#page .jp-out-pre {
|
| 769 |
+
min-width: 0;
|
| 770 |
+
margin: 0;
|
| 771 |
+
border: none;
|
| 772 |
+
border-radius: 0;
|
| 773 |
+
background: none;
|
| 774 |
+
color: var(--ink);
|
| 775 |
+
font-family: var(--mono);
|
| 776 |
+
font-size: 13px;
|
| 777 |
+
line-height: 1.55;
|
| 778 |
+
padding: 12px 16px 12px 0;
|
| 779 |
+
white-space: pre;
|
| 780 |
+
overflow-x: auto;
|
| 781 |
+
overflow-y: auto;
|
| 782 |
+
max-height: 26em;
|
| 783 |
+
}
|
| 784 |
+
.jp-artifacts {
|
| 785 |
+
display: flex;
|
| 786 |
+
flex-direction: column;
|
| 787 |
+
}
|
| 788 |
+
.jp-out-body .jp-out-pre + .jp-artifacts {
|
| 789 |
+
border-top: 1px solid var(--line);
|
| 790 |
+
}
|
| 791 |
+
.out-artifact {
|
| 792 |
+
display: flex;
|
| 793 |
+
align-items: baseline;
|
| 794 |
+
gap: 8px;
|
| 795 |
+
padding: 9px 16px 9px 0;
|
| 796 |
+
text-decoration: none;
|
| 797 |
+
color: inherit;
|
| 798 |
+
}
|
| 799 |
+
.out-artifact + .out-artifact {
|
| 800 |
+
border-top: 1px solid var(--line);
|
| 801 |
+
}
|
| 802 |
+
a.out-artifact:hover .out-artifact-name {
|
| 803 |
+
color: var(--accent-strong);
|
| 804 |
+
}
|
| 805 |
+
.out-artifact-ico {
|
| 806 |
+
flex: 0 0 auto;
|
| 807 |
+
font-size: 13px;
|
| 808 |
+
}
|
| 809 |
+
.out-artifact-name {
|
| 810 |
+
font-family: var(--mono);
|
| 811 |
+
font-size: 12.5px;
|
| 812 |
+
font-weight: 600;
|
| 813 |
+
color: var(--ink);
|
| 814 |
+
overflow: hidden;
|
| 815 |
+
text-overflow: ellipsis;
|
| 816 |
+
white-space: nowrap;
|
| 817 |
+
}
|
| 818 |
+
.out-artifact-meta {
|
| 819 |
+
flex: 0 0 auto;
|
| 820 |
+
margin-left: auto;
|
| 821 |
+
padding-left: 12px;
|
| 822 |
+
font-size: 12px;
|
| 823 |
+
color: var(--muted);
|
| 824 |
+
white-space: nowrap;
|
| 825 |
+
}
|
| 826 |
+
.out-artifact-state.open {
|
| 827 |
+
color: var(--accent);
|
| 828 |
+
font-weight: 600;
|
| 829 |
+
}
|
| 830 |
+
.trackio-embed {
|
| 831 |
+
border: 1px solid var(--line);
|
| 832 |
+
border-radius: var(--radius);
|
| 833 |
+
overflow: hidden;
|
| 834 |
+
background: var(--panel);
|
| 835 |
+
}
|
| 836 |
+
.trackio-cell-meta {
|
| 837 |
+
display: flex;
|
| 838 |
+
gap: 6px;
|
| 839 |
+
flex-wrap: wrap;
|
| 840 |
+
justify-content: flex-end;
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
/* ---- unfurl cards ---- */
|
| 844 |
+
.unfurl {
|
| 845 |
+
display: block;
|
| 846 |
+
border: 1px solid var(--line);
|
| 847 |
+
border-radius: var(--radius);
|
| 848 |
+
background: var(--panel);
|
| 849 |
+
margin: 12px 0;
|
| 850 |
+
overflow: hidden;
|
| 851 |
+
text-decoration: none;
|
| 852 |
+
color: inherit;
|
| 853 |
+
transition: border-color 0.14s, box-shadow 0.14s;
|
| 854 |
+
}
|
| 855 |
+
.unfurl:hover {
|
| 856 |
+
border-color: #cfcbe6;
|
| 857 |
+
box-shadow: 0 4px 18px rgba(30, 20, 80, 0.06);
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
.unfurl-body {
|
| 861 |
+
padding: 13px 16px;
|
| 862 |
+
display: flex;
|
| 863 |
+
gap: 12px;
|
| 864 |
+
align-items: flex-start;
|
| 865 |
+
}
|
| 866 |
+
|
| 867 |
+
.unfurl-ico {
|
| 868 |
+
font-size: 20px;
|
| 869 |
+
line-height: 1.3;
|
| 870 |
+
flex: 0 0 auto;
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
.unfurl-main {
|
| 874 |
+
min-width: 0;
|
| 875 |
+
flex: 1;
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
.unfurl-kind {
|
| 879 |
+
font-family: var(--mono);
|
| 880 |
+
font-size: 10.5px;
|
| 881 |
+
text-transform: uppercase;
|
| 882 |
+
letter-spacing: 0.08em;
|
| 883 |
+
color: var(--accent);
|
| 884 |
+
font-weight: 600;
|
| 885 |
+
}
|
| 886 |
+
|
| 887 |
+
.unfurl-title {
|
| 888 |
+
font-weight: 650;
|
| 889 |
+
font-size: 15px;
|
| 890 |
+
margin: 1px 0 2px;
|
| 891 |
+
white-space: nowrap;
|
| 892 |
+
overflow: hidden;
|
| 893 |
+
text-overflow: ellipsis;
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
.unfurl-desc {
|
| 897 |
+
color: var(--muted);
|
| 898 |
+
font-size: 13.5px;
|
| 899 |
+
line-height: 1.45;
|
| 900 |
+
}
|
| 901 |
+
|
| 902 |
+
.unfurl-meta {
|
| 903 |
+
margin-top: 6px;
|
| 904 |
+
display: flex;
|
| 905 |
+
flex-wrap: wrap;
|
| 906 |
+
gap: 6px;
|
| 907 |
+
}
|
| 908 |
+
|
| 909 |
+
.chip {
|
| 910 |
+
font-size: 11.5px;
|
| 911 |
+
background: var(--code-bg);
|
| 912 |
+
border-radius: 999px;
|
| 913 |
+
padding: 2px 9px;
|
| 914 |
+
color: var(--muted);
|
| 915 |
+
font-family: var(--mono);
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
.unfurl-raw {
|
| 919 |
+
font-family: var(--mono);
|
| 920 |
+
font-size: 11px;
|
| 921 |
+
color: var(--muted);
|
| 922 |
+
border-top: 1px solid var(--line);
|
| 923 |
+
padding: 7px 16px;
|
| 924 |
+
white-space: nowrap;
|
| 925 |
+
overflow: hidden;
|
| 926 |
+
text-overflow: ellipsis;
|
| 927 |
+
}
|
| 928 |
+
|
| 929 |
+
.unfurl.embed {
|
| 930 |
+
padding: 0;
|
| 931 |
+
overflow: hidden;
|
| 932 |
+
}
|
| 933 |
+
.embed-head {
|
| 934 |
+
display: flex;
|
| 935 |
+
align-items: center;
|
| 936 |
+
gap: 10px;
|
| 937 |
+
padding: 10px 14px;
|
| 938 |
+
border-bottom: 1px solid var(--line);
|
| 939 |
+
}
|
| 940 |
+
.embed-head .unfurl-kind {
|
| 941 |
+
flex: 0 0 auto;
|
| 942 |
+
}
|
| 943 |
+
.embed-title {
|
| 944 |
+
flex: 1;
|
| 945 |
+
min-width: 0;
|
| 946 |
+
font-weight: 650;
|
| 947 |
+
font-size: 14px;
|
| 948 |
+
color: var(--ink);
|
| 949 |
+
text-decoration: none;
|
| 950 |
+
white-space: nowrap;
|
| 951 |
+
overflow: hidden;
|
| 952 |
+
text-overflow: ellipsis;
|
| 953 |
+
}
|
| 954 |
+
.embed-title:hover {
|
| 955 |
+
color: var(--accent);
|
| 956 |
+
}
|
| 957 |
+
.embed-open {
|
| 958 |
+
flex: 0 0 auto;
|
| 959 |
+
font-family: var(--mono);
|
| 960 |
+
font-size: 12px;
|
| 961 |
+
color: var(--accent);
|
| 962 |
+
text-decoration: none;
|
| 963 |
+
}
|
| 964 |
+
.embed-frame {
|
| 965 |
+
display: block;
|
| 966 |
+
width: 100%;
|
| 967 |
+
height: 560px;
|
| 968 |
+
border: 0;
|
| 969 |
+
background: var(--code-bg);
|
| 970 |
+
}
|
| 971 |
+
|
| 972 |
+
.dashboard-shell {
|
| 973 |
+
display: block;
|
| 974 |
+
}
|
| 975 |
+
.dashboard-shell .dashboard-frame {
|
| 976 |
+
display: block;
|
| 977 |
+
width: 100%;
|
| 978 |
+
height: 900px;
|
| 979 |
+
border: 0;
|
| 980 |
+
background: var(--code-bg);
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
.unfurl.image {
|
| 984 |
+
padding: 0;
|
| 985 |
+
}
|
| 986 |
+
.unfurl.image img {
|
| 987 |
+
display: block;
|
| 988 |
+
width: 100%;
|
| 989 |
+
height: auto;
|
| 990 |
+
max-height: 460px;
|
| 991 |
+
object-fit: contain;
|
| 992 |
+
background: var(--code-bg);
|
| 993 |
+
}
|
| 994 |
+
|
| 995 |
+
.artifact-chip {
|
| 996 |
+
border: 1px solid var(--line);
|
| 997 |
+
background: var(--panel);
|
| 998 |
+
border-radius: var(--radius);
|
| 999 |
+
padding: 10px 14px;
|
| 1000 |
+
margin: 8px 0;
|
| 1001 |
+
font-size: 14px;
|
| 1002 |
+
}
|
| 1003 |
+
.cell.dashboard .artifact-chip {
|
| 1004 |
+
margin: 14px 18px 18px;
|
| 1005 |
+
}
|
| 1006 |
+
.artifact-chip code {
|
| 1007 |
+
color: var(--accent);
|
| 1008 |
+
}
|
| 1009 |
+
|
| 1010 |
+
/* ---- task board ---- */
|
| 1011 |
+
.board-wrap {
|
| 1012 |
+
overflow-x: auto;
|
| 1013 |
+
border: 1px solid var(--line);
|
| 1014 |
+
border-radius: var(--radius);
|
| 1015 |
+
margin: 12px 0 20px;
|
| 1016 |
+
background: var(--panel);
|
| 1017 |
+
}
|
| 1018 |
+
table.board {
|
| 1019 |
+
border-collapse: collapse;
|
| 1020 |
+
width: 100%;
|
| 1021 |
+
font-size: 14px;
|
| 1022 |
+
}
|
| 1023 |
+
table.board th,
|
| 1024 |
+
table.board td {
|
| 1025 |
+
text-align: left;
|
| 1026 |
+
padding: 9px 14px;
|
| 1027 |
+
border-bottom: 1px solid var(--line);
|
| 1028 |
+
vertical-align: top;
|
| 1029 |
+
}
|
| 1030 |
+
table.board thead th {
|
| 1031 |
+
background: var(--accent-soft);
|
| 1032 |
+
font-size: 12px;
|
| 1033 |
+
text-transform: uppercase;
|
| 1034 |
+
letter-spacing: 0.05em;
|
| 1035 |
+
color: #9a4a12;
|
| 1036 |
+
font-weight: 600;
|
| 1037 |
+
border-bottom: 1px solid var(--line);
|
| 1038 |
+
}
|
| 1039 |
+
table.board tbody tr:last-child td {
|
| 1040 |
+
border-bottom: none;
|
| 1041 |
+
}
|
| 1042 |
+
table.board .col-check {
|
| 1043 |
+
text-align: center;
|
| 1044 |
+
width: 92px;
|
| 1045 |
+
white-space: nowrap;
|
| 1046 |
+
}
|
| 1047 |
+
table.board tr.section-row td {
|
| 1048 |
+
background: var(--accent-soft);
|
| 1049 |
+
text-align: center;
|
| 1050 |
+
font-weight: 700;
|
| 1051 |
+
font-size: 13px;
|
| 1052 |
+
color: var(--accent-strong);
|
| 1053 |
+
padding: 7px 14px;
|
| 1054 |
+
letter-spacing: 0.02em;
|
| 1055 |
+
}
|
| 1056 |
+
.box {
|
| 1057 |
+
display: inline-flex;
|
| 1058 |
+
align-items: center;
|
| 1059 |
+
justify-content: center;
|
| 1060 |
+
width: 18px;
|
| 1061 |
+
height: 18px;
|
| 1062 |
+
border: 1.5px solid #cfcbe0;
|
| 1063 |
+
border-radius: 5px;
|
| 1064 |
+
font-size: 12px;
|
| 1065 |
+
color: #fff;
|
| 1066 |
+
line-height: 1;
|
| 1067 |
+
}
|
| 1068 |
+
.box.on {
|
| 1069 |
+
background: var(--accent);
|
| 1070 |
+
border-color: var(--accent);
|
| 1071 |
+
}
|
| 1072 |
+
.who-chip {
|
| 1073 |
+
display: inline-block;
|
| 1074 |
+
padding: 3px 12px;
|
| 1075 |
+
border-radius: 999px;
|
| 1076 |
+
font-size: 12.5px;
|
| 1077 |
+
font-weight: 600;
|
| 1078 |
+
white-space: nowrap;
|
| 1079 |
+
}
|
| 1080 |
+
.who-chip.muted {
|
| 1081 |
+
background: var(--code-bg);
|
| 1082 |
+
color: var(--muted);
|
| 1083 |
+
font-weight: 500;
|
| 1084 |
+
}
|
| 1085 |
+
|
| 1086 |
+
/* ---- status badges + clickable rows ---- */
|
| 1087 |
+
table.board .col-status {
|
| 1088 |
+
width: 130px;
|
| 1089 |
+
white-space: nowrap;
|
| 1090 |
+
}
|
| 1091 |
+
.badge {
|
| 1092 |
+
display: inline-block;
|
| 1093 |
+
padding: 3px 11px;
|
| 1094 |
+
border-radius: 999px;
|
| 1095 |
+
font-size: 12px;
|
| 1096 |
+
font-weight: 600;
|
| 1097 |
+
letter-spacing: 0.01em;
|
| 1098 |
+
}
|
| 1099 |
+
.badge.gray {
|
| 1100 |
+
background: var(--code-bg);
|
| 1101 |
+
color: var(--muted);
|
| 1102 |
+
}
|
| 1103 |
+
.badge.amber {
|
| 1104 |
+
background: var(--accent-soft);
|
| 1105 |
+
color: #b45309;
|
| 1106 |
+
}
|
| 1107 |
+
.badge.green {
|
| 1108 |
+
background: #e6f7ee;
|
| 1109 |
+
color: #1a8a55;
|
| 1110 |
+
}
|
| 1111 |
+
.badge.red {
|
| 1112 |
+
background: #fde8ec;
|
| 1113 |
+
color: #c62a4b;
|
| 1114 |
+
}
|
| 1115 |
+
table.board tr.linked-row {
|
| 1116 |
+
cursor: pointer;
|
| 1117 |
+
}
|
| 1118 |
+
table.board tr.linked-row:hover td {
|
| 1119 |
+
background: var(--accent-soft);
|
| 1120 |
+
}
|
| 1121 |
+
table.board tr.linked-row a {
|
| 1122 |
+
color: var(--ink);
|
| 1123 |
+
font-weight: 600;
|
| 1124 |
+
text-decoration: none;
|
| 1125 |
+
}
|
| 1126 |
+
table.board tr.linked-row:hover a {
|
| 1127 |
+
color: var(--accent-strong);
|
| 1128 |
+
}
|
| 1129 |
+
|
| 1130 |
+
/* ---- agent read hint ---- */
|
| 1131 |
+
.agent-hint {
|
| 1132 |
+
display: flex;
|
| 1133 |
+
align-items: center;
|
| 1134 |
+
flex-wrap: wrap;
|
| 1135 |
+
gap: 8px;
|
| 1136 |
+
margin: 0;
|
| 1137 |
+
font-size: 12.5px;
|
| 1138 |
+
color: var(--muted);
|
| 1139 |
+
}
|
| 1140 |
+
.agent-hint code {
|
| 1141 |
+
flex: 1 1 18rem;
|
| 1142 |
+
min-width: 0;
|
| 1143 |
+
background: var(--code-bg);
|
| 1144 |
+
padding: 2px 9px;
|
| 1145 |
+
border-radius: 6px;
|
| 1146 |
+
font-family: var(--mono);
|
| 1147 |
+
font-size: 12px;
|
| 1148 |
+
font-weight: 500;
|
| 1149 |
+
color: var(--ink);
|
| 1150 |
+
overflow: hidden;
|
| 1151 |
+
text-overflow: ellipsis;
|
| 1152 |
+
white-space: nowrap;
|
| 1153 |
+
}
|
| 1154 |
+
.agent-hint .copy {
|
| 1155 |
+
flex: 0 0 auto;
|
| 1156 |
+
background: none;
|
| 1157 |
+
color: var(--muted);
|
| 1158 |
+
border: 1px solid var(--line);
|
| 1159 |
+
border-radius: 6px;
|
| 1160 |
+
width: 22px;
|
| 1161 |
+
height: 22px;
|
| 1162 |
+
font-size: 11px;
|
| 1163 |
+
line-height: 1;
|
| 1164 |
+
cursor: pointer;
|
| 1165 |
+
transition: color 0.12s, border-color 0.12s;
|
| 1166 |
+
}
|
| 1167 |
+
.agent-hint .copy:hover {
|
| 1168 |
+
color: var(--accent-strong);
|
| 1169 |
+
border-color: var(--accent);
|
| 1170 |
+
}
|
| 1171 |
+
.agent-hint .copy.copied {
|
| 1172 |
+
color: #1a8a55;
|
| 1173 |
+
border-color: #1a8a55;
|
| 1174 |
+
}
|
| 1175 |
+
.agent-hint-note {
|
| 1176 |
+
margin-left: auto;
|
| 1177 |
+
font-size: 12px;
|
| 1178 |
+
color: var(--muted);
|
| 1179 |
+
}
|
| 1180 |
+
.hub-destination {
|
| 1181 |
+
display: flex;
|
| 1182 |
+
align-items: center;
|
| 1183 |
+
flex-wrap: wrap;
|
| 1184 |
+
gap: 8px;
|
| 1185 |
+
color: var(--muted);
|
| 1186 |
+
font-size: 12.5px;
|
| 1187 |
+
}
|
| 1188 |
+
.hub-destination a {
|
| 1189 |
+
display: inline-flex;
|
| 1190 |
+
align-items: center;
|
| 1191 |
+
gap: 6px;
|
| 1192 |
+
max-width: 100%;
|
| 1193 |
+
padding: 3px 9px;
|
| 1194 |
+
border: 1px solid var(--accent-line);
|
| 1195 |
+
border-radius: 999px;
|
| 1196 |
+
background: var(--accent-soft);
|
| 1197 |
+
color: var(--accent-strong);
|
| 1198 |
+
font-family: var(--mono);
|
| 1199 |
+
font-size: 12px;
|
| 1200 |
+
font-weight: 650;
|
| 1201 |
+
line-height: 1.5;
|
| 1202 |
+
text-decoration: none;
|
| 1203 |
+
overflow-wrap: anywhere;
|
| 1204 |
+
transition: border-color 0.12s, background 0.12s, color 0.12s;
|
| 1205 |
+
}
|
| 1206 |
+
.hub-destination a:hover {
|
| 1207 |
+
border-color: var(--accent);
|
| 1208 |
+
background: #ffedd5;
|
| 1209 |
+
color: #c2410c;
|
| 1210 |
+
}
|
| 1211 |
+
.hub-destination svg {
|
| 1212 |
+
width: 13px;
|
| 1213 |
+
height: 13px;
|
| 1214 |
+
flex: 0 0 auto;
|
| 1215 |
+
fill: none;
|
| 1216 |
+
stroke: currentColor;
|
| 1217 |
+
stroke-width: 1.8;
|
| 1218 |
+
stroke-linecap: round;
|
| 1219 |
+
stroke-linejoin: round;
|
| 1220 |
+
}
|
| 1221 |
+
|
| 1222 |
+
.index-paper-link {
|
| 1223 |
+
margin: 14px 0 30px;
|
| 1224 |
+
font-size: 19px;
|
| 1225 |
+
line-height: 1.35;
|
| 1226 |
+
font-weight: 700;
|
| 1227 |
+
}
|
| 1228 |
+
.index-paper-link a {
|
| 1229 |
+
text-underline-offset: 4px;
|
| 1230 |
+
text-decoration-thickness: 2px;
|
| 1231 |
+
}
|
| 1232 |
+
.art-ico {
|
| 1233 |
+
width: 1em;
|
| 1234 |
+
height: 1em;
|
| 1235 |
+
object-fit: contain;
|
| 1236 |
+
vertical-align: -0.15em;
|
| 1237 |
+
}
|
| 1238 |
+
.art-file-ico {
|
| 1239 |
+
width: 15px;
|
| 1240 |
+
height: 15px;
|
| 1241 |
+
flex: 0 0 auto;
|
| 1242 |
+
fill: none;
|
| 1243 |
+
stroke: currentColor;
|
| 1244 |
+
stroke-width: 1.7;
|
| 1245 |
+
stroke-linecap: round;
|
| 1246 |
+
stroke-linejoin: round;
|
| 1247 |
+
vertical-align: -0.2em;
|
| 1248 |
+
}
|
| 1249 |
+
.out-artifact-ico .art-file-ico {
|
| 1250 |
+
color: var(--muted);
|
| 1251 |
+
}
|
| 1252 |
+
|
| 1253 |
+
/* ---- scroll-to-resource highlight ---- */
|
| 1254 |
+
.res-flash {
|
| 1255 |
+
animation: res-flash 1.5s ease;
|
| 1256 |
+
border-radius: 8px;
|
| 1257 |
+
}
|
| 1258 |
+
@keyframes res-flash {
|
| 1259 |
+
0%,
|
| 1260 |
+
25% {
|
| 1261 |
+
box-shadow: 0 0 0 3px var(--accent);
|
| 1262 |
+
}
|
| 1263 |
+
100% {
|
| 1264 |
+
box-shadow: 0 0 0 3px rgba(249, 115, 22, 0);
|
| 1265 |
+
}
|
| 1266 |
+
}
|
| 1267 |
+
|
| 1268 |
+
/* ---- inline resource chips ---- */
|
| 1269 |
+
#page .res-chip {
|
| 1270 |
+
display: inline-flex;
|
| 1271 |
+
align-items: center;
|
| 1272 |
+
gap: 5px;
|
| 1273 |
+
max-width: 100%;
|
| 1274 |
+
padding: 0 9px 0 6px;
|
| 1275 |
+
margin: 0 1px;
|
| 1276 |
+
border: 1px solid var(--line);
|
| 1277 |
+
border-radius: 999px;
|
| 1278 |
+
background: var(--panel);
|
| 1279 |
+
font-family: var(--mono);
|
| 1280 |
+
font-size: 0.78em;
|
| 1281 |
+
font-weight: 600;
|
| 1282 |
+
color: var(--ink);
|
| 1283 |
+
text-decoration: none;
|
| 1284 |
+
white-space: nowrap;
|
| 1285 |
+
overflow: hidden;
|
| 1286 |
+
text-overflow: ellipsis;
|
| 1287 |
+
vertical-align: middle;
|
| 1288 |
+
line-height: 1.65;
|
| 1289 |
+
transform: translateY(-0.08em);
|
| 1290 |
+
transition: border-color 0.12s, background 0.12s, color 0.12s;
|
| 1291 |
+
}
|
| 1292 |
+
.res-chip-ico {
|
| 1293 |
+
font-size: 1.05em;
|
| 1294 |
+
line-height: 1;
|
| 1295 |
+
}
|
| 1296 |
+
#page .res-chip:hover {
|
| 1297 |
+
border-color: var(--accent);
|
| 1298 |
+
background: var(--accent-soft);
|
| 1299 |
+
color: var(--accent-strong);
|
| 1300 |
+
}
|
| 1301 |
+
|
| 1302 |
+
/* ---- connect footer + modal ---- */
|
| 1303 |
+
#sidebar-foot {
|
| 1304 |
+
margin-top: auto;
|
| 1305 |
+
padding-top: 14px;
|
| 1306 |
+
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
| 1307 |
+
}
|
| 1308 |
+
|
| 1309 |
+
#connect-btn {
|
| 1310 |
+
width: 100%;
|
| 1311 |
+
display: flex;
|
| 1312 |
+
align-items: center;
|
| 1313 |
+
gap: 8px;
|
| 1314 |
+
background: rgba(255, 255, 255, 0.05);
|
| 1315 |
+
color: #c3c4cb;
|
| 1316 |
+
border: 1px solid rgba(255, 255, 255, 0.12);
|
| 1317 |
+
border-radius: 9px;
|
| 1318 |
+
padding: 9px 12px;
|
| 1319 |
+
font-size: 13.5px;
|
| 1320 |
+
font-family: var(--sans);
|
| 1321 |
+
cursor: pointer;
|
| 1322 |
+
transition: background 0.12s, color 0.12s, border-color 0.12s;
|
| 1323 |
+
}
|
| 1324 |
+
#connect-btn:hover {
|
| 1325 |
+
background: rgba(249, 115, 22, 0.14);
|
| 1326 |
+
border-color: rgba(249, 115, 22, 0.4);
|
| 1327 |
+
color: #fdba74;
|
| 1328 |
+
}
|
| 1329 |
+
#connect-btn .ico {
|
| 1330 |
+
font-size: 15px;
|
| 1331 |
+
}
|
| 1332 |
+
|
| 1333 |
+
#modal[hidden] {
|
| 1334 |
+
display: none;
|
| 1335 |
+
}
|
| 1336 |
+
#modal {
|
| 1337 |
+
position: fixed;
|
| 1338 |
+
inset: 0;
|
| 1339 |
+
z-index: 100;
|
| 1340 |
+
display: flex;
|
| 1341 |
+
align-items: center;
|
| 1342 |
+
justify-content: center;
|
| 1343 |
+
padding: 24px;
|
| 1344 |
+
}
|
| 1345 |
+
.modal-backdrop {
|
| 1346 |
+
position: absolute;
|
| 1347 |
+
inset: 0;
|
| 1348 |
+
background: rgba(20, 18, 30, 0.5);
|
| 1349 |
+
backdrop-filter: blur(2px);
|
| 1350 |
+
}
|
| 1351 |
+
.modal-card {
|
| 1352 |
+
position: relative;
|
| 1353 |
+
background: var(--panel);
|
| 1354 |
+
border-radius: 16px;
|
| 1355 |
+
width: 100%;
|
| 1356 |
+
max-width: 620px;
|
| 1357 |
+
max-height: 85vh;
|
| 1358 |
+
overflow-y: auto;
|
| 1359 |
+
box-shadow: 0 24px 70px rgba(20, 15, 50, 0.28);
|
| 1360 |
+
}
|
| 1361 |
+
.modal-head {
|
| 1362 |
+
display: flex;
|
| 1363 |
+
align-items: center;
|
| 1364 |
+
justify-content: space-between;
|
| 1365 |
+
gap: 12px;
|
| 1366 |
+
padding: 18px 22px;
|
| 1367 |
+
border-bottom: 1px solid var(--line);
|
| 1368 |
+
position: sticky;
|
| 1369 |
+
top: 0;
|
| 1370 |
+
background: var(--panel);
|
| 1371 |
+
}
|
| 1372 |
+
.modal-title {
|
| 1373 |
+
display: flex;
|
| 1374 |
+
align-items: center;
|
| 1375 |
+
gap: 10px;
|
| 1376 |
+
font-family: var(--serif);
|
| 1377 |
+
font-size: 21px;
|
| 1378 |
+
letter-spacing: -0.01em;
|
| 1379 |
+
}
|
| 1380 |
+
.modal-logo {
|
| 1381 |
+
width: 26px;
|
| 1382 |
+
height: 26px;
|
| 1383 |
+
object-fit: contain;
|
| 1384 |
+
}
|
| 1385 |
+
.modal-actions {
|
| 1386 |
+
display: flex;
|
| 1387 |
+
align-items: center;
|
| 1388 |
+
gap: 8px;
|
| 1389 |
+
}
|
| 1390 |
+
.btn {
|
| 1391 |
+
font-family: var(--sans);
|
| 1392 |
+
font-size: 13.5px;
|
| 1393 |
+
font-weight: 600;
|
| 1394 |
+
border: 1px solid var(--line);
|
| 1395 |
+
background: var(--panel);
|
| 1396 |
+
color: var(--ink);
|
| 1397 |
+
border-radius: 9px;
|
| 1398 |
+
padding: 8px 13px;
|
| 1399 |
+
cursor: pointer;
|
| 1400 |
+
transition: background 0.12s, border-color 0.12s, color 0.12s;
|
| 1401 |
+
}
|
| 1402 |
+
.btn:hover {
|
| 1403 |
+
border-color: var(--accent);
|
| 1404 |
+
color: var(--accent-strong);
|
| 1405 |
+
}
|
| 1406 |
+
.btn.copied {
|
| 1407 |
+
border-color: #1a8a55;
|
| 1408 |
+
color: #1a8a55;
|
| 1409 |
+
}
|
| 1410 |
+
.btn.icon {
|
| 1411 |
+
font-size: 18px;
|
| 1412 |
+
line-height: 1;
|
| 1413 |
+
padding: 6px 11px;
|
| 1414 |
+
font-weight: 400;
|
| 1415 |
+
}
|
| 1416 |
+
.modal-body {
|
| 1417 |
+
padding: 20px 22px 26px;
|
| 1418 |
+
}
|
| 1419 |
+
.modal-intro {
|
| 1420 |
+
margin: 0 0 20px;
|
| 1421 |
+
color: var(--muted);
|
| 1422 |
+
line-height: 1.55;
|
| 1423 |
+
}
|
| 1424 |
+
#connect-steps {
|
| 1425 |
+
list-style: none;
|
| 1426 |
+
margin: 0;
|
| 1427 |
+
padding: 0;
|
| 1428 |
+
}
|
| 1429 |
+
#connect-steps li {
|
| 1430 |
+
margin-bottom: 18px;
|
| 1431 |
+
}
|
| 1432 |
+
.step-title {
|
| 1433 |
+
font-weight: 600;
|
| 1434 |
+
font-size: 14.5px;
|
| 1435 |
+
margin-bottom: 8px;
|
| 1436 |
+
}
|
| 1437 |
+
.codeblock {
|
| 1438 |
+
display: flex;
|
| 1439 |
+
align-items: center;
|
| 1440 |
+
gap: 8px;
|
| 1441 |
+
background: #17181c;
|
| 1442 |
+
border-radius: 10px;
|
| 1443 |
+
padding: 11px 12px 11px 15px;
|
| 1444 |
+
}
|
| 1445 |
+
.codeblock code {
|
| 1446 |
+
flex: 1;
|
| 1447 |
+
min-width: 0;
|
| 1448 |
+
overflow-x: auto;
|
| 1449 |
+
white-space: nowrap;
|
| 1450 |
+
font-family: var(--mono);
|
| 1451 |
+
font-size: 13px;
|
| 1452 |
+
color: #f0efff;
|
| 1453 |
+
background: none;
|
| 1454 |
+
padding: 0;
|
| 1455 |
+
}
|
| 1456 |
+
.codeblock .copy {
|
| 1457 |
+
flex: 0 0 auto;
|
| 1458 |
+
background: rgba(255, 255, 255, 0.08);
|
| 1459 |
+
color: #c3c4cb;
|
| 1460 |
+
border: 1px solid rgba(255, 255, 255, 0.14);
|
| 1461 |
+
border-radius: 7px;
|
| 1462 |
+
width: 30px;
|
| 1463 |
+
height: 30px;
|
| 1464 |
+
font-size: 14px;
|
| 1465 |
+
cursor: pointer;
|
| 1466 |
+
transition: background 0.12s, color 0.12s;
|
| 1467 |
+
}
|
| 1468 |
+
.codeblock .copy:hover {
|
| 1469 |
+
background: rgba(249, 115, 22, 0.2);
|
| 1470 |
+
color: #fdba74;
|
| 1471 |
+
}
|
| 1472 |
+
.codeblock .copy.copied {
|
| 1473 |
+
color: #52d08a;
|
| 1474 |
+
}
|
| 1475 |
+
|
| 1476 |
+
/* ---- top-level logbook views ---- */
|
| 1477 |
+
#view-tabs {
|
| 1478 |
+
position: sticky;
|
| 1479 |
+
top: 0;
|
| 1480 |
+
z-index: 30;
|
| 1481 |
+
width: 100%;
|
| 1482 |
+
max-width: 1080px;
|
| 1483 |
+
margin: 0 auto 24px;
|
| 1484 |
+
padding-top: 10px;
|
| 1485 |
+
display: flex;
|
| 1486 |
+
align-items: center;
|
| 1487 |
+
justify-content: flex-start;
|
| 1488 |
+
gap: 26px;
|
| 1489 |
+
border-bottom: 1px solid var(--line);
|
| 1490 |
+
background: var(--paper);
|
| 1491 |
+
}
|
| 1492 |
+
#view-tabs a {
|
| 1493 |
+
display: inline-flex;
|
| 1494 |
+
align-items: center;
|
| 1495 |
+
gap: 8px;
|
| 1496 |
+
min-height: 44px;
|
| 1497 |
+
margin-bottom: -1px;
|
| 1498 |
+
color: var(--muted);
|
| 1499 |
+
border-bottom: 2px solid transparent;
|
| 1500 |
+
text-decoration: none;
|
| 1501 |
+
font-size: 13.5px;
|
| 1502 |
+
font-weight: 600;
|
| 1503 |
+
transition: color 0.12s, border-color 0.12s;
|
| 1504 |
+
}
|
| 1505 |
+
#view-tabs a:hover {
|
| 1506 |
+
color: var(--ink);
|
| 1507 |
+
}
|
| 1508 |
+
#view-tabs a.active {
|
| 1509 |
+
color: var(--accent-strong);
|
| 1510 |
+
border-bottom-color: var(--accent);
|
| 1511 |
+
}
|
| 1512 |
+
#view-tabs svg {
|
| 1513 |
+
width: 18px;
|
| 1514 |
+
height: 18px;
|
| 1515 |
+
flex: 0 0 auto;
|
| 1516 |
+
fill: none;
|
| 1517 |
+
stroke: currentColor;
|
| 1518 |
+
stroke-width: 2;
|
| 1519 |
+
stroke-linecap: round;
|
| 1520 |
+
stroke-linejoin: round;
|
| 1521 |
+
}
|
| 1522 |
+
.workspace-file svg,
|
| 1523 |
+
.workspace-folder summary svg,
|
| 1524 |
+
.workspace-download svg {
|
| 1525 |
+
width: 17px;
|
| 1526 |
+
height: 17px;
|
| 1527 |
+
flex: 0 0 auto;
|
| 1528 |
+
fill: none;
|
| 1529 |
+
stroke: currentColor;
|
| 1530 |
+
stroke-width: 1.7;
|
| 1531 |
+
stroke-linecap: round;
|
| 1532 |
+
stroke-linejoin: round;
|
| 1533 |
+
}
|
| 1534 |
+
|
| 1535 |
+
#page.trace-page,
|
| 1536 |
+
#page.workspace-page {
|
| 1537 |
+
max-width: 1080px;
|
| 1538 |
+
}
|
| 1539 |
+
.view-loading {
|
| 1540 |
+
padding: 72px 0;
|
| 1541 |
+
color: var(--muted);
|
| 1542 |
+
text-align: center;
|
| 1543 |
+
}
|
| 1544 |
+
.view-empty {
|
| 1545 |
+
margin: 48px 0;
|
| 1546 |
+
padding: 44px 28px;
|
| 1547 |
+
border: 1px dashed #d8dbe1;
|
| 1548 |
+
border-radius: var(--radius);
|
| 1549 |
+
background: rgba(255, 255, 255, 0.72);
|
| 1550 |
+
text-align: center;
|
| 1551 |
+
}
|
| 1552 |
+
.view-empty h2 {
|
| 1553 |
+
margin: 0 0 7px;
|
| 1554 |
+
font-size: 18px;
|
| 1555 |
+
}
|
| 1556 |
+
.view-empty p {
|
| 1557 |
+
max-width: 560px;
|
| 1558 |
+
margin: 0 auto;
|
| 1559 |
+
color: var(--muted);
|
| 1560 |
+
}
|
| 1561 |
+
.view-empty code {
|
| 1562 |
+
display: inline-block;
|
| 1563 |
+
margin-top: 18px;
|
| 1564 |
+
padding: 7px 10px;
|
| 1565 |
+
border-radius: 7px;
|
| 1566 |
+
background: var(--code-bg);
|
| 1567 |
+
font-family: var(--mono);
|
| 1568 |
+
font-size: 12px;
|
| 1569 |
+
}
|
| 1570 |
+
#page .repo-ref-link {
|
| 1571 |
+
display: inline-block;
|
| 1572 |
+
margin-top: 18px;
|
| 1573 |
+
padding: 8px 14px;
|
| 1574 |
+
border-radius: 8px;
|
| 1575 |
+
background: var(--accent-strong, #2158d0);
|
| 1576 |
+
color: #fff;
|
| 1577 |
+
font-weight: 600;
|
| 1578 |
+
text-decoration: none;
|
| 1579 |
+
}
|
| 1580 |
+
#page .repo-ref-link:hover,
|
| 1581 |
+
#page .repo-ref-link:focus-visible {
|
| 1582 |
+
color: #fff;
|
| 1583 |
+
filter: brightness(0.95);
|
| 1584 |
+
}
|
| 1585 |
+
.view-eyebrow {
|
| 1586 |
+
margin-bottom: 4px;
|
| 1587 |
+
color: var(--accent-strong);
|
| 1588 |
+
font-family: var(--mono);
|
| 1589 |
+
font-size: 11px;
|
| 1590 |
+
font-weight: 700;
|
| 1591 |
+
letter-spacing: 0.12em;
|
| 1592 |
+
text-transform: uppercase;
|
| 1593 |
+
}
|
| 1594 |
+
|
| 1595 |
+
/* ---- trace ---- */
|
| 1596 |
+
.trace-session {
|
| 1597 |
+
scroll-margin-top: 24px;
|
| 1598 |
+
}
|
| 1599 |
+
.trace-session + .trace-session {
|
| 1600 |
+
margin-top: 44px;
|
| 1601 |
+
padding-top: 40px;
|
| 1602 |
+
border-top: 1px solid var(--line);
|
| 1603 |
+
}
|
| 1604 |
+
.trace-session-title {
|
| 1605 |
+
margin: 0 0 14px;
|
| 1606 |
+
color: var(--ink);
|
| 1607 |
+
font-family: var(--serif);
|
| 1608 |
+
font-size: 22px;
|
| 1609 |
+
line-height: 1.2;
|
| 1610 |
+
letter-spacing: -0.02em;
|
| 1611 |
+
overflow-wrap: anywhere;
|
| 1612 |
+
}
|
| 1613 |
+
.workspace-header h1 {
|
| 1614 |
+
margin: 0;
|
| 1615 |
+
color: var(--ink);
|
| 1616 |
+
font-size: 30px;
|
| 1617 |
+
line-height: 1.2;
|
| 1618 |
+
letter-spacing: -0.025em;
|
| 1619 |
+
}
|
| 1620 |
+
.trace-meta {
|
| 1621 |
+
display: flex;
|
| 1622 |
+
flex-wrap: wrap;
|
| 1623 |
+
gap: 9px 20px;
|
| 1624 |
+
margin-bottom: 34px;
|
| 1625 |
+
padding: 14px 16px;
|
| 1626 |
+
border: 1px solid var(--line);
|
| 1627 |
+
border-radius: 10px;
|
| 1628 |
+
background: rgba(255, 255, 255, 0.78);
|
| 1629 |
+
color: var(--muted);
|
| 1630 |
+
font-family: var(--mono);
|
| 1631 |
+
font-size: 11px;
|
| 1632 |
+
}
|
| 1633 |
+
.trace-meta strong {
|
| 1634 |
+
color: var(--ink);
|
| 1635 |
+
font-weight: 650;
|
| 1636 |
+
}
|
| 1637 |
+
.trace-source-missing {
|
| 1638 |
+
color: #b45309;
|
| 1639 |
+
}
|
| 1640 |
+
.trace-timeline {
|
| 1641 |
+
position: relative;
|
| 1642 |
+
}
|
| 1643 |
+
.trace-timeline::before {
|
| 1644 |
+
content: "";
|
| 1645 |
+
position: absolute;
|
| 1646 |
+
top: 0;
|
| 1647 |
+
bottom: 0;
|
| 1648 |
+
left: 82px;
|
| 1649 |
+
width: 1px;
|
| 1650 |
+
background: #dedfe3;
|
| 1651 |
+
}
|
| 1652 |
+
.trace-load-controls {
|
| 1653 |
+
display: flex;
|
| 1654 |
+
align-items: center;
|
| 1655 |
+
justify-content: space-between;
|
| 1656 |
+
gap: 16px;
|
| 1657 |
+
margin: 22px 0 0 100px;
|
| 1658 |
+
padding-top: 16px;
|
| 1659 |
+
border-top: 1px solid var(--line);
|
| 1660 |
+
}
|
| 1661 |
+
.trace-load-progress {
|
| 1662 |
+
color: var(--muted);
|
| 1663 |
+
font-family: var(--mono);
|
| 1664 |
+
font-size: 11px;
|
| 1665 |
+
}
|
| 1666 |
+
.trace-load-more {
|
| 1667 |
+
padding: 7px 12px;
|
| 1668 |
+
border: 1px solid var(--line-strong);
|
| 1669 |
+
border-radius: 7px;
|
| 1670 |
+
background: var(--paper);
|
| 1671 |
+
color: var(--ink);
|
| 1672 |
+
cursor: pointer;
|
| 1673 |
+
font: 650 12px/1.2 var(--sans);
|
| 1674 |
+
}
|
| 1675 |
+
.trace-load-more:hover:not(:disabled) {
|
| 1676 |
+
border-color: var(--accent);
|
| 1677 |
+
color: var(--accent-strong);
|
| 1678 |
+
}
|
| 1679 |
+
.trace-load-more:disabled {
|
| 1680 |
+
cursor: default;
|
| 1681 |
+
opacity: 0.65;
|
| 1682 |
+
}
|
| 1683 |
+
.trace-entry {
|
| 1684 |
+
--trace-depth: 0;
|
| 1685 |
+
position: relative;
|
| 1686 |
+
display: grid;
|
| 1687 |
+
grid-template-columns: 100px minmax(0, 1fr);
|
| 1688 |
+
margin: 0 0 18px calc(var(--trace-depth) * 24px);
|
| 1689 |
+
}
|
| 1690 |
+
.trace-rail {
|
| 1691 |
+
position: relative;
|
| 1692 |
+
min-height: 36px;
|
| 1693 |
+
padding: 4px 28px 0 0;
|
| 1694 |
+
color: #8a8d95;
|
| 1695 |
+
text-align: right;
|
| 1696 |
+
font-family: var(--mono);
|
| 1697 |
+
}
|
| 1698 |
+
.trace-number,
|
| 1699 |
+
.trace-elapsed {
|
| 1700 |
+
display: block;
|
| 1701 |
+
white-space: nowrap;
|
| 1702 |
+
}
|
| 1703 |
+
.trace-number {
|
| 1704 |
+
font-size: 12px;
|
| 1705 |
+
font-weight: 650;
|
| 1706 |
+
}
|
| 1707 |
+
.trace-elapsed {
|
| 1708 |
+
margin-top: 3px;
|
| 1709 |
+
font-size: 10px;
|
| 1710 |
+
}
|
| 1711 |
+
.trace-dot {
|
| 1712 |
+
position: absolute;
|
| 1713 |
+
top: 10px;
|
| 1714 |
+
right: 11px;
|
| 1715 |
+
width: 11px;
|
| 1716 |
+
height: 11px;
|
| 1717 |
+
border: 2px solid var(--paper);
|
| 1718 |
+
border-radius: 50%;
|
| 1719 |
+
background: var(--accent);
|
| 1720 |
+
box-shadow: 0 0 0 1px #d7d9de;
|
| 1721 |
+
}
|
| 1722 |
+
.trace-card {
|
| 1723 |
+
min-width: 0;
|
| 1724 |
+
overflow: hidden;
|
| 1725 |
+
border: 1px solid #dddfe4;
|
| 1726 |
+
border-radius: 11px;
|
| 1727 |
+
background: rgba(255, 255, 255, 0.92);
|
| 1728 |
+
}
|
| 1729 |
+
.trace-card > header {
|
| 1730 |
+
display: flex;
|
| 1731 |
+
align-items: center;
|
| 1732 |
+
gap: 10px;
|
| 1733 |
+
min-height: 37px;
|
| 1734 |
+
padding: 8px 13px;
|
| 1735 |
+
border-bottom: 1px solid #eceef1;
|
| 1736 |
+
}
|
| 1737 |
+
.trace-status .trace-card > header {
|
| 1738 |
+
border-bottom: 0;
|
| 1739 |
+
padding-bottom: 5px;
|
| 1740 |
+
}
|
| 1741 |
+
.trace-kind {
|
| 1742 |
+
font-family: var(--mono);
|
| 1743 |
+
font-size: 10.5px;
|
| 1744 |
+
font-weight: 750;
|
| 1745 |
+
letter-spacing: 0.08em;
|
| 1746 |
+
text-transform: uppercase;
|
| 1747 |
+
}
|
| 1748 |
+
.trace-turn {
|
| 1749 |
+
color: var(--muted);
|
| 1750 |
+
font: 10px var(--mono);
|
| 1751 |
+
}
|
| 1752 |
+
.trace-status-badge {
|
| 1753 |
+
margin-left: auto;
|
| 1754 |
+
padding: 1px 6px;
|
| 1755 |
+
border-radius: 999px;
|
| 1756 |
+
background: #eef0f3;
|
| 1757 |
+
color: var(--muted);
|
| 1758 |
+
font: 9.5px var(--mono);
|
| 1759 |
+
text-transform: uppercase;
|
| 1760 |
+
}
|
| 1761 |
+
.trace-status-badge-error,
|
| 1762 |
+
.trace-status-badge-failed {
|
| 1763 |
+
background: #fef2f2;
|
| 1764 |
+
color: #b91c1c;
|
| 1765 |
+
}
|
| 1766 |
+
.trace-body {
|
| 1767 |
+
margin: 0;
|
| 1768 |
+
padding: 15px 17px 17px;
|
| 1769 |
+
overflow-wrap: anywhere;
|
| 1770 |
+
white-space: pre-wrap;
|
| 1771 |
+
font-family: var(--sans);
|
| 1772 |
+
font-size: 13px;
|
| 1773 |
+
line-height: 1.65;
|
| 1774 |
+
}
|
| 1775 |
+
.trace-reasoning .trace-card {
|
| 1776 |
+
border-style: dashed;
|
| 1777 |
+
border-color: #d7b98a;
|
| 1778 |
+
background: #fffdf8;
|
| 1779 |
+
}
|
| 1780 |
+
.trace-reasoning .trace-kind {
|
| 1781 |
+
color: #9a6b22;
|
| 1782 |
+
}
|
| 1783 |
+
.trace-reasoning .trace-body {
|
| 1784 |
+
font-style: italic;
|
| 1785 |
+
}
|
| 1786 |
+
.trace-user .trace-card {
|
| 1787 |
+
border-left: 3px solid #f3a66d;
|
| 1788 |
+
}
|
| 1789 |
+
.trace-tool_call .trace-card,
|
| 1790 |
+
.trace-tool_result .trace-card {
|
| 1791 |
+
border-color: #2d3036;
|
| 1792 |
+
background: #191a1e;
|
| 1793 |
+
color: #ececf0;
|
| 1794 |
+
}
|
| 1795 |
+
.trace-tool_call .trace-card > header,
|
| 1796 |
+
.trace-tool_result .trace-card > header {
|
| 1797 |
+
border-bottom-color: rgba(255, 255, 255, 0.1);
|
| 1798 |
+
}
|
| 1799 |
+
.trace-tool_call .trace-kind,
|
| 1800 |
+
.trace-tool_result .trace-kind {
|
| 1801 |
+
color: #f5a66d;
|
| 1802 |
+
}
|
| 1803 |
+
.trace-tool_call .trace-turn,
|
| 1804 |
+
.trace-tool_result .trace-turn {
|
| 1805 |
+
color: #979aa3;
|
| 1806 |
+
}
|
| 1807 |
+
.trace-tool_call .trace-body,
|
| 1808 |
+
.trace-tool_result .trace-body,
|
| 1809 |
+
.trace-output pre {
|
| 1810 |
+
font-family: var(--mono);
|
| 1811 |
+
font-size: 11.5px;
|
| 1812 |
+
line-height: 1.6;
|
| 1813 |
+
}
|
| 1814 |
+
#page .trace-tool_call pre.trace-body,
|
| 1815 |
+
#page .trace-tool_result pre.trace-body {
|
| 1816 |
+
margin: 0;
|
| 1817 |
+
padding: 15px 17px 17px;
|
| 1818 |
+
border: 0;
|
| 1819 |
+
border-radius: 0;
|
| 1820 |
+
background: transparent;
|
| 1821 |
+
color: #ececf0;
|
| 1822 |
+
}
|
| 1823 |
+
.trace-output {
|
| 1824 |
+
border-top: 1px dashed rgba(255, 255, 255, 0.14);
|
| 1825 |
+
}
|
| 1826 |
+
.trace-output summary {
|
| 1827 |
+
padding: 9px 14px;
|
| 1828 |
+
color: #aaaeb7;
|
| 1829 |
+
cursor: pointer;
|
| 1830 |
+
font: 700 10px var(--mono);
|
| 1831 |
+
letter-spacing: 0.06em;
|
| 1832 |
+
text-transform: uppercase;
|
| 1833 |
+
}
|
| 1834 |
+
#page .trace-output pre {
|
| 1835 |
+
max-height: 480px;
|
| 1836 |
+
margin: 0;
|
| 1837 |
+
padding: 0 16px 16px;
|
| 1838 |
+
border: 0;
|
| 1839 |
+
border-radius: 0;
|
| 1840 |
+
background: transparent;
|
| 1841 |
+
overflow: auto;
|
| 1842 |
+
color: #d7d8dd;
|
| 1843 |
+
white-space: pre-wrap;
|
| 1844 |
+
}
|
| 1845 |
+
|
| 1846 |
+
/* ---- workspace ---- */
|
| 1847 |
+
.workspace-header {
|
| 1848 |
+
padding-bottom: 24px;
|
| 1849 |
+
}
|
| 1850 |
+
.workspace-header p {
|
| 1851 |
+
margin: 0;
|
| 1852 |
+
color: var(--muted);
|
| 1853 |
+
font-family: var(--mono);
|
| 1854 |
+
font-size: 11px;
|
| 1855 |
+
}
|
| 1856 |
+
.workspace-inventory {
|
| 1857 |
+
overflow: hidden;
|
| 1858 |
+
border: 1px solid var(--line);
|
| 1859 |
+
border-radius: 11px;
|
| 1860 |
+
background: rgba(255, 255, 255, 0.92);
|
| 1861 |
+
}
|
| 1862 |
+
.workspace-folder > summary {
|
| 1863 |
+
display: flex;
|
| 1864 |
+
align-items: center;
|
| 1865 |
+
gap: 8px;
|
| 1866 |
+
min-height: 39px;
|
| 1867 |
+
padding: 8px 13px;
|
| 1868 |
+
background: #fafafa;
|
| 1869 |
+
cursor: pointer;
|
| 1870 |
+
font-weight: 650;
|
| 1871 |
+
list-style: none;
|
| 1872 |
+
}
|
| 1873 |
+
.workspace-folder > summary::-webkit-details-marker {
|
| 1874 |
+
display: none;
|
| 1875 |
+
}
|
| 1876 |
+
.workspace-folder > summary::after {
|
| 1877 |
+
content: "›";
|
| 1878 |
+
margin-left: auto;
|
| 1879 |
+
color: #989ba2;
|
| 1880 |
+
transform: rotate(90deg);
|
| 1881 |
+
}
|
| 1882 |
+
.workspace-folder:not([open]) > summary::after {
|
| 1883 |
+
transform: rotate(0);
|
| 1884 |
+
}
|
| 1885 |
+
.workspace-folder-children {
|
| 1886 |
+
padding-left: 20px;
|
| 1887 |
+
}
|
| 1888 |
+
.workspace-file {
|
| 1889 |
+
display: grid;
|
| 1890 |
+
grid-template-columns: minmax(180px, 1fr) 72px 78px 180px 36px;
|
| 1891 |
+
align-items: center;
|
| 1892 |
+
min-height: 44px;
|
| 1893 |
+
padding: 7px 10px 7px 13px;
|
| 1894 |
+
color: var(--muted);
|
| 1895 |
+
font-family: var(--mono);
|
| 1896 |
+
font-size: 10.5px;
|
| 1897 |
+
}
|
| 1898 |
+
.workspace-file-name {
|
| 1899 |
+
display: flex;
|
| 1900 |
+
align-items: center;
|
| 1901 |
+
min-width: 0;
|
| 1902 |
+
gap: 8px;
|
| 1903 |
+
color: var(--ink);
|
| 1904 |
+
font-family: var(--sans);
|
| 1905 |
+
font-size: 12.5px;
|
| 1906 |
+
font-weight: 550;
|
| 1907 |
+
}
|
| 1908 |
+
.workspace-file-name span {
|
| 1909 |
+
overflow: hidden;
|
| 1910 |
+
text-overflow: ellipsis;
|
| 1911 |
+
white-space: nowrap;
|
| 1912 |
+
}
|
| 1913 |
+
.workspace-file-type {
|
| 1914 |
+
width: fit-content;
|
| 1915 |
+
padding: 1px 6px;
|
| 1916 |
+
border-radius: 999px;
|
| 1917 |
+
background: var(--accent-soft);
|
| 1918 |
+
color: var(--accent-strong);
|
| 1919 |
+
text-transform: uppercase;
|
| 1920 |
+
}
|
| 1921 |
+
.workspace-download {
|
| 1922 |
+
display: inline-flex;
|
| 1923 |
+
align-items: center;
|
| 1924 |
+
justify-content: center;
|
| 1925 |
+
width: 30px;
|
| 1926 |
+
height: 30px;
|
| 1927 |
+
border-radius: 7px;
|
| 1928 |
+
color: var(--muted);
|
| 1929 |
+
}
|
| 1930 |
+
.workspace-download:hover {
|
| 1931 |
+
background: var(--accent-soft);
|
| 1932 |
+
color: var(--accent-strong);
|
| 1933 |
+
}
|
| 1934 |
+
.workspace-unpublished {
|
| 1935 |
+
color: #9ca3af;
|
| 1936 |
+
text-align: center;
|
| 1937 |
+
}
|
| 1938 |
+
|
| 1939 |
+
.workspace-header {
|
| 1940 |
+
display: flex;
|
| 1941 |
+
align-items: center;
|
| 1942 |
+
justify-content: space-between;
|
| 1943 |
+
gap: 16px;
|
| 1944 |
+
flex-wrap: wrap;
|
| 1945 |
+
}
|
| 1946 |
+
.workspace-toggle {
|
| 1947 |
+
display: inline-flex;
|
| 1948 |
+
align-items: center;
|
| 1949 |
+
padding: 2px;
|
| 1950 |
+
border: 1px solid var(--line);
|
| 1951 |
+
border-radius: 999px;
|
| 1952 |
+
background: #fafafa;
|
| 1953 |
+
}
|
| 1954 |
+
.workspace-toggle-btn {
|
| 1955 |
+
padding: 4px 13px;
|
| 1956 |
+
border: 0;
|
| 1957 |
+
border-radius: 999px;
|
| 1958 |
+
background: transparent;
|
| 1959 |
+
color: var(--muted);
|
| 1960 |
+
font-family: var(--sans);
|
| 1961 |
+
font-size: 12px;
|
| 1962 |
+
font-weight: 600;
|
| 1963 |
+
cursor: pointer;
|
| 1964 |
+
}
|
| 1965 |
+
.workspace-toggle-btn:hover {
|
| 1966 |
+
color: var(--accent-strong);
|
| 1967 |
+
}
|
| 1968 |
+
.workspace-toggle-btn.is-active {
|
| 1969 |
+
background: var(--accent);
|
| 1970 |
+
color: #ffffff;
|
| 1971 |
+
}
|
| 1972 |
+
.workspace-group + .workspace-group {
|
| 1973 |
+
margin-top: 18px;
|
| 1974 |
+
}
|
| 1975 |
+
.workspace-group-head,
|
| 1976 |
+
.workspace-hub-group-head {
|
| 1977 |
+
display: flex;
|
| 1978 |
+
align-items: center;
|
| 1979 |
+
gap: 8px;
|
| 1980 |
+
margin: 0;
|
| 1981 |
+
padding: 8px 13px;
|
| 1982 |
+
background: #fafafa;
|
| 1983 |
+
border-bottom: 1px solid var(--line);
|
| 1984 |
+
color: var(--ink);
|
| 1985 |
+
font-family: var(--sans);
|
| 1986 |
+
font-size: 12px;
|
| 1987 |
+
font-weight: 650;
|
| 1988 |
+
text-transform: capitalize;
|
| 1989 |
+
}
|
| 1990 |
+
.workspace-group-count,
|
| 1991 |
+
.workspace-hub-count {
|
| 1992 |
+
padding: 0 7px;
|
| 1993 |
+
border-radius: 999px;
|
| 1994 |
+
background: var(--accent-soft);
|
| 1995 |
+
color: var(--accent-strong);
|
| 1996 |
+
font-family: var(--mono);
|
| 1997 |
+
font-size: 10.5px;
|
| 1998 |
+
}
|
| 1999 |
+
.workspace-group {
|
| 2000 |
+
overflow: hidden;
|
| 2001 |
+
border: 1px solid var(--line);
|
| 2002 |
+
border-radius: 11px;
|
| 2003 |
+
background: rgba(255, 255, 255, 0.92);
|
| 2004 |
+
}
|
| 2005 |
+
|
| 2006 |
+
.workspace-hub {
|
| 2007 |
+
margin-top: 28px;
|
| 2008 |
+
}
|
| 2009 |
+
.workspace-hub-title {
|
| 2010 |
+
margin: 0 0 14px;
|
| 2011 |
+
font-family: var(--sans);
|
| 2012 |
+
font-size: 16px;
|
| 2013 |
+
font-weight: 700;
|
| 2014 |
+
color: var(--ink);
|
| 2015 |
+
}
|
| 2016 |
+
.workspace-hub-group {
|
| 2017 |
+
overflow: hidden;
|
| 2018 |
+
border: 1px solid var(--line);
|
| 2019 |
+
border-radius: 11px;
|
| 2020 |
+
background: rgba(255, 255, 255, 0.92);
|
| 2021 |
+
}
|
| 2022 |
+
.workspace-hub-group + .workspace-hub-group {
|
| 2023 |
+
margin-top: 14px;
|
| 2024 |
+
}
|
| 2025 |
+
.workspace-hub-list {
|
| 2026 |
+
display: flex;
|
| 2027 |
+
flex-direction: column;
|
| 2028 |
+
}
|
| 2029 |
+
.workspace-hub-link {
|
| 2030 |
+
padding: 9px 13px;
|
| 2031 |
+
color: var(--accent-strong);
|
| 2032 |
+
font-family: var(--mono);
|
| 2033 |
+
font-size: 12px;
|
| 2034 |
+
text-decoration: none;
|
| 2035 |
+
overflow: hidden;
|
| 2036 |
+
text-overflow: ellipsis;
|
| 2037 |
+
white-space: nowrap;
|
| 2038 |
+
}
|
| 2039 |
+
.workspace-hub-link + .workspace-hub-link {
|
| 2040 |
+
border-top: 1px solid var(--line);
|
| 2041 |
+
}
|
| 2042 |
+
.workspace-hub-link:hover {
|
| 2043 |
+
background: var(--accent-soft);
|
| 2044 |
+
text-decoration: underline;
|
| 2045 |
+
}
|
| 2046 |
+
|
| 2047 |
+
/* --- UI nits --- */
|
| 2048 |
+
/* Flush group headers: #page h3/h2 (ID selectors) otherwise inject a top margin
|
| 2049 |
+
that, with overflow:hidden on the card, shows as whitespace above "Jobs" etc. */
|
| 2050 |
+
#page .workspace-hub-title {
|
| 2051 |
+
margin: 0 0 14px;
|
| 2052 |
+
}
|
| 2053 |
+
#page .workspace-hub-group-head,
|
| 2054 |
+
#page .workspace-group-head {
|
| 2055 |
+
margin: 0;
|
| 2056 |
+
}
|
| 2057 |
+
/* HF brand logo before the "Hugging Face artifacts" heading */
|
| 2058 |
+
.workspace-hub-title {
|
| 2059 |
+
display: flex;
|
| 2060 |
+
align-items: center;
|
| 2061 |
+
gap: 9px;
|
| 2062 |
+
}
|
| 2063 |
+
.workspace-hub-logo {
|
| 2064 |
+
width: 22px;
|
| 2065 |
+
height: 22px;
|
| 2066 |
+
flex: none;
|
| 2067 |
+
}
|
| 2068 |
+
/* Center empty-state placeholders (heading, body, command) */
|
| 2069 |
+
.view-empty {
|
| 2070 |
+
display: flex;
|
| 2071 |
+
flex-direction: column;
|
| 2072 |
+
align-items: center;
|
| 2073 |
+
}
|
| 2074 |
+
#page .view-empty h2,
|
| 2075 |
+
#page .view-empty p {
|
| 2076 |
+
text-align: center;
|
| 2077 |
+
}
|
| 2078 |
+
|
| 2079 |
+
@media (max-width: 720px) {
|
| 2080 |
+
#app {
|
| 2081 |
+
flex-direction: column;
|
| 2082 |
+
}
|
| 2083 |
+
#sidebar {
|
| 2084 |
+
width: 100%;
|
| 2085 |
+
flex: none;
|
| 2086 |
+
height: auto;
|
| 2087 |
+
position: static;
|
| 2088 |
+
}
|
| 2089 |
+
#content {
|
| 2090 |
+
display: block;
|
| 2091 |
+
width: 100%;
|
| 2092 |
+
padding: 28px 20px 80px;
|
| 2093 |
+
overflow-x: hidden;
|
| 2094 |
+
}
|
| 2095 |
+
#view-tabs {
|
| 2096 |
+
margin: 0 0 20px;
|
| 2097 |
+
gap: 18px;
|
| 2098 |
+
justify-content: flex-start;
|
| 2099 |
+
overflow-x: auto;
|
| 2100 |
+
}
|
| 2101 |
+
#view-tabs a {
|
| 2102 |
+
flex: 0 0 auto;
|
| 2103 |
+
}
|
| 2104 |
+
.trace-timeline::before {
|
| 2105 |
+
left: 16px;
|
| 2106 |
+
}
|
| 2107 |
+
.trace-entry {
|
| 2108 |
+
grid-template-columns: 32px minmax(0, 1fr);
|
| 2109 |
+
margin-left: calc(var(--trace-depth) * 10px);
|
| 2110 |
+
}
|
| 2111 |
+
.trace-rail {
|
| 2112 |
+
padding: 0;
|
| 2113 |
+
}
|
| 2114 |
+
.trace-number,
|
| 2115 |
+
.trace-elapsed {
|
| 2116 |
+
display: none;
|
| 2117 |
+
}
|
| 2118 |
+
.trace-dot {
|
| 2119 |
+
top: 10px;
|
| 2120 |
+
right: 10px;
|
| 2121 |
+
}
|
| 2122 |
+
.workspace-file {
|
| 2123 |
+
grid-template-columns: minmax(150px, 1fr) 66px 34px;
|
| 2124 |
+
}
|
| 2125 |
+
.workspace-file-size,
|
| 2126 |
+
.workspace-file-time {
|
| 2127 |
+
display: none;
|
| 2128 |
+
}
|
| 2129 |
+
#page {
|
| 2130 |
+
width: 100%;
|
| 2131 |
+
max-width: 100%;
|
| 2132 |
+
}
|
| 2133 |
+
#page h1,
|
| 2134 |
+
#logbook-title {
|
| 2135 |
+
font-size: 30px;
|
| 2136 |
+
}
|
| 2137 |
+
.cell-head {
|
| 2138 |
+
align-items: flex-start;
|
| 2139 |
+
flex-direction: column;
|
| 2140 |
+
gap: 4px;
|
| 2141 |
+
}
|
| 2142 |
+
}
|
logbook.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
logbook.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 2,
|
| 3 |
+
"title": "Reproduction: Adaptive Personalized Federated Learning via Multi-task Averaging of Kernel Mean Embeddings",
|
| 4 |
+
"emoji": "🎯",
|
| 5 |
+
"space_id": "vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding",
|
| 6 |
+
"paper": {
|
| 7 |
+
"arxiv_id": "2603.02233"
|
| 8 |
+
},
|
| 9 |
+
"tags": [
|
| 10 |
+
"icml2026-repro",
|
| 11 |
+
"paper-ADHGbxsREr"
|
| 12 |
+
],
|
| 13 |
+
"updated_at": "2026-07-28T06:21:29+00:00",
|
| 14 |
+
"root": {
|
| 15 |
+
"slug": "index",
|
| 16 |
+
"title": "Reproduction: Adaptive Personalized Federated Learning via Multi-task Averaging of Kernel Mean Embeddings",
|
| 17 |
+
"file": "pages/index.md",
|
| 18 |
+
"children": [
|
| 19 |
+
{
|
| 20 |
+
"slug": "executive-summary",
|
| 21 |
+
"title": "Executive summary",
|
| 22 |
+
"file": "pages/executive-summary/page.md",
|
| 23 |
+
"children": []
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"slug": "claim-1-theorem-4-4-finite-sample-kme-guarantee",
|
| 27 |
+
"title": "Claim 1: Theorem 4.4 finite-sample KME guarantee",
|
| 28 |
+
"file": "pages/claim-1-theorem-4-4-finite-sample-kme-guarantee/page.md",
|
| 29 |
+
"children": []
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"slug": "claim-2-corollary-4-6-downstream-excess-risk-transfer",
|
| 33 |
+
"title": "Claim 2: Corollary 4.6 downstream excess-risk transfer",
|
| 34 |
+
"file": "pages/claim-2-corollary-4-6-downstream-excess-risk-transfer/page.md",
|
| 35 |
+
"children": []
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"slug": "claim-3-example-4-5-automatic-adaptive-collaboration",
|
| 39 |
+
"title": "Claim 3: Example 4.5 automatic adaptive collaboration",
|
| 40 |
+
"file": "pages/claim-3-example-4-5-automatic-adaptive-collaboration/page.md",
|
| 41 |
+
"children": []
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"slug": "claim-4-theorem-5-2-random-fourier-feature-tradeoff",
|
| 45 |
+
"title": "Claim 4: Theorem 5.2 random Fourier-feature tradeoff",
|
| 46 |
+
"file": "pages/claim-4-theorem-5-2-random-fourier-feature-tradeoff/page.md",
|
| 47 |
+
"children": []
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"slug": "claim-5-section-6-1-100-agent-synthetic-concept-shift",
|
| 51 |
+
"title": "Claim 5: Section 6.1 100-agent synthetic concept shift",
|
| 52 |
+
"file": "pages/claim-5-section-6-1-100-agent-synthetic-concept-shift/page.md",
|
| 53 |
+
"children": []
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"slug": "claim-6-section-6-3-femnist-192-agent-benchmark",
|
| 57 |
+
"title": "Claim 6: Section 6.3 FEMNIST 192-agent benchmark",
|
| 58 |
+
"file": "pages/claim-6-section-6-3-femnist-192-agent-benchmark/page.md",
|
| 59 |
+
"children": []
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"slug": "conclusion",
|
| 63 |
+
"title": "Conclusion",
|
| 64 |
+
"file": "pages/conclusion/page.md",
|
| 65 |
+
"children": []
|
| 66 |
+
}
|
| 67 |
+
]
|
| 68 |
+
},
|
| 69 |
+
"traces": [],
|
| 70 |
+
"workspace": {
|
| 71 |
+
"file": "workspace.json",
|
| 72 |
+
"file_count": 0,
|
| 73 |
+
"total_size": 0,
|
| 74 |
+
"bucket_id": null
|
| 75 |
+
},
|
| 76 |
+
"agent_view_tokens": 4609,
|
| 77 |
+
"trace_view_tokens": 10,
|
| 78 |
+
"workspace_view_tokens": 48,
|
| 79 |
+
"revision": "da220efeb6d76cd226b2",
|
| 80 |
+
"workspace_ref": {
|
| 81 |
+
"repo_id": "vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts",
|
| 82 |
+
"repo_type": "bucket",
|
| 83 |
+
"repo_url": "https://huggingface.co/buckets/vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts",
|
| 84 |
+
"private": true
|
| 85 |
+
},
|
| 86 |
+
"workspace_bucket": "https://huggingface.co/buckets/vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts"
|
| 87 |
+
}
|
pages/claim-1-theorem-4-4-finite-sample-kme-guarantee/page.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Claim 1: Theorem 4.4 finite-sample KME guarantee
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
---
|
| 5 |
+
<!-- trackio-cell
|
| 6 |
+
{"type": "markdown", "id": "cell_069091946489", "created_at": "2026-07-19T09:32:03+00:00", "title": "Claim 1: Theorem 4.4 finite-sample KME guarantee"}
|
| 7 |
+
-->
|
| 8 |
+
Document setup, runs, and results for **Claim 1: Theorem 4.4 finite-sample KME guarantee**.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
<!-- trackio-cell
|
| 13 |
+
{"type": "markdown", "id": "cell_40b9d46f1306", "created_at": "2026-07-19T09:54:23+00:00", "title": "Evidence and status"}
|
| 14 |
+
-->
|
| 15 |
+
The source theorem was checked against the [arXiv PDF](https://arxiv.org/pdf/2603.02233), Theorem 4.4 (Eq. 14–15). For every subset containing target agent 1, it bounds expected squared MMD by a bias term , variance , and lower-order terms involving , , and effective dimension. This directly establishes the stated bias–variance tradeoff. **Status: source-verified theorem statement; not independently re-proven.**
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
---
|
| 19 |
+
<!-- trackio-cell
|
| 20 |
+
{"type": "markdown", "id": "cell_7efaad82fdef", "created_at": "2026-07-19T09:56:03+00:00", "title": "Clarified evidence"}
|
| 21 |
+
-->
|
| 22 |
+
Clarification: in Eq. 14, for every V containing agent 1, the leading terms are Delta_V squared plus (Tr Sigma_1 + 2 Delta_V)/n_V. Delta_V is the largest distributional MMD within V and n_V is the combined client sample size. The remaining terms depend on log(B n_1), |V|/n_V, and effective dimension. This is a direct source audit of https://arxiv.org/pdf/2603.02233, not an independent proof.
|
pages/claim-2-corollary-4-6-downstream-excess-risk-transfer/page.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Claim 2: Corollary 4.6 downstream excess-risk transfer
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
---
|
| 5 |
+
<!-- trackio-cell
|
| 6 |
+
{"type": "markdown", "id": "cell_6ed1cb9e8ba8", "created_at": "2026-07-19T09:32:03+00:00", "title": "Claim 2: Corollary 4.6 downstream excess-risk transfer"}
|
| 7 |
+
-->
|
| 8 |
+
Document setup, runs, and results for **Claim 2: Corollary 4.6 downstream excess-risk transfer**.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
<!-- trackio-cell
|
| 13 |
+
{"type": "markdown", "id": "cell_130e10d00f66", "created_at": "2026-07-19T09:54:23+00:00", "title": "Evidence and status"}
|
| 14 |
+
-->
|
| 15 |
+
[Corollary 4.6 in the arXiv PDF](https://arxiv.org/pdf/2603.02233) states . Its Appendix F.4 proof expands population and weighted empirical risks through KMEs, applies optimality of , then Cauchy–Schwarz twice. Thus the claimed direct transfer from KME estimation error to task excess risk is supported by the paper. **Status: source-verified theorem/proof audit; optimization error remains outside the corollary’s scope.**
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
---
|
| 19 |
+
<!-- trackio-cell
|
| 20 |
+
{"type": "markdown", "id": "cell_efe13b52d7af", "created_at": "2026-07-19T09:56:17+00:00", "title": "Clarified evidence"}
|
| 21 |
+
-->
|
| 22 |
+
Clarification: Corollary 4.6 gives expected target excess risk at most 2 R_Theta times expected MMD between the learned empirical mixture and P_1. Appendix F.4 derives it by KME risk representation, weighted empirical-risk optimality, and Cauchy-Schwarz. Source: https://arxiv.org/pdf/2603.02233 .
|
pages/claim-3-example-4-5-automatic-adaptive-collaboration/page.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Claim 3: Example 4.5 automatic adaptive collaboration
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
---
|
| 5 |
+
<!-- trackio-cell
|
| 6 |
+
{"type": "markdown", "id": "cell_3bda5e9c37b3", "created_at": "2026-07-19T09:32:03+00:00", "title": "Claim 3: Example 4.5 automatic adaptive collaboration"}
|
| 7 |
+
-->
|
| 8 |
+
Document setup, runs, and results for **Claim 3: Example 4.5 automatic adaptive collaboration**.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
<!-- trackio-cell
|
| 13 |
+
{"type": "markdown", "id": "cell_632280fed65b", "created_at": "2026-07-19T09:54:23+00:00", "title": "Evidence and status"}
|
| 14 |
+
-->
|
| 15 |
+
[Example 4.5](https://arxiv.org/pdf/2603.02233) specializes Theorem 4.4 to identical agents: the leading error becomes (up to lower-order terms), while returns the local rate. This verifies the stated oracle-style pooling/local regimes at the level of the theorem. In the independent implementation below (Claim 5), the literal RFF Q-objective did not recover the paper’s empirical transition; see that page for the non-replication result. **Status: source-verified asymptotic example; empirical adaptivity not reproduced by this implementation.**
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
---
|
| 19 |
+
<!-- trackio-cell
|
| 20 |
+
{"type": "markdown", "id": "cell_d6652be82cbd", "created_at": "2026-07-19T09:56:34+00:00", "title": "Clarified evidence"}
|
| 21 |
+
-->
|
| 22 |
+
Clarification: Example 4.5 gives leading KME error Tr Sigma_1/n_V for an identical-agent set V, whereas V={1} recovers Tr Sigma_1/n_1. It establishes the pooling versus local statistical regimes in theory. Source: https://arxiv.org/pdf/2603.02233 .
|
pages/claim-4-theorem-5-2-random-fourier-feature-tradeoff/page.md
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Claim 4: Theorem 5.2 random Fourier-feature tradeoff
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
---
|
| 5 |
+
<!-- trackio-cell
|
| 6 |
+
{"type": "markdown", "id": "cell_3385698671bb", "created_at": "2026-07-19T09:32:03+00:00", "title": "Claim 4: Theorem 5.2 random Fourier-feature tradeoff"}
|
| 7 |
+
-->
|
| 8 |
+
Document setup, runs, and results for **Claim 4: Theorem 5.2 random Fourier-feature tradeoff**.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
<!-- trackio-cell
|
| 13 |
+
{"type": "code", "id": "cell_e08f5b2ace5f", "created_at": "2026-07-19T09:53:12+00:00", "title": "Run: python reproduce.py (exit 0)", "command": ["/home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python", "src/reproduce.py", "rff", "--repeats", "100", "--rff-grid", "16", "32", "64", "128", "256", "512", "1024", "--output", "outputs/rff_tradeoff_100seeds.csv", "--device", "cuda"], "exit_code": 0, "duration_s": 1.465}
|
| 14 |
+
-->
|
| 15 |
+
````bash
|
| 16 |
+
$ /home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python src/reproduce.py rff --repeats 100 --rff-grid 16 32 64 128 256 512 1024 --output outputs/rff_tradeoff_100seeds.csv --device cuda
|
| 17 |
+
````
|
| 18 |
+
|
| 19 |
+
exit 0 · 1.5s
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
````python title=reproduce.py
|
| 23 |
+
#!/usr/bin/env python3
|
| 24 |
+
"""Independent, GPU-capable checks for Fermanian et al. (2026), arXiv:2603.02233.
|
| 25 |
+
|
| 26 |
+
The implementation follows Algorithms 1--2 at a scaled experimental budget. It
|
| 27 |
+
uses RFF KMEs to choose a target client's collaboration weights and fits the
|
| 28 |
+
weighted empirical-risk minimizer exactly for linear regression. The FEMNIST
|
| 29 |
+
mode uses the public natural writer partition and a linear softmax model.
|
| 30 |
+
"""
|
| 31 |
+
from __future__ import annotations
|
| 32 |
+
|
| 33 |
+
import argparse
|
| 34 |
+
import csv
|
| 35 |
+
import json
|
| 36 |
+
import math
|
| 37 |
+
from pathlib import Path
|
| 38 |
+
from time import perf_counter
|
| 39 |
+
|
| 40 |
+
import numpy as np
|
| 41 |
+
import torch
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def device_from_arg(name: str) -> torch.device:
|
| 48 |
+
if name == "auto":
|
| 49 |
+
return torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 50 |
+
return torch.device(name)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def rff(z: torch.Tensor, d_rff: int, generator: torch.Generator, scale: torch.Tensor) -> torch.Tensor:
|
| 54 |
+
"""Gaussian-kernel RFF, with a supplied coordinate rescaling."""
|
| 55 |
+
w = torch.randn((z.shape[1], d_rff), generator=generator, device=z.device, dtype=z.dtype)
|
| 56 |
+
w = w * scale[:, None]
|
| 57 |
+
b = 2 * math.pi * torch.rand((d_rff,), generator=generator, device=z.device, dtype=z.dtype)
|
| 58 |
+
return math.sqrt(2.0 / d_rff) * torch.cos(z @ w + b)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def simplex_weights(means: torch.Tensor, target_phi: torch.Tensor, steps: int = 900) -> torch.Tensor:
|
| 62 |
+
"""Solve Algorithm 1's empirical Q-aggregation objective by projected GD."""
|
| 63 |
+
b_agents = means.shape[0]
|
| 64 |
+
n1 = target_phi.shape[0]
|
| 65 |
+
centered = target_phi - means[0]
|
| 66 |
+
cov = centered.T @ centered / max(n1 - 1, 1)
|
| 67 |
+
trace = torch.trace(cov)
|
| 68 |
+
diffs = means[1:] - means[0]
|
| 69 |
+
q_terms = torch.sqrt(torch.clamp(torch.einsum("bd,df,bf->b", diffs, cov, diffs), min=0.0) + 1e-12)
|
| 70 |
+
p_terms = torch.linalg.vector_norm(diffs, dim=1)
|
| 71 |
+
# Table 1 uses CQ^2=CP=log B: CQ=sqrt(log B), CP=log B.
|
| 72 |
+
cq, cp = math.sqrt(math.log(b_agents)), math.log(b_agents)
|
| 73 |
+
w = torch.full((b_agents,), 1.0 / b_agents, device=means.device, dtype=means.dtype)
|
| 74 |
+
for _ in range(steps):
|
| 75 |
+
w.requires_grad_(True)
|
| 76 |
+
mixture = w @ means
|
| 77 |
+
loss = torch.sum((mixture - means[0]) ** 2) + 2.0 * w[0] * trace / n1
|
| 78 |
+
loss = loss + cq / math.sqrt(n1) * torch.dot(w[1:], q_terms)
|
| 79 |
+
loss = loss + cp / n1 * torch.dot(w[1:], p_terms)
|
| 80 |
+
(grad,) = torch.autograd.grad(loss, w)
|
| 81 |
+
with torch.no_grad():
|
| 82 |
+
# Euclidean projection on the simplex, Duchi et al. (2008).
|
| 83 |
+
v = w - 0.04 * grad
|
| 84 |
+
u, _ = torch.sort(v, descending=True)
|
| 85 |
+
cssv = torch.cumsum(u, 0) - 1
|
| 86 |
+
ind = torch.arange(1, b_agents + 1, device=v.device, dtype=v.dtype)
|
| 87 |
+
rho = torch.nonzero(u - cssv / ind > 0, as_tuple=False)[-1, 0]
|
| 88 |
+
theta = cssv[rho] / (rho + 1)
|
| 89 |
+
w = torch.clamp(v - theta, min=0)
|
| 90 |
+
return w.detach()
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def weighted_linear_fit(xs: torch.Tensor, ys: torch.Tensor, weights: torch.Tensor, ridge: float = 1e-3) -> torch.Tensor:
|
| 94 |
+
"""Exact weighted empirical-risk minimizer for linear regression."""
|
| 95 |
+
b_agents, n, dim = xs.shape
|
| 96 |
+
x = torch.cat([xs, torch.ones((b_agents, n, 1), device=xs.device, dtype=xs.dtype)], dim=-1)
|
| 97 |
+
sample_w = (weights[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 98 |
+
flat_x, flat_y = x.reshape(-1, dim + 1), ys.reshape(-1)
|
| 99 |
+
lhs = flat_x.T @ (flat_x * sample_w[:, None]) + ridge * torch.eye(dim + 1, device=xs.device)
|
| 100 |
+
rhs = flat_x.T @ (flat_y * sample_w)
|
| 101 |
+
return torch.linalg.solve(lhs, rhs)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def concept_trial(seed: int, sigma2: float, d_rff: int, device: torch.device) -> dict:
|
| 105 |
+
g = torch.Generator(device=device).manual_seed(seed)
|
| 106 |
+
b_agents, n, dim, n_test = 100, 10, 20, 1000
|
| 107 |
+
signs = torch.where(torch.rand((b_agents,), generator=g, device=device) > .5, 1., -1.)
|
| 108 |
+
beta0 = torch.randn((dim,), generator=g, device=device)
|
| 109 |
+
eps = torch.randn((b_agents, dim), generator=g, device=device)
|
| 110 |
+
betas = signs[:, None] * math.sqrt(1 - sigma2) * beta0 + math.sqrt(sigma2) * eps
|
| 111 |
+
x = 1.0 + torch.randn((b_agents, n, dim), generator=g, device=device)
|
| 112 |
+
y = torch.einsum("bnd,bd->bn", x, betas) + math.sqrt(2.0) * torch.randn((b_agents, n), generator=g, device=device)
|
| 113 |
+
x_test = 1.0 + torch.randn((n_test, dim), generator=g, device=device)
|
| 114 |
+
y_test = x_test @ betas[0] + math.sqrt(2.0) * torch.randn((n_test,), generator=g, device=device)
|
| 115 |
+
# The paper's weighted Gaussian KME kernel gives X a 1/sqrt(d) scaling.
|
| 116 |
+
z = torch.cat([x, y[..., None]], dim=-1).reshape(-1, dim + 1)
|
| 117 |
+
scale = torch.cat([torch.full((dim,), 1 / math.sqrt(dim), device=device), torch.ones((1,), device=device)])
|
| 118 |
+
phi = rff(z, d_rff, g, scale).reshape(b_agents, n, d_rff)
|
| 119 |
+
means = phi.mean(1)
|
| 120 |
+
q_w = simplex_weights(means, phi[0])
|
| 121 |
+
local = torch.zeros(b_agents, device=device); local[0] = 1
|
| 122 |
+
grand = torch.full((b_agents,), 1 / b_agents, device=device)
|
| 123 |
+
oracle = (signs == signs[0]).float(); oracle /= oracle.sum()
|
| 124 |
+
result = {"sigma2": sigma2, "seed": seed, "q_local_weight": float(q_w[0]),
|
| 125 |
+
"q_same_group_weight": float(q_w[signs == signs[0]].sum())}
|
| 126 |
+
for name, weights in [("local", local), ("grandmean", grand), ("oracle", oracle), ("qaggregation", q_w)]:
|
| 127 |
+
beta = weighted_linear_fit(x, y, weights)
|
| 128 |
+
pred = x_test @ beta[:-1] + beta[-1]
|
| 129 |
+
result[f"{name}_mse"] = float(torch.mean((pred - y_test) ** 2))
|
| 130 |
+
return result
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def run_concept(args: argparse.Namespace) -> list[dict]:
|
| 134 |
+
device = device_from_arg(args.device)
|
| 135 |
+
rows = []
|
| 136 |
+
for sigma2 in args.sigmas:
|
| 137 |
+
for rep in range(args.repeats):
|
| 138 |
+
rows.append(concept_trial(args.seed + rep * 101 + int(sigma2 * 1000), sigma2, args.rff_dim, device))
|
| 139 |
+
return rows
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def exact_rbf_mmd(x: torch.Tensor, y: torch.Tensor, bandwidth: float = 1.0) -> torch.Tensor:
|
| 143 |
+
def k(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
|
| 144 |
+
return torch.exp(-torch.cdist(a, b).square() / (2 * bandwidth * bandwidth))
|
| 145 |
+
return torch.sqrt(torch.clamp(k(x, x).mean() + k(y, y).mean() - 2 * k(x, y).mean(), min=0.0))
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def run_rff(args: argparse.Namespace) -> list[dict]:
|
| 149 |
+
device = device_from_arg(args.device)
|
| 150 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 151 |
+
x = torch.randn((300, 8), generator=g, device=device)
|
| 152 |
+
y = torch.randn((300, 8), generator=g, device=device) + torch.tensor([0.35] + [0.] * 7, device=device)
|
| 153 |
+
exact = float(exact_rbf_mmd(x, y))
|
| 154 |
+
rows = []
|
| 155 |
+
for d_rff in args.rff_grid:
|
| 156 |
+
errors = []
|
| 157 |
+
for trial in range(args.repeats):
|
| 158 |
+
tg = torch.Generator(device=device).manual_seed(args.seed + 1000 * d_rff + trial)
|
| 159 |
+
phi = rff(torch.cat([x, y]), d_rff, tg, torch.ones(8, device=device))
|
| 160 |
+
approx = torch.linalg.vector_norm(phi[:len(x)].mean(0) - phi[len(x):].mean(0)).item()
|
| 161 |
+
errors.append(abs(approx - exact))
|
| 162 |
+
rows.append({"rff_dim": d_rff, "exact_mmd": exact, "mean_abs_error": float(np.mean(errors)),
|
| 163 |
+
"std_abs_error": float(np.std(errors)), "sqrt_logB_over_D": math.sqrt(math.log(100) / d_rff),
|
| 164 |
+
"one_shot_floats_per_agent": d_rff})
|
| 165 |
+
return rows
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def run_femnist(args: argparse.Namespace) -> list[dict]:
|
| 169 |
+
"""Actual FEMNIST writer data, deliberately scaled in samples/features/epochs."""
|
| 170 |
+
from datasets import load_dataset
|
| 171 |
+
device = device_from_arg(args.device)
|
| 172 |
+
local_parquet = ROOT / "data" / "femnist" / "data" / "train-00000-of-00001.parquet"
|
| 173 |
+
dataset = load_dataset("parquet", data_files=str(local_parquet), split="train", streaming=True) if local_parquet.exists() else load_dataset("flwrlabs/femnist", split="train", streaming=True)
|
| 174 |
+
by_writer: dict[str, list[tuple[np.ndarray, int]]] = {}
|
| 175 |
+
want = args.agents
|
| 176 |
+
for ex in dataset:
|
| 177 |
+
writer = ex["writer_id"]
|
| 178 |
+
if writer not in by_writer and len(by_writer) >= want:
|
| 179 |
+
continue
|
| 180 |
+
if writer in by_writer or len(by_writer) < want:
|
| 181 |
+
by_writer.setdefault(writer, []).append((np.asarray(ex["image"], dtype=np.float32) / 255., int(ex["character"])))
|
| 182 |
+
if len(by_writer) >= want and all(len(v) >= args.train_per_agent + args.test_per_agent for v in by_writer.values()):
|
| 183 |
+
break
|
| 184 |
+
eligible = [v for v in by_writer.values() if len(v) >= args.train_per_agent + args.test_per_agent][:want]
|
| 185 |
+
if len(eligible) < want:
|
| 186 |
+
raise RuntimeError(f"Only found {len(eligible)} eligible writers; need {want}")
|
| 187 |
+
x_train = torch.tensor(np.stack([np.stack([a for a, _ in v[:args.train_per_agent]]) for v in eligible]), device=device)
|
| 188 |
+
y_train = torch.tensor(np.stack([[b for _, b in v[:args.train_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 189 |
+
x_test = torch.tensor(np.stack([np.stack([a for a, _ in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]]) for v in eligible]), device=device)
|
| 190 |
+
y_test = torch.tensor(np.stack([[b for _, b in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 191 |
+
b_agents, n, raw_dim = x_train.shape[0], x_train.shape[1], 784
|
| 192 |
+
flat = x_train.reshape(b_agents, n, raw_dim)
|
| 193 |
+
# Fixed random projection reduces the RFF input cost while retaining a reproducible vision proxy.
|
| 194 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 195 |
+
proj = torch.randn((raw_dim, args.feature_dim), generator=g, device=device) / math.sqrt(raw_dim)
|
| 196 |
+
features = flat @ proj
|
| 197 |
+
phi_all = rff(features.reshape(-1, args.feature_dim), args.rff_dim, g, torch.ones(args.feature_dim, device=device)).reshape(b_agents, n, args.rff_dim)
|
| 198 |
+
means = phi_all.mean(1)
|
| 199 |
+
# Fit one regularized softmax classifier for each target using its personalized weights.
|
| 200 |
+
rows = []
|
| 201 |
+
all_x = features.reshape(-1, args.feature_dim)
|
| 202 |
+
all_y = y_train.reshape(-1)
|
| 203 |
+
for target in range(b_agents):
|
| 204 |
+
weights = simplex_weights(means, phi_all[target], steps=300)
|
| 205 |
+
schemes = {"local": torch.nn.functional.one_hot(torch.tensor(target, device=device), b_agents).float(),
|
| 206 |
+
"grandmean": torch.full((b_agents,), 1 / b_agents, device=device), "qaggregation": weights}
|
| 207 |
+
test_feat = x_test[target].reshape(args.test_per_agent, raw_dim) @ proj
|
| 208 |
+
for name, w in schemes.items():
|
| 209 |
+
model = torch.zeros((args.feature_dim, 62), device=device, requires_grad=True)
|
| 210 |
+
opt = torch.optim.Adam([model], lr=args.lr, weight_decay=1e-4)
|
| 211 |
+
sample_w = (w[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 212 |
+
for _ in range(args.epochs):
|
| 213 |
+
opt.zero_grad()
|
| 214 |
+
losses = torch.nn.functional.cross_entropy(all_x @ model, all_y, reduction="none")
|
| 215 |
+
(losses * sample_w).sum().backward(); opt.step()
|
| 216 |
+
acc = ((test_feat @ model).argmax(1) == y_test[target]).float().mean().item()
|
| 217 |
+
rows.append({"agent": target, "method": name, "accuracy": acc, "q_local_weight": float(weights[target])})
|
| 218 |
+
return rows
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def write_rows(rows: list[dict], out: Path) -> None:
|
| 222 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 223 |
+
with out.open("w", newline="") as f:
|
| 224 |
+
writer = csv.DictWriter(f, fieldnames=list(rows[0]))
|
| 225 |
+
writer.writeheader(); writer.writerows(rows)
|
| 226 |
+
out.with_suffix(".json").write_text(json.dumps(rows, indent=2))
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def main() -> None:
|
| 230 |
+
p = argparse.ArgumentParser()
|
| 231 |
+
p.add_argument("mode", choices=["concept", "rff", "femnist"])
|
| 232 |
+
p.add_argument("--output", type=Path, required=True)
|
| 233 |
+
p.add_argument("--device", default="auto")
|
| 234 |
+
p.add_argument("--seed", type=int, default=20260719)
|
| 235 |
+
p.add_argument("--repeats", type=int, default=30)
|
| 236 |
+
p.add_argument("--rff-dim", type=int, default=500)
|
| 237 |
+
p.add_argument("--sigmas", type=float, nargs="+", default=[0., .1, .25, .5, .75, 1.])
|
| 238 |
+
p.add_argument("--rff-grid", type=int, nargs="+", default=[16, 32, 64, 128, 256, 512, 1024])
|
| 239 |
+
p.add_argument("--agents", type=int, default=192)
|
| 240 |
+
p.add_argument("--train-per-agent", type=int, default=32)
|
| 241 |
+
p.add_argument("--test-per-agent", type=int, default=16)
|
| 242 |
+
p.add_argument("--feature-dim", type=int, default=64)
|
| 243 |
+
p.add_argument("--epochs", type=int, default=20)
|
| 244 |
+
p.add_argument("--lr", type=float, default=.08)
|
| 245 |
+
args = p.parse_args()
|
| 246 |
+
started = perf_counter()
|
| 247 |
+
rows = {"concept": run_concept, "rff": run_rff, "femnist": run_femnist}[args.mode](args)
|
| 248 |
+
write_rows(rows, args.output)
|
| 249 |
+
if args.mode == "concept":
|
| 250 |
+
summary = {str(s): {k: float(np.mean([r[k] for r in rows if r["sigma2"] == s])) for k in ["local_mse", "grandmean_mse", "oracle_mse", "qaggregation_mse", "q_local_weight", "q_same_group_weight"]} for s in args.sigmas}
|
| 251 |
+
print(json.dumps({"concept_summary": summary}, indent=2))
|
| 252 |
+
elif args.mode == "rff":
|
| 253 |
+
print(json.dumps({"rff_summary": {str(r["rff_dim"]): r["mean_abs_error"] for r in rows}}, indent=2))
|
| 254 |
+
elif args.mode == "femnist":
|
| 255 |
+
summary = {m: float(np.mean([r["accuracy"] for r in rows if r["method"] == m])) for m in ["local", "grandmean", "qaggregation"]}
|
| 256 |
+
print(json.dumps({"femnist_accuracy": summary}, indent=2))
|
| 257 |
+
print(json.dumps({"mode": args.mode, "rows": len(rows), "output": str(args.output), "seconds": round(perf_counter() - started, 2), "device": str(device_from_arg(args.device))}, indent=2))
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
if __name__ == "__main__":
|
| 261 |
+
main()
|
| 262 |
+
|
| 263 |
+
````
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
````output
|
| 267 |
+
{
|
| 268 |
+
"rff_summary": {
|
| 269 |
+
"16": 0.011847271621227264,
|
| 270 |
+
"32": 0.008519105277955533,
|
| 271 |
+
"64": 0.005433569923043251,
|
| 272 |
+
"128": 0.004183858707547188,
|
| 273 |
+
"256": 0.003424282595515251,
|
| 274 |
+
"512": 0.0020784523338079454,
|
| 275 |
+
"1024": 0.0013805751502513886
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
{
|
| 279 |
+
"mode": "rff",
|
| 280 |
+
"rows": 7,
|
| 281 |
+
"output": "outputs/rff_tradeoff_100seeds.csv",
|
| 282 |
+
"seconds": 0.47,
|
| 283 |
+
"device": "cuda"
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
````
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
---
|
| 290 |
+
<!-- trackio-cell
|
| 291 |
+
{"type": "artifact", "id": "cell_ffe4264c28a2", "created_at": "2026-07-19T09:53:12+00:00", "title": "Artifact: rff_tradeoff_100seeds.csv", "path": "outputs/rff_tradeoff_100seeds.csv", "size": 721, "artifact_type": "dataset", "auto": true}
|
| 292 |
+
-->
|
| 293 |
+
**📦 Artifact** `outputs/rff_tradeoff_100seeds.csv` · dataset · 721 B
|
| 294 |
+
|
| 295 |
+
https://huggingface.co/buckets/vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts#logbook-files/outputs/rff_tradeoff_100seeds.csv
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
---
|
| 299 |
+
<!-- trackio-cell
|
| 300 |
+
{"type": "markdown", "id": "cell_e4032fbdf86b", "created_at": "2026-07-19T09:56:47+00:00", "title": "Clarified evidence"}
|
| 301 |
+
-->
|
| 302 |
+
Theorem 5.2 source audit: https://arxiv.org/pdf/2603.02233 adds an RFF approximation contribution of order sqrt(log B / D), so increasing D trades one-shot communication for statistical precision. CUDA 100-seed check: mean absolute MMD error falls from 0.01185 at D=16 to 0.00138 at D=1024, while transmitted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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Claim 5: Section 6.1 100-agent synthetic concept shift
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
---
|
| 5 |
+
<!-- trackio-cell
|
| 6 |
+
{"type": "markdown", "id": "cell_c62136c62a13", "created_at": "2026-07-19T09:32:03+00:00", "title": "Claim 5: Section 6.1 100-agent synthetic concept shift"}
|
| 7 |
+
-->
|
| 8 |
+
Document setup, runs, and results for **Claim 5: Section 6.1 100-agent synthetic concept shift**.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
<!-- trackio-cell
|
| 13 |
+
{"type": "code", "id": "cell_afaa63e40a29", "created_at": "2026-07-19T09:45:31+00:00", "title": "Run: echo (exit 0)", "command": ["echo", "TRACKIO_CAPTURE_CHECK"], "exit_code": 0, "duration_s": 0.001}
|
| 14 |
+
-->
|
| 15 |
+
````bash
|
| 16 |
+
$ echo TRACKIO_CAPTURE_CHECK
|
| 17 |
+
````
|
| 18 |
+
|
| 19 |
+
exit 0 · 0.0s
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
````output
|
| 23 |
+
TRACKIO_CAPTURE_CHECK
|
| 24 |
+
|
| 25 |
+
````
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
---
|
| 29 |
+
<!-- trackio-cell
|
| 30 |
+
{"type": "code", "id": "cell_ab96ac0a6224", "created_at": "2026-07-19T09:47:33+00:00", "title": "Run: python reproduce.py (exit 0)", "command": ["/home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python", "src/reproduce.py", "concept", "--repeats", "100", "--rff-dim", "500", "--output", "outputs/concept_100agents_100reps.csv", "--device", "cuda"], "exit_code": 0, "duration_s": 287.498}
|
| 31 |
+
-->
|
| 32 |
+
````bash
|
| 33 |
+
$ /home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python src/reproduce.py concept --repeats 100 --rff-dim 500 --output outputs/concept_100agents_100reps.csv --device cuda
|
| 34 |
+
````
|
| 35 |
+
|
| 36 |
+
exit 0 · 287.5s
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
````python title=reproduce.py
|
| 40 |
+
#!/usr/bin/env python3
|
| 41 |
+
"""Independent, GPU-capable checks for Fermanian et al. (2026), arXiv:2603.02233.
|
| 42 |
+
|
| 43 |
+
The implementation follows Algorithms 1--2 at a scaled experimental budget. It
|
| 44 |
+
uses RFF KMEs to choose a target client's collaboration weights and fits the
|
| 45 |
+
weighted empirical-risk minimizer exactly for linear regression. The FEMNIST
|
| 46 |
+
mode uses the public natural writer partition and a linear softmax model.
|
| 47 |
+
"""
|
| 48 |
+
from __future__ import annotations
|
| 49 |
+
|
| 50 |
+
import argparse
|
| 51 |
+
import csv
|
| 52 |
+
import json
|
| 53 |
+
import math
|
| 54 |
+
from pathlib import Path
|
| 55 |
+
from time import perf_counter
|
| 56 |
+
|
| 57 |
+
import numpy as np
|
| 58 |
+
import torch
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def device_from_arg(name: str) -> torch.device:
|
| 65 |
+
if name == "auto":
|
| 66 |
+
return torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 67 |
+
return torch.device(name)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def rff(z: torch.Tensor, d_rff: int, generator: torch.Generator, scale: torch.Tensor) -> torch.Tensor:
|
| 71 |
+
"""Gaussian-kernel RFF, with a supplied coordinate rescaling."""
|
| 72 |
+
w = torch.randn((z.shape[1], d_rff), generator=generator, device=z.device, dtype=z.dtype)
|
| 73 |
+
w = w * scale[:, None]
|
| 74 |
+
b = 2 * math.pi * torch.rand((d_rff,), generator=generator, device=z.device, dtype=z.dtype)
|
| 75 |
+
return math.sqrt(2.0 / d_rff) * torch.cos(z @ w + b)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def simplex_weights(means: torch.Tensor, target_phi: torch.Tensor, steps: int = 900) -> torch.Tensor:
|
| 79 |
+
"""Solve Algorithm 1's empirical Q-aggregation objective by projected GD."""
|
| 80 |
+
b_agents = means.shape[0]
|
| 81 |
+
n1 = target_phi.shape[0]
|
| 82 |
+
centered = target_phi - means[0]
|
| 83 |
+
cov = centered.T @ centered / max(n1 - 1, 1)
|
| 84 |
+
trace = torch.trace(cov)
|
| 85 |
+
diffs = means[1:] - means[0]
|
| 86 |
+
q_terms = torch.sqrt(torch.clamp(torch.einsum("bd,df,bf->b", diffs, cov, diffs), min=0.0) + 1e-12)
|
| 87 |
+
p_terms = torch.linalg.vector_norm(diffs, dim=1)
|
| 88 |
+
# Table 1 uses CQ^2=CP=log B: CQ=sqrt(log B), CP=log B.
|
| 89 |
+
cq, cp = math.sqrt(math.log(b_agents)), math.log(b_agents)
|
| 90 |
+
w = torch.full((b_agents,), 1.0 / b_agents, device=means.device, dtype=means.dtype)
|
| 91 |
+
for _ in range(steps):
|
| 92 |
+
w.requires_grad_(True)
|
| 93 |
+
mixture = w @ means
|
| 94 |
+
loss = torch.sum((mixture - means[0]) ** 2) + 2.0 * w[0] * trace / n1
|
| 95 |
+
loss = loss + cq / math.sqrt(n1) * torch.dot(w[1:], q_terms)
|
| 96 |
+
loss = loss + cp / n1 * torch.dot(w[1:], p_terms)
|
| 97 |
+
(grad,) = torch.autograd.grad(loss, w)
|
| 98 |
+
with torch.no_grad():
|
| 99 |
+
# Euclidean projection on the simplex, Duchi et al. (2008).
|
| 100 |
+
v = w - 0.04 * grad
|
| 101 |
+
u, _ = torch.sort(v, descending=True)
|
| 102 |
+
cssv = torch.cumsum(u, 0) - 1
|
| 103 |
+
ind = torch.arange(1, b_agents + 1, device=v.device, dtype=v.dtype)
|
| 104 |
+
rho = torch.nonzero(u - cssv / ind > 0, as_tuple=False)[-1, 0]
|
| 105 |
+
theta = cssv[rho] / (rho + 1)
|
| 106 |
+
w = torch.clamp(v - theta, min=0)
|
| 107 |
+
return w.detach()
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def weighted_linear_fit(xs: torch.Tensor, ys: torch.Tensor, weights: torch.Tensor, ridge: float = 1e-3) -> torch.Tensor:
|
| 111 |
+
"""Exact weighted empirical-risk minimizer for linear regression."""
|
| 112 |
+
b_agents, n, dim = xs.shape
|
| 113 |
+
x = torch.cat([xs, torch.ones((b_agents, n, 1), device=xs.device, dtype=xs.dtype)], dim=-1)
|
| 114 |
+
sample_w = (weights[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 115 |
+
flat_x, flat_y = x.reshape(-1, dim + 1), ys.reshape(-1)
|
| 116 |
+
lhs = flat_x.T @ (flat_x * sample_w[:, None]) + ridge * torch.eye(dim + 1, device=xs.device)
|
| 117 |
+
rhs = flat_x.T @ (flat_y * sample_w)
|
| 118 |
+
return torch.linalg.solve(lhs, rhs)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def concept_trial(seed: int, sigma2: float, d_rff: int, device: torch.device) -> dict:
|
| 122 |
+
g = torch.Generator(device=device).manual_seed(seed)
|
| 123 |
+
b_agents, n, dim, n_test = 100, 10, 20, 1000
|
| 124 |
+
signs = torch.where(torch.rand((b_agents,), generator=g, device=device) > .5, 1., -1.)
|
| 125 |
+
beta0 = torch.randn((dim,), generator=g, device=device)
|
| 126 |
+
eps = torch.randn((b_agents, dim), generator=g, device=device)
|
| 127 |
+
betas = signs[:, None] * math.sqrt(1 - sigma2) * beta0 + math.sqrt(sigma2) * eps
|
| 128 |
+
x = 1.0 + torch.randn((b_agents, n, dim), generator=g, device=device)
|
| 129 |
+
y = torch.einsum("bnd,bd->bn", x, betas) + math.sqrt(2.0) * torch.randn((b_agents, n), generator=g, device=device)
|
| 130 |
+
x_test = 1.0 + torch.randn((n_test, dim), generator=g, device=device)
|
| 131 |
+
y_test = x_test @ betas[0] + math.sqrt(2.0) * torch.randn((n_test,), generator=g, device=device)
|
| 132 |
+
# The paper's weighted Gaussian KME kernel gives X a 1/sqrt(d) scaling.
|
| 133 |
+
z = torch.cat([x, y[..., None]], dim=-1).reshape(-1, dim + 1)
|
| 134 |
+
scale = torch.cat([torch.full((dim,), 1 / math.sqrt(dim), device=device), torch.ones((1,), device=device)])
|
| 135 |
+
phi = rff(z, d_rff, g, scale).reshape(b_agents, n, d_rff)
|
| 136 |
+
means = phi.mean(1)
|
| 137 |
+
q_w = simplex_weights(means, phi[0])
|
| 138 |
+
local = torch.zeros(b_agents, device=device); local[0] = 1
|
| 139 |
+
grand = torch.full((b_agents,), 1 / b_agents, device=device)
|
| 140 |
+
oracle = (signs == signs[0]).float(); oracle /= oracle.sum()
|
| 141 |
+
result = {"sigma2": sigma2, "seed": seed, "q_local_weight": float(q_w[0]),
|
| 142 |
+
"q_same_group_weight": float(q_w[signs == signs[0]].sum())}
|
| 143 |
+
for name, weights in [("local", local), ("grandmean", grand), ("oracle", oracle), ("qaggregation", q_w)]:
|
| 144 |
+
beta = weighted_linear_fit(x, y, weights)
|
| 145 |
+
pred = x_test @ beta[:-1] + beta[-1]
|
| 146 |
+
result[f"{name}_mse"] = float(torch.mean((pred - y_test) ** 2))
|
| 147 |
+
return result
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def run_concept(args: argparse.Namespace) -> list[dict]:
|
| 151 |
+
device = device_from_arg(args.device)
|
| 152 |
+
rows = []
|
| 153 |
+
for sigma2 in args.sigmas:
|
| 154 |
+
for rep in range(args.repeats):
|
| 155 |
+
rows.append(concept_trial(args.seed + rep * 101 + int(sigma2 * 1000), sigma2, args.rff_dim, device))
|
| 156 |
+
return rows
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def exact_rbf_mmd(x: torch.Tensor, y: torch.Tensor, bandwidth: float = 1.0) -> torch.Tensor:
|
| 160 |
+
def k(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
|
| 161 |
+
return torch.exp(-torch.cdist(a, b).square() / (2 * bandwidth * bandwidth))
|
| 162 |
+
return torch.sqrt(torch.clamp(k(x, x).mean() + k(y, y).mean() - 2 * k(x, y).mean(), min=0.0))
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def run_rff(args: argparse.Namespace) -> list[dict]:
|
| 166 |
+
device = device_from_arg(args.device)
|
| 167 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 168 |
+
x = torch.randn((300, 8), generator=g, device=device)
|
| 169 |
+
y = torch.randn((300, 8), generator=g, device=device) + torch.tensor([0.35] + [0.] * 7, device=device)
|
| 170 |
+
exact = float(exact_rbf_mmd(x, y))
|
| 171 |
+
rows = []
|
| 172 |
+
for d_rff in args.rff_grid:
|
| 173 |
+
errors = []
|
| 174 |
+
for trial in range(args.repeats):
|
| 175 |
+
tg = torch.Generator(device=device).manual_seed(args.seed + 1000 * d_rff + trial)
|
| 176 |
+
phi = rff(torch.cat([x, y]), d_rff, tg, torch.ones(8, device=device))
|
| 177 |
+
approx = torch.linalg.vector_norm(phi[:len(x)].mean(0) - phi[len(x):].mean(0)).item()
|
| 178 |
+
errors.append(abs(approx - exact))
|
| 179 |
+
rows.append({"rff_dim": d_rff, "exact_mmd": exact, "mean_abs_error": float(np.mean(errors)),
|
| 180 |
+
"std_abs_error": float(np.std(errors)), "sqrt_logB_over_D": math.sqrt(math.log(100) / d_rff),
|
| 181 |
+
"one_shot_floats_per_agent": d_rff})
|
| 182 |
+
return rows
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def run_femnist(args: argparse.Namespace) -> list[dict]:
|
| 186 |
+
"""Actual FEMNIST writer data, deliberately scaled in samples/features/epochs."""
|
| 187 |
+
from datasets import load_dataset
|
| 188 |
+
device = device_from_arg(args.device)
|
| 189 |
+
local_parquet = ROOT / "data" / "femnist" / "data" / "train-00000-of-00001.parquet"
|
| 190 |
+
dataset = load_dataset("parquet", data_files=str(local_parquet), split="train", streaming=True) if local_parquet.exists() else load_dataset("flwrlabs/femnist", split="train", streaming=True)
|
| 191 |
+
by_writer: dict[str, list[tuple[np.ndarray, int]]] = {}
|
| 192 |
+
want = args.agents
|
| 193 |
+
for ex in dataset:
|
| 194 |
+
writer = ex["writer_id"]
|
| 195 |
+
if writer not in by_writer and len(by_writer) >= want:
|
| 196 |
+
continue
|
| 197 |
+
if writer in by_writer or len(by_writer) < want:
|
| 198 |
+
by_writer.setdefault(writer, []).append((np.asarray(ex["image"], dtype=np.float32) / 255., int(ex["character"])))
|
| 199 |
+
if len(by_writer) >= want and all(len(v) >= args.train_per_agent + args.test_per_agent for v in by_writer.values()):
|
| 200 |
+
break
|
| 201 |
+
eligible = [v for v in by_writer.values() if len(v) >= args.train_per_agent + args.test_per_agent][:want]
|
| 202 |
+
if len(eligible) < want:
|
| 203 |
+
raise RuntimeError(f"Only found {len(eligible)} eligible writers; need {want}")
|
| 204 |
+
x_train = torch.tensor(np.stack([np.stack([a for a, _ in v[:args.train_per_agent]]) for v in eligible]), device=device)
|
| 205 |
+
y_train = torch.tensor(np.stack([[b for _, b in v[:args.train_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 206 |
+
x_test = torch.tensor(np.stack([np.stack([a for a, _ in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]]) for v in eligible]), device=device)
|
| 207 |
+
y_test = torch.tensor(np.stack([[b for _, b in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 208 |
+
b_agents, n, raw_dim = x_train.shape[0], x_train.shape[1], 784
|
| 209 |
+
flat = x_train.reshape(b_agents, n, raw_dim)
|
| 210 |
+
# Fixed random projection reduces the RFF input cost while retaining a reproducible vision proxy.
|
| 211 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 212 |
+
proj = torch.randn((raw_dim, args.feature_dim), generator=g, device=device) / math.sqrt(raw_dim)
|
| 213 |
+
features = flat @ proj
|
| 214 |
+
phi_all = rff(features.reshape(-1, args.feature_dim), args.rff_dim, g, torch.ones(args.feature_dim, device=device)).reshape(b_agents, n, args.rff_dim)
|
| 215 |
+
means = phi_all.mean(1)
|
| 216 |
+
# Fit one regularized softmax classifier for each target using its personalized weights.
|
| 217 |
+
rows = []
|
| 218 |
+
all_x = features.reshape(-1, args.feature_dim)
|
| 219 |
+
all_y = y_train.reshape(-1)
|
| 220 |
+
for target in range(b_agents):
|
| 221 |
+
weights = simplex_weights(means, phi_all[target], steps=300)
|
| 222 |
+
schemes = {"local": torch.nn.functional.one_hot(torch.tensor(target, device=device), b_agents).float(),
|
| 223 |
+
"grandmean": torch.full((b_agents,), 1 / b_agents, device=device), "qaggregation": weights}
|
| 224 |
+
test_feat = x_test[target].reshape(args.test_per_agent, raw_dim) @ proj
|
| 225 |
+
for name, w in schemes.items():
|
| 226 |
+
model = torch.zeros((args.feature_dim, 62), device=device, requires_grad=True)
|
| 227 |
+
opt = torch.optim.Adam([model], lr=args.lr, weight_decay=1e-4)
|
| 228 |
+
sample_w = (w[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 229 |
+
for _ in range(args.epochs):
|
| 230 |
+
opt.zero_grad()
|
| 231 |
+
losses = torch.nn.functional.cross_entropy(all_x @ model, all_y, reduction="none")
|
| 232 |
+
(losses * sample_w).sum().backward(); opt.step()
|
| 233 |
+
acc = ((test_feat @ model).argmax(1) == y_test[target]).float().mean().item()
|
| 234 |
+
rows.append({"agent": target, "method": name, "accuracy": acc, "q_local_weight": float(weights[target])})
|
| 235 |
+
return rows
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def write_rows(rows: list[dict], out: Path) -> None:
|
| 239 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 240 |
+
with out.open("w", newline="") as f:
|
| 241 |
+
writer = csv.DictWriter(f, fieldnames=list(rows[0]))
|
| 242 |
+
writer.writeheader(); writer.writerows(rows)
|
| 243 |
+
out.with_suffix(".json").write_text(json.dumps(rows, indent=2))
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def main() -> None:
|
| 247 |
+
p = argparse.ArgumentParser()
|
| 248 |
+
p.add_argument("mode", choices=["concept", "rff", "femnist"])
|
| 249 |
+
p.add_argument("--output", type=Path, required=True)
|
| 250 |
+
p.add_argument("--device", default="auto")
|
| 251 |
+
p.add_argument("--seed", type=int, default=20260719)
|
| 252 |
+
p.add_argument("--repeats", type=int, default=30)
|
| 253 |
+
p.add_argument("--rff-dim", type=int, default=500)
|
| 254 |
+
p.add_argument("--sigmas", type=float, nargs="+", default=[0., .1, .25, .5, .75, 1.])
|
| 255 |
+
p.add_argument("--rff-grid", type=int, nargs="+", default=[16, 32, 64, 128, 256, 512, 1024])
|
| 256 |
+
p.add_argument("--agents", type=int, default=192)
|
| 257 |
+
p.add_argument("--train-per-agent", type=int, default=32)
|
| 258 |
+
p.add_argument("--test-per-agent", type=int, default=16)
|
| 259 |
+
p.add_argument("--feature-dim", type=int, default=64)
|
| 260 |
+
p.add_argument("--epochs", type=int, default=20)
|
| 261 |
+
p.add_argument("--lr", type=float, default=.08)
|
| 262 |
+
args = p.parse_args()
|
| 263 |
+
started = perf_counter()
|
| 264 |
+
rows = {"concept": run_concept, "rff": run_rff, "femnist": run_femnist}[args.mode](args)
|
| 265 |
+
write_rows(rows, args.output)
|
| 266 |
+
if args.mode == "concept":
|
| 267 |
+
summary = {str(s): {k: float(np.mean([r[k] for r in rows if r["sigma2"] == s])) for k in ["local_mse", "grandmean_mse", "oracle_mse", "qaggregation_mse", "q_local_weight", "q_same_group_weight"]} for s in args.sigmas}
|
| 268 |
+
print(json.dumps({"concept_summary": summary}, indent=2))
|
| 269 |
+
elif args.mode == "rff":
|
| 270 |
+
print(json.dumps({"rff_summary": {str(r["rff_dim"]): r["mean_abs_error"] for r in rows}}, indent=2))
|
| 271 |
+
elif args.mode == "femnist":
|
| 272 |
+
summary = {m: float(np.mean([r["accuracy"] for r in rows if r["method"] == m])) for m in ["local", "grandmean", "qaggregation"]}
|
| 273 |
+
print(json.dumps({"femnist_accuracy": summary}, indent=2))
|
| 274 |
+
print(json.dumps({"mode": args.mode, "rows": len(rows), "output": str(args.output), "seconds": round(perf_counter() - started, 2), "device": str(device_from_arg(args.device))}, indent=2))
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
if __name__ == "__main__":
|
| 278 |
+
main()
|
| 279 |
+
|
| 280 |
+
````
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
````output
|
| 284 |
+
{
|
| 285 |
+
"concept_summary": {
|
| 286 |
+
"0.0": {
|
| 287 |
+
"local_mse": 15.748318042755127,
|
| 288 |
+
"grandmean_mse": 40.606961507797244,
|
| 289 |
+
"oracle_mse": 2.0862513756752015,
|
| 290 |
+
"qaggregation_mse": 17.83958231449127,
|
| 291 |
+
"q_local_weight": 0.9771137142181396,
|
| 292 |
+
"q_same_group_weight": 0.9975556522607804
|
| 293 |
+
},
|
| 294 |
+
"0.1": {
|
| 295 |
+
"local_mse": 15.361917610168456,
|
| 296 |
+
"grandmean_mse": 45.73134832382202,
|
| 297 |
+
"oracle_mse": 6.119768922328949,
|
| 298 |
+
"qaggregation_mse": 18.07122127532959,
|
| 299 |
+
"q_local_weight": 0.9787336409091949,
|
| 300 |
+
"q_same_group_weight": 0.9981670784950256
|
| 301 |
+
},
|
| 302 |
+
"0.25": {
|
| 303 |
+
"local_mse": 15.827756361961365,
|
| 304 |
+
"grandmean_mse": 39.008377923965455,
|
| 305 |
+
"oracle_mse": 11.351614267826081,
|
| 306 |
+
"qaggregation_mse": 25.339054584503174,
|
| 307 |
+
"q_local_weight": 0.9825072956085205,
|
| 308 |
+
"q_same_group_weight": 0.99599778175354
|
| 309 |
+
},
|
| 310 |
+
"0.5": {
|
| 311 |
+
"local_mse": 14.459182372093201,
|
| 312 |
+
"grandmean_mse": 45.512830362319946,
|
| 313 |
+
"oracle_mse": 24.322485909461975,
|
| 314 |
+
"qaggregation_mse": 25.430337595939637,
|
| 315 |
+
"q_local_weight": 0.9876203048229217,
|
| 316 |
+
"q_same_group_weight": 0.9948384702205658
|
| 317 |
+
},
|
| 318 |
+
"0.75": {
|
| 319 |
+
"local_mse": 15.87236515045166,
|
| 320 |
+
"grandmean_mse": 39.63199781417847,
|
| 321 |
+
"oracle_mse": 30.853181953430177,
|
| 322 |
+
"qaggregation_mse": 33.74232290267944,
|
| 323 |
+
"q_local_weight": 0.9877495408058167,
|
| 324 |
+
"q_same_group_weight": 0.9943676108121872
|
| 325 |
+
},
|
| 326 |
+
"1.0": {
|
| 327 |
+
"local_mse": 15.390748682022094,
|
| 328 |
+
"grandmean_mse": 39.16119129180908,
|
| 329 |
+
"oracle_mse": 40.00151491165161,
|
| 330 |
+
"qaggregation_mse": 30.293080587387085,
|
| 331 |
+
"q_local_weight": 0.9896031093597412,
|
| 332 |
+
"q_same_group_weight": 0.9947122848033905
|
| 333 |
+
}
|
| 334 |
+
}
|
| 335 |
+
}
|
| 336 |
+
{
|
| 337 |
+
"mode": "concept",
|
| 338 |
+
"rows": 600,
|
| 339 |
+
"output": "outputs/concept_100agents_100reps.csv",
|
| 340 |
+
"seconds": 286.58,
|
| 341 |
+
"device": "cuda"
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
````
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
---
|
| 348 |
+
<!-- trackio-cell
|
| 349 |
+
{"type": "artifact", "id": "cell_edfa78971b70", "created_at": "2026-07-19T09:47:34+00:00", "title": "Artifact: concept_100agents_100reps.csv", "path": "outputs/concept_100agents_100reps.csv", "size": 63718, "artifact_type": "dataset", "auto": true}
|
| 350 |
+
-->
|
| 351 |
+
**📦 Artifact** `outputs/concept_100agents_100reps.csv` · dataset · 63.7 kB
|
| 352 |
+
|
| 353 |
+
https://huggingface.co/buckets/vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts#logbook-files/outputs/concept_100agents_100reps.csv
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
---
|
| 357 |
+
<!-- trackio-cell
|
| 358 |
+
{"type": "code", "id": "cell_1d5aa5c25cad", "created_at": "2026-07-19T09:49:48+00:00", "title": "Run: python reproduce.py (exit 0)", "command": ["/home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python", "src/reproduce.py", "concept", "--repeats", "100", "--rff-dim", "500", "--output", "outputs/concept_100agents_100reps.csv", "--device", "cuda"], "exit_code": 0, "duration_s": 333.017}
|
| 359 |
+
-->
|
| 360 |
+
````bash
|
| 361 |
+
$ /home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python src/reproduce.py concept --repeats 100 --rff-dim 500 --output outputs/concept_100agents_100reps.csv --device cuda
|
| 362 |
+
````
|
| 363 |
+
|
| 364 |
+
exit 0 · 333.0s
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
````python title=reproduce.py
|
| 368 |
+
#!/usr/bin/env python3
|
| 369 |
+
"""Independent, GPU-capable checks for Fermanian et al. (2026), arXiv:2603.02233.
|
| 370 |
+
|
| 371 |
+
The implementation follows Algorithms 1--2 at a scaled experimental budget. It
|
| 372 |
+
uses RFF KMEs to choose a target client's collaboration weights and fits the
|
| 373 |
+
weighted empirical-risk minimizer exactly for linear regression. The FEMNIST
|
| 374 |
+
mode uses the public natural writer partition and a linear softmax model.
|
| 375 |
+
"""
|
| 376 |
+
from __future__ import annotations
|
| 377 |
+
|
| 378 |
+
import argparse
|
| 379 |
+
import csv
|
| 380 |
+
import json
|
| 381 |
+
import math
|
| 382 |
+
from pathlib import Path
|
| 383 |
+
from time import perf_counter
|
| 384 |
+
|
| 385 |
+
import numpy as np
|
| 386 |
+
import torch
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
def device_from_arg(name: str) -> torch.device:
|
| 393 |
+
if name == "auto":
|
| 394 |
+
return torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 395 |
+
return torch.device(name)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def rff(z: torch.Tensor, d_rff: int, generator: torch.Generator, scale: torch.Tensor) -> torch.Tensor:
|
| 399 |
+
"""Gaussian-kernel RFF, with a supplied coordinate rescaling."""
|
| 400 |
+
w = torch.randn((z.shape[1], d_rff), generator=generator, device=z.device, dtype=z.dtype)
|
| 401 |
+
w = w * scale[:, None]
|
| 402 |
+
b = 2 * math.pi * torch.rand((d_rff,), generator=generator, device=z.device, dtype=z.dtype)
|
| 403 |
+
return math.sqrt(2.0 / d_rff) * torch.cos(z @ w + b)
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
def simplex_weights(means: torch.Tensor, target_phi: torch.Tensor, steps: int = 900) -> torch.Tensor:
|
| 407 |
+
"""Solve Algorithm 1's empirical Q-aggregation objective by projected GD."""
|
| 408 |
+
b_agents = means.shape[0]
|
| 409 |
+
n1 = target_phi.shape[0]
|
| 410 |
+
centered = target_phi - means[0]
|
| 411 |
+
cov = centered.T @ centered / max(n1 - 1, 1)
|
| 412 |
+
trace = torch.trace(cov)
|
| 413 |
+
diffs = means[1:] - means[0]
|
| 414 |
+
q_terms = torch.sqrt(torch.clamp(torch.einsum("bd,df,bf->b", diffs, cov, diffs), min=0.0) + 1e-12)
|
| 415 |
+
p_terms = torch.linalg.vector_norm(diffs, dim=1)
|
| 416 |
+
# Table 1 uses CQ^2=CP=log B: CQ=sqrt(log B), CP=log B.
|
| 417 |
+
cq, cp = math.sqrt(math.log(b_agents)), math.log(b_agents)
|
| 418 |
+
w = torch.full((b_agents,), 1.0 / b_agents, device=means.device, dtype=means.dtype)
|
| 419 |
+
for _ in range(steps):
|
| 420 |
+
w.requires_grad_(True)
|
| 421 |
+
mixture = w @ means
|
| 422 |
+
loss = torch.sum((mixture - means[0]) ** 2) + 2.0 * w[0] * trace / n1
|
| 423 |
+
loss = loss + cq / math.sqrt(n1) * torch.dot(w[1:], q_terms)
|
| 424 |
+
loss = loss + cp / n1 * torch.dot(w[1:], p_terms)
|
| 425 |
+
(grad,) = torch.autograd.grad(loss, w)
|
| 426 |
+
with torch.no_grad():
|
| 427 |
+
# Euclidean projection on the simplex, Duchi et al. (2008).
|
| 428 |
+
v = w - 0.04 * grad
|
| 429 |
+
u, _ = torch.sort(v, descending=True)
|
| 430 |
+
cssv = torch.cumsum(u, 0) - 1
|
| 431 |
+
ind = torch.arange(1, b_agents + 1, device=v.device, dtype=v.dtype)
|
| 432 |
+
rho = torch.nonzero(u - cssv / ind > 0, as_tuple=False)[-1, 0]
|
| 433 |
+
theta = cssv[rho] / (rho + 1)
|
| 434 |
+
w = torch.clamp(v - theta, min=0)
|
| 435 |
+
return w.detach()
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
def weighted_linear_fit(xs: torch.Tensor, ys: torch.Tensor, weights: torch.Tensor, ridge: float = 1e-3) -> torch.Tensor:
|
| 439 |
+
"""Exact weighted empirical-risk minimizer for linear regression."""
|
| 440 |
+
b_agents, n, dim = xs.shape
|
| 441 |
+
x = torch.cat([xs, torch.ones((b_agents, n, 1), device=xs.device, dtype=xs.dtype)], dim=-1)
|
| 442 |
+
sample_w = (weights[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 443 |
+
flat_x, flat_y = x.reshape(-1, dim + 1), ys.reshape(-1)
|
| 444 |
+
lhs = flat_x.T @ (flat_x * sample_w[:, None]) + ridge * torch.eye(dim + 1, device=xs.device)
|
| 445 |
+
rhs = flat_x.T @ (flat_y * sample_w)
|
| 446 |
+
return torch.linalg.solve(lhs, rhs)
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
def concept_trial(seed: int, sigma2: float, d_rff: int, device: torch.device) -> dict:
|
| 450 |
+
g = torch.Generator(device=device).manual_seed(seed)
|
| 451 |
+
b_agents, n, dim, n_test = 100, 10, 20, 1000
|
| 452 |
+
signs = torch.where(torch.rand((b_agents,), generator=g, device=device) > .5, 1., -1.)
|
| 453 |
+
beta0 = torch.randn((dim,), generator=g, device=device)
|
| 454 |
+
eps = torch.randn((b_agents, dim), generator=g, device=device)
|
| 455 |
+
betas = signs[:, None] * math.sqrt(1 - sigma2) * beta0 + math.sqrt(sigma2) * eps
|
| 456 |
+
x = 1.0 + torch.randn((b_agents, n, dim), generator=g, device=device)
|
| 457 |
+
y = torch.einsum("bnd,bd->bn", x, betas) + math.sqrt(2.0) * torch.randn((b_agents, n), generator=g, device=device)
|
| 458 |
+
x_test = 1.0 + torch.randn((n_test, dim), generator=g, device=device)
|
| 459 |
+
y_test = x_test @ betas[0] + math.sqrt(2.0) * torch.randn((n_test,), generator=g, device=device)
|
| 460 |
+
# The paper's weighted Gaussian KME kernel gives X a 1/sqrt(d) scaling.
|
| 461 |
+
z = torch.cat([x, y[..., None]], dim=-1).reshape(-1, dim + 1)
|
| 462 |
+
scale = torch.cat([torch.full((dim,), 1 / math.sqrt(dim), device=device), torch.ones((1,), device=device)])
|
| 463 |
+
phi = rff(z, d_rff, g, scale).reshape(b_agents, n, d_rff)
|
| 464 |
+
means = phi.mean(1)
|
| 465 |
+
q_w = simplex_weights(means, phi[0])
|
| 466 |
+
local = torch.zeros(b_agents, device=device); local[0] = 1
|
| 467 |
+
grand = torch.full((b_agents,), 1 / b_agents, device=device)
|
| 468 |
+
oracle = (signs == signs[0]).float(); oracle /= oracle.sum()
|
| 469 |
+
result = {"sigma2": sigma2, "seed": seed, "q_local_weight": float(q_w[0]),
|
| 470 |
+
"q_same_group_weight": float(q_w[signs == signs[0]].sum())}
|
| 471 |
+
for name, weights in [("local", local), ("grandmean", grand), ("oracle", oracle), ("qaggregation", q_w)]:
|
| 472 |
+
beta = weighted_linear_fit(x, y, weights)
|
| 473 |
+
pred = x_test @ beta[:-1] + beta[-1]
|
| 474 |
+
result[f"{name}_mse"] = float(torch.mean((pred - y_test) ** 2))
|
| 475 |
+
return result
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def run_concept(args: argparse.Namespace) -> list[dict]:
|
| 479 |
+
device = device_from_arg(args.device)
|
| 480 |
+
rows = []
|
| 481 |
+
for sigma2 in args.sigmas:
|
| 482 |
+
for rep in range(args.repeats):
|
| 483 |
+
rows.append(concept_trial(args.seed + rep * 101 + int(sigma2 * 1000), sigma2, args.rff_dim, device))
|
| 484 |
+
return rows
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def exact_rbf_mmd(x: torch.Tensor, y: torch.Tensor, bandwidth: float = 1.0) -> torch.Tensor:
|
| 488 |
+
def k(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
|
| 489 |
+
return torch.exp(-torch.cdist(a, b).square() / (2 * bandwidth * bandwidth))
|
| 490 |
+
return torch.sqrt(torch.clamp(k(x, x).mean() + k(y, y).mean() - 2 * k(x, y).mean(), min=0.0))
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
def run_rff(args: argparse.Namespace) -> list[dict]:
|
| 494 |
+
device = device_from_arg(args.device)
|
| 495 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 496 |
+
x = torch.randn((300, 8), generator=g, device=device)
|
| 497 |
+
y = torch.randn((300, 8), generator=g, device=device) + torch.tensor([0.35] + [0.] * 7, device=device)
|
| 498 |
+
exact = float(exact_rbf_mmd(x, y))
|
| 499 |
+
rows = []
|
| 500 |
+
for d_rff in args.rff_grid:
|
| 501 |
+
errors = []
|
| 502 |
+
for trial in range(args.repeats):
|
| 503 |
+
tg = torch.Generator(device=device).manual_seed(args.seed + 1000 * d_rff + trial)
|
| 504 |
+
phi = rff(torch.cat([x, y]), d_rff, tg, torch.ones(8, device=device))
|
| 505 |
+
approx = torch.linalg.vector_norm(phi[:len(x)].mean(0) - phi[len(x):].mean(0)).item()
|
| 506 |
+
errors.append(abs(approx - exact))
|
| 507 |
+
rows.append({"rff_dim": d_rff, "exact_mmd": exact, "mean_abs_error": float(np.mean(errors)),
|
| 508 |
+
"std_abs_error": float(np.std(errors)), "sqrt_logB_over_D": math.sqrt(math.log(100) / d_rff),
|
| 509 |
+
"one_shot_floats_per_agent": d_rff})
|
| 510 |
+
return rows
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def run_femnist(args: argparse.Namespace) -> list[dict]:
|
| 514 |
+
"""Actual FEMNIST writer data, deliberately scaled in samples/features/epochs."""
|
| 515 |
+
from datasets import load_dataset
|
| 516 |
+
device = device_from_arg(args.device)
|
| 517 |
+
local_parquet = ROOT / "data" / "femnist" / "data" / "train-00000-of-00001.parquet"
|
| 518 |
+
dataset = load_dataset("parquet", data_files=str(local_parquet), split="train", streaming=True) if local_parquet.exists() else load_dataset("flwrlabs/femnist", split="train", streaming=True)
|
| 519 |
+
by_writer: dict[str, list[tuple[np.ndarray, int]]] = {}
|
| 520 |
+
want = args.agents
|
| 521 |
+
for ex in dataset:
|
| 522 |
+
writer = ex["writer_id"]
|
| 523 |
+
if writer not in by_writer and len(by_writer) >= want:
|
| 524 |
+
continue
|
| 525 |
+
if writer in by_writer or len(by_writer) < want:
|
| 526 |
+
by_writer.setdefault(writer, []).append((np.asarray(ex["image"], dtype=np.float32) / 255., int(ex["character"])))
|
| 527 |
+
if len(by_writer) >= want and all(len(v) >= args.train_per_agent + args.test_per_agent for v in by_writer.values()):
|
| 528 |
+
break
|
| 529 |
+
eligible = [v for v in by_writer.values() if len(v) >= args.train_per_agent + args.test_per_agent][:want]
|
| 530 |
+
if len(eligible) < want:
|
| 531 |
+
raise RuntimeError(f"Only found {len(eligible)} eligible writers; need {want}")
|
| 532 |
+
x_train = torch.tensor(np.stack([np.stack([a for a, _ in v[:args.train_per_agent]]) for v in eligible]), device=device)
|
| 533 |
+
y_train = torch.tensor(np.stack([[b for _, b in v[:args.train_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 534 |
+
x_test = torch.tensor(np.stack([np.stack([a for a, _ in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]]) for v in eligible]), device=device)
|
| 535 |
+
y_test = torch.tensor(np.stack([[b for _, b in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 536 |
+
b_agents, n, raw_dim = x_train.shape[0], x_train.shape[1], 784
|
| 537 |
+
flat = x_train.reshape(b_agents, n, raw_dim)
|
| 538 |
+
# Fixed random projection reduces the RFF input cost while retaining a reproducible vision proxy.
|
| 539 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 540 |
+
proj = torch.randn((raw_dim, args.feature_dim), generator=g, device=device) / math.sqrt(raw_dim)
|
| 541 |
+
features = flat @ proj
|
| 542 |
+
phi_all = rff(features.reshape(-1, args.feature_dim), args.rff_dim, g, torch.ones(args.feature_dim, device=device)).reshape(b_agents, n, args.rff_dim)
|
| 543 |
+
means = phi_all.mean(1)
|
| 544 |
+
# Fit one regularized softmax classifier for each target using its personalized weights.
|
| 545 |
+
rows = []
|
| 546 |
+
all_x = features.reshape(-1, args.feature_dim)
|
| 547 |
+
all_y = y_train.reshape(-1)
|
| 548 |
+
for target in range(b_agents):
|
| 549 |
+
weights = simplex_weights(means, phi_all[target], steps=300)
|
| 550 |
+
schemes = {"local": torch.nn.functional.one_hot(torch.tensor(target, device=device), b_agents).float(),
|
| 551 |
+
"grandmean": torch.full((b_agents,), 1 / b_agents, device=device), "qaggregation": weights}
|
| 552 |
+
test_feat = x_test[target].reshape(args.test_per_agent, raw_dim) @ proj
|
| 553 |
+
for name, w in schemes.items():
|
| 554 |
+
model = torch.zeros((args.feature_dim, 62), device=device, requires_grad=True)
|
| 555 |
+
opt = torch.optim.Adam([model], lr=args.lr, weight_decay=1e-4)
|
| 556 |
+
sample_w = (w[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 557 |
+
for _ in range(args.epochs):
|
| 558 |
+
opt.zero_grad()
|
| 559 |
+
losses = torch.nn.functional.cross_entropy(all_x @ model, all_y, reduction="none")
|
| 560 |
+
(losses * sample_w).sum().backward(); opt.step()
|
| 561 |
+
acc = ((test_feat @ model).argmax(1) == y_test[target]).float().mean().item()
|
| 562 |
+
rows.append({"agent": target, "method": name, "accuracy": acc, "q_local_weight": float(weights[target])})
|
| 563 |
+
return rows
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
def write_rows(rows: list[dict], out: Path) -> None:
|
| 567 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 568 |
+
with out.open("w", newline="") as f:
|
| 569 |
+
writer = csv.DictWriter(f, fieldnames=list(rows[0]))
|
| 570 |
+
writer.writeheader(); writer.writerows(rows)
|
| 571 |
+
out.with_suffix(".json").write_text(json.dumps(rows, indent=2))
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
def main() -> None:
|
| 575 |
+
p = argparse.ArgumentParser()
|
| 576 |
+
p.add_argument("mode", choices=["concept", "rff", "femnist"])
|
| 577 |
+
p.add_argument("--output", type=Path, required=True)
|
| 578 |
+
p.add_argument("--device", default="auto")
|
| 579 |
+
p.add_argument("--seed", type=int, default=20260719)
|
| 580 |
+
p.add_argument("--repeats", type=int, default=30)
|
| 581 |
+
p.add_argument("--rff-dim", type=int, default=500)
|
| 582 |
+
p.add_argument("--sigmas", type=float, nargs="+", default=[0., .1, .25, .5, .75, 1.])
|
| 583 |
+
p.add_argument("--rff-grid", type=int, nargs="+", default=[16, 32, 64, 128, 256, 512, 1024])
|
| 584 |
+
p.add_argument("--agents", type=int, default=192)
|
| 585 |
+
p.add_argument("--train-per-agent", type=int, default=32)
|
| 586 |
+
p.add_argument("--test-per-agent", type=int, default=16)
|
| 587 |
+
p.add_argument("--feature-dim", type=int, default=64)
|
| 588 |
+
p.add_argument("--epochs", type=int, default=20)
|
| 589 |
+
p.add_argument("--lr", type=float, default=.08)
|
| 590 |
+
args = p.parse_args()
|
| 591 |
+
started = perf_counter()
|
| 592 |
+
rows = {"concept": run_concept, "rff": run_rff, "femnist": run_femnist}[args.mode](args)
|
| 593 |
+
write_rows(rows, args.output)
|
| 594 |
+
if args.mode == "concept":
|
| 595 |
+
summary = {str(s): {k: float(np.mean([r[k] for r in rows if r["sigma2"] == s])) for k in ["local_mse", "grandmean_mse", "oracle_mse", "qaggregation_mse", "q_local_weight", "q_same_group_weight"]} for s in args.sigmas}
|
| 596 |
+
print(json.dumps({"concept_summary": summary}, indent=2))
|
| 597 |
+
elif args.mode == "rff":
|
| 598 |
+
print(json.dumps({"rff_summary": {str(r["rff_dim"]): r["mean_abs_error"] for r in rows}}, indent=2))
|
| 599 |
+
elif args.mode == "femnist":
|
| 600 |
+
summary = {m: float(np.mean([r["accuracy"] for r in rows if r["method"] == m])) for m in ["local", "grandmean", "qaggregation"]}
|
| 601 |
+
print(json.dumps({"femnist_accuracy": summary}, indent=2))
|
| 602 |
+
print(json.dumps({"mode": args.mode, "rows": len(rows), "output": str(args.output), "seconds": round(perf_counter() - started, 2), "device": str(device_from_arg(args.device))}, indent=2))
|
| 603 |
+
|
| 604 |
+
|
| 605 |
+
if __name__ == "__main__":
|
| 606 |
+
main()
|
| 607 |
+
|
| 608 |
+
````
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
````output
|
| 612 |
+
{
|
| 613 |
+
"concept_summary": {
|
| 614 |
+
"0.0": {
|
| 615 |
+
"local_mse": 15.748318042755127,
|
| 616 |
+
"grandmean_mse": 40.606961507797244,
|
| 617 |
+
"oracle_mse": 2.0862513756752015,
|
| 618 |
+
"qaggregation_mse": 17.83958231449127,
|
| 619 |
+
"q_local_weight": 0.9771137142181396,
|
| 620 |
+
"q_same_group_weight": 0.9975556522607804
|
| 621 |
+
},
|
| 622 |
+
"0.1": {
|
| 623 |
+
"local_mse": 15.361917610168456,
|
| 624 |
+
"grandmean_mse": 45.73134832382202,
|
| 625 |
+
"oracle_mse": 6.119768922328949,
|
| 626 |
+
"qaggregation_mse": 18.07122127532959,
|
| 627 |
+
"q_local_weight": 0.9787336409091949,
|
| 628 |
+
"q_same_group_weight": 0.9981670784950256
|
| 629 |
+
},
|
| 630 |
+
"0.25": {
|
| 631 |
+
"local_mse": 15.827756361961365,
|
| 632 |
+
"grandmean_mse": 39.008377923965455,
|
| 633 |
+
"oracle_mse": 11.351614267826081,
|
| 634 |
+
"qaggregation_mse": 25.339054584503174,
|
| 635 |
+
"q_local_weight": 0.9825072956085205,
|
| 636 |
+
"q_same_group_weight": 0.99599778175354
|
| 637 |
+
},
|
| 638 |
+
"0.5": {
|
| 639 |
+
"local_mse": 14.459182372093201,
|
| 640 |
+
"grandmean_mse": 45.512830362319946,
|
| 641 |
+
"oracle_mse": 24.322485909461975,
|
| 642 |
+
"qaggregation_mse": 25.430337595939637,
|
| 643 |
+
"q_local_weight": 0.9876203048229217,
|
| 644 |
+
"q_same_group_weight": 0.9948384702205658
|
| 645 |
+
},
|
| 646 |
+
"0.75": {
|
| 647 |
+
"local_mse": 15.87236515045166,
|
| 648 |
+
"grandmean_mse": 39.63199781417847,
|
| 649 |
+
"oracle_mse": 30.853181953430177,
|
| 650 |
+
"qaggregation_mse": 33.74232290267944,
|
| 651 |
+
"q_local_weight": 0.9877495408058167,
|
| 652 |
+
"q_same_group_weight": 0.9943676108121872
|
| 653 |
+
},
|
| 654 |
+
"1.0": {
|
| 655 |
+
"local_mse": 15.390748682022094,
|
| 656 |
+
"grandmean_mse": 39.16119129180908,
|
| 657 |
+
"oracle_mse": 40.00151491165161,
|
| 658 |
+
"qaggregation_mse": 30.293080587387085,
|
| 659 |
+
"q_local_weight": 0.9896031093597412,
|
| 660 |
+
"q_same_group_weight": 0.9947122848033905
|
| 661 |
+
}
|
| 662 |
+
}
|
| 663 |
+
}
|
| 664 |
+
{
|
| 665 |
+
"mode": "concept",
|
| 666 |
+
"rows": 600,
|
| 667 |
+
"output": "outputs/concept_100agents_100reps.csv",
|
| 668 |
+
"seconds": 332.1,
|
| 669 |
+
"device": "cuda"
|
| 670 |
+
}
|
| 671 |
+
|
| 672 |
+
````
|
| 673 |
+
|
| 674 |
+
|
| 675 |
+
---
|
| 676 |
+
<!-- trackio-cell
|
| 677 |
+
{"type": "artifact", "id": "cell_5838f11deee2", "created_at": "2026-07-19T09:49:49+00:00", "title": "Artifact: concept_100agents_100reps.csv", "path": "outputs/concept_100agents_100reps.csv", "size": 63718, "artifact_type": "dataset", "auto": true}
|
| 678 |
+
-->
|
| 679 |
+
**📦 Artifact** `outputs/concept_100agents_100reps.csv` · dataset · 63.7 kB
|
| 680 |
+
|
| 681 |
+
https://huggingface.co/buckets/vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts#logbook-files/outputs/concept_100agents_100reps.csv
|
| 682 |
+
|
| 683 |
+
|
| 684 |
+
---
|
| 685 |
+
<!-- trackio-cell
|
| 686 |
+
{"type": "code", "id": "cell_0e566181e79c", "created_at": "2026-07-19T09:50:42+00:00", "title": "Run: python reproduce.py (exit 0)", "command": ["/home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python", "src/reproduce.py", "concept", "--repeats", "100", "--rff-dim", "500", "--output", "outputs/concept_100agents_100reps.csv", "--device", "cuda"], "exit_code": 0, "duration_s": 300.077}
|
| 687 |
+
-->
|
| 688 |
+
````bash
|
| 689 |
+
$ /home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python src/reproduce.py concept --repeats 100 --rff-dim 500 --output outputs/concept_100agents_100reps.csv --device cuda
|
| 690 |
+
````
|
| 691 |
+
|
| 692 |
+
exit 0 · 300.1s
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
````python title=reproduce.py
|
| 696 |
+
#!/usr/bin/env python3
|
| 697 |
+
"""Independent, GPU-capable checks for Fermanian et al. (2026), arXiv:2603.02233.
|
| 698 |
+
|
| 699 |
+
The implementation follows Algorithms 1--2 at a scaled experimental budget. It
|
| 700 |
+
uses RFF KMEs to choose a target client's collaboration weights and fits the
|
| 701 |
+
weighted empirical-risk minimizer exactly for linear regression. The FEMNIST
|
| 702 |
+
mode uses the public natural writer partition and a linear softmax model.
|
| 703 |
+
"""
|
| 704 |
+
from __future__ import annotations
|
| 705 |
+
|
| 706 |
+
import argparse
|
| 707 |
+
import csv
|
| 708 |
+
import json
|
| 709 |
+
import math
|
| 710 |
+
from pathlib import Path
|
| 711 |
+
from time import perf_counter
|
| 712 |
+
|
| 713 |
+
import numpy as np
|
| 714 |
+
import torch
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 718 |
+
|
| 719 |
+
|
| 720 |
+
def device_from_arg(name: str) -> torch.device:
|
| 721 |
+
if name == "auto":
|
| 722 |
+
return torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 723 |
+
return torch.device(name)
|
| 724 |
+
|
| 725 |
+
|
| 726 |
+
def rff(z: torch.Tensor, d_rff: int, generator: torch.Generator, scale: torch.Tensor) -> torch.Tensor:
|
| 727 |
+
"""Gaussian-kernel RFF, with a supplied coordinate rescaling."""
|
| 728 |
+
w = torch.randn((z.shape[1], d_rff), generator=generator, device=z.device, dtype=z.dtype)
|
| 729 |
+
w = w * scale[:, None]
|
| 730 |
+
b = 2 * math.pi * torch.rand((d_rff,), generator=generator, device=z.device, dtype=z.dtype)
|
| 731 |
+
return math.sqrt(2.0 / d_rff) * torch.cos(z @ w + b)
|
| 732 |
+
|
| 733 |
+
|
| 734 |
+
def simplex_weights(means: torch.Tensor, target_phi: torch.Tensor, steps: int = 900) -> torch.Tensor:
|
| 735 |
+
"""Solve Algorithm 1's empirical Q-aggregation objective by projected GD."""
|
| 736 |
+
b_agents = means.shape[0]
|
| 737 |
+
n1 = target_phi.shape[0]
|
| 738 |
+
centered = target_phi - means[0]
|
| 739 |
+
cov = centered.T @ centered / max(n1 - 1, 1)
|
| 740 |
+
trace = torch.trace(cov)
|
| 741 |
+
diffs = means[1:] - means[0]
|
| 742 |
+
q_terms = torch.sqrt(torch.clamp(torch.einsum("bd,df,bf->b", diffs, cov, diffs), min=0.0) + 1e-12)
|
| 743 |
+
p_terms = torch.linalg.vector_norm(diffs, dim=1)
|
| 744 |
+
# Table 1 uses CQ^2=CP=log B: CQ=sqrt(log B), CP=log B.
|
| 745 |
+
cq, cp = math.sqrt(math.log(b_agents)), math.log(b_agents)
|
| 746 |
+
w = torch.full((b_agents,), 1.0 / b_agents, device=means.device, dtype=means.dtype)
|
| 747 |
+
for _ in range(steps):
|
| 748 |
+
w.requires_grad_(True)
|
| 749 |
+
mixture = w @ means
|
| 750 |
+
loss = torch.sum((mixture - means[0]) ** 2) + 2.0 * w[0] * trace / n1
|
| 751 |
+
loss = loss + cq / math.sqrt(n1) * torch.dot(w[1:], q_terms)
|
| 752 |
+
loss = loss + cp / n1 * torch.dot(w[1:], p_terms)
|
| 753 |
+
(grad,) = torch.autograd.grad(loss, w)
|
| 754 |
+
with torch.no_grad():
|
| 755 |
+
# Euclidean projection on the simplex, Duchi et al. (2008).
|
| 756 |
+
v = w - 0.04 * grad
|
| 757 |
+
u, _ = torch.sort(v, descending=True)
|
| 758 |
+
cssv = torch.cumsum(u, 0) - 1
|
| 759 |
+
ind = torch.arange(1, b_agents + 1, device=v.device, dtype=v.dtype)
|
| 760 |
+
rho = torch.nonzero(u - cssv / ind > 0, as_tuple=False)[-1, 0]
|
| 761 |
+
theta = cssv[rho] / (rho + 1)
|
| 762 |
+
w = torch.clamp(v - theta, min=0)
|
| 763 |
+
return w.detach()
|
| 764 |
+
|
| 765 |
+
|
| 766 |
+
def weighted_linear_fit(xs: torch.Tensor, ys: torch.Tensor, weights: torch.Tensor, ridge: float = 1e-3) -> torch.Tensor:
|
| 767 |
+
"""Exact weighted empirical-risk minimizer for linear regression."""
|
| 768 |
+
b_agents, n, dim = xs.shape
|
| 769 |
+
x = torch.cat([xs, torch.ones((b_agents, n, 1), device=xs.device, dtype=xs.dtype)], dim=-1)
|
| 770 |
+
sample_w = (weights[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 771 |
+
flat_x, flat_y = x.reshape(-1, dim + 1), ys.reshape(-1)
|
| 772 |
+
lhs = flat_x.T @ (flat_x * sample_w[:, None]) + ridge * torch.eye(dim + 1, device=xs.device)
|
| 773 |
+
rhs = flat_x.T @ (flat_y * sample_w)
|
| 774 |
+
return torch.linalg.solve(lhs, rhs)
|
| 775 |
+
|
| 776 |
+
|
| 777 |
+
def concept_trial(seed: int, sigma2: float, d_rff: int, device: torch.device) -> dict:
|
| 778 |
+
g = torch.Generator(device=device).manual_seed(seed)
|
| 779 |
+
b_agents, n, dim, n_test = 100, 10, 20, 1000
|
| 780 |
+
signs = torch.where(torch.rand((b_agents,), generator=g, device=device) > .5, 1., -1.)
|
| 781 |
+
beta0 = torch.randn((dim,), generator=g, device=device)
|
| 782 |
+
eps = torch.randn((b_agents, dim), generator=g, device=device)
|
| 783 |
+
betas = signs[:, None] * math.sqrt(1 - sigma2) * beta0 + math.sqrt(sigma2) * eps
|
| 784 |
+
x = 1.0 + torch.randn((b_agents, n, dim), generator=g, device=device)
|
| 785 |
+
y = torch.einsum("bnd,bd->bn", x, betas) + math.sqrt(2.0) * torch.randn((b_agents, n), generator=g, device=device)
|
| 786 |
+
x_test = 1.0 + torch.randn((n_test, dim), generator=g, device=device)
|
| 787 |
+
y_test = x_test @ betas[0] + math.sqrt(2.0) * torch.randn((n_test,), generator=g, device=device)
|
| 788 |
+
# The paper's weighted Gaussian KME kernel gives X a 1/sqrt(d) scaling.
|
| 789 |
+
z = torch.cat([x, y[..., None]], dim=-1).reshape(-1, dim + 1)
|
| 790 |
+
scale = torch.cat([torch.full((dim,), 1 / math.sqrt(dim), device=device), torch.ones((1,), device=device)])
|
| 791 |
+
phi = rff(z, d_rff, g, scale).reshape(b_agents, n, d_rff)
|
| 792 |
+
means = phi.mean(1)
|
| 793 |
+
q_w = simplex_weights(means, phi[0])
|
| 794 |
+
local = torch.zeros(b_agents, device=device); local[0] = 1
|
| 795 |
+
grand = torch.full((b_agents,), 1 / b_agents, device=device)
|
| 796 |
+
oracle = (signs == signs[0]).float(); oracle /= oracle.sum()
|
| 797 |
+
result = {"sigma2": sigma2, "seed": seed, "q_local_weight": float(q_w[0]),
|
| 798 |
+
"q_same_group_weight": float(q_w[signs == signs[0]].sum())}
|
| 799 |
+
for name, weights in [("local", local), ("grandmean", grand), ("oracle", oracle), ("qaggregation", q_w)]:
|
| 800 |
+
beta = weighted_linear_fit(x, y, weights)
|
| 801 |
+
pred = x_test @ beta[:-1] + beta[-1]
|
| 802 |
+
result[f"{name}_mse"] = float(torch.mean((pred - y_test) ** 2))
|
| 803 |
+
return result
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
def run_concept(args: argparse.Namespace) -> list[dict]:
|
| 807 |
+
device = device_from_arg(args.device)
|
| 808 |
+
rows = []
|
| 809 |
+
for sigma2 in args.sigmas:
|
| 810 |
+
for rep in range(args.repeats):
|
| 811 |
+
rows.append(concept_trial(args.seed + rep * 101 + int(sigma2 * 1000), sigma2, args.rff_dim, device))
|
| 812 |
+
return rows
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
def exact_rbf_mmd(x: torch.Tensor, y: torch.Tensor, bandwidth: float = 1.0) -> torch.Tensor:
|
| 816 |
+
def k(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
|
| 817 |
+
return torch.exp(-torch.cdist(a, b).square() / (2 * bandwidth * bandwidth))
|
| 818 |
+
return torch.sqrt(torch.clamp(k(x, x).mean() + k(y, y).mean() - 2 * k(x, y).mean(), min=0.0))
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
def run_rff(args: argparse.Namespace) -> list[dict]:
|
| 822 |
+
device = device_from_arg(args.device)
|
| 823 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 824 |
+
x = torch.randn((300, 8), generator=g, device=device)
|
| 825 |
+
y = torch.randn((300, 8), generator=g, device=device) + torch.tensor([0.35] + [0.] * 7, device=device)
|
| 826 |
+
exact = float(exact_rbf_mmd(x, y))
|
| 827 |
+
rows = []
|
| 828 |
+
for d_rff in args.rff_grid:
|
| 829 |
+
errors = []
|
| 830 |
+
for trial in range(args.repeats):
|
| 831 |
+
tg = torch.Generator(device=device).manual_seed(args.seed + 1000 * d_rff + trial)
|
| 832 |
+
phi = rff(torch.cat([x, y]), d_rff, tg, torch.ones(8, device=device))
|
| 833 |
+
approx = torch.linalg.vector_norm(phi[:len(x)].mean(0) - phi[len(x):].mean(0)).item()
|
| 834 |
+
errors.append(abs(approx - exact))
|
| 835 |
+
rows.append({"rff_dim": d_rff, "exact_mmd": exact, "mean_abs_error": float(np.mean(errors)),
|
| 836 |
+
"std_abs_error": float(np.std(errors)), "sqrt_logB_over_D": math.sqrt(math.log(100) / d_rff),
|
| 837 |
+
"one_shot_floats_per_agent": d_rff})
|
| 838 |
+
return rows
|
| 839 |
+
|
| 840 |
+
|
| 841 |
+
def run_femnist(args: argparse.Namespace) -> list[dict]:
|
| 842 |
+
"""Actual FEMNIST writer data, deliberately scaled in samples/features/epochs."""
|
| 843 |
+
from datasets import load_dataset
|
| 844 |
+
device = device_from_arg(args.device)
|
| 845 |
+
local_parquet = ROOT / "data" / "femnist" / "data" / "train-00000-of-00001.parquet"
|
| 846 |
+
dataset = load_dataset("parquet", data_files=str(local_parquet), split="train", streaming=True) if local_parquet.exists() else load_dataset("flwrlabs/femnist", split="train", streaming=True)
|
| 847 |
+
by_writer: dict[str, list[tuple[np.ndarray, int]]] = {}
|
| 848 |
+
want = args.agents
|
| 849 |
+
for ex in dataset:
|
| 850 |
+
writer = ex["writer_id"]
|
| 851 |
+
if writer not in by_writer and len(by_writer) >= want:
|
| 852 |
+
continue
|
| 853 |
+
if writer in by_writer or len(by_writer) < want:
|
| 854 |
+
by_writer.setdefault(writer, []).append((np.asarray(ex["image"], dtype=np.float32) / 255., int(ex["character"])))
|
| 855 |
+
if len(by_writer) >= want and all(len(v) >= args.train_per_agent + args.test_per_agent for v in by_writer.values()):
|
| 856 |
+
break
|
| 857 |
+
eligible = [v for v in by_writer.values() if len(v) >= args.train_per_agent + args.test_per_agent][:want]
|
| 858 |
+
if len(eligible) < want:
|
| 859 |
+
raise RuntimeError(f"Only found {len(eligible)} eligible writers; need {want}")
|
| 860 |
+
x_train = torch.tensor(np.stack([np.stack([a for a, _ in v[:args.train_per_agent]]) for v in eligible]), device=device)
|
| 861 |
+
y_train = torch.tensor(np.stack([[b for _, b in v[:args.train_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 862 |
+
x_test = torch.tensor(np.stack([np.stack([a for a, _ in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]]) for v in eligible]), device=device)
|
| 863 |
+
y_test = torch.tensor(np.stack([[b for _, b in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 864 |
+
b_agents, n, raw_dim = x_train.shape[0], x_train.shape[1], 784
|
| 865 |
+
flat = x_train.reshape(b_agents, n, raw_dim)
|
| 866 |
+
# Fixed random projection reduces the RFF input cost while retaining a reproducible vision proxy.
|
| 867 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 868 |
+
proj = torch.randn((raw_dim, args.feature_dim), generator=g, device=device) / math.sqrt(raw_dim)
|
| 869 |
+
features = flat @ proj
|
| 870 |
+
phi_all = rff(features.reshape(-1, args.feature_dim), args.rff_dim, g, torch.ones(args.feature_dim, device=device)).reshape(b_agents, n, args.rff_dim)
|
| 871 |
+
means = phi_all.mean(1)
|
| 872 |
+
# Fit one regularized softmax classifier for each target using its personalized weights.
|
| 873 |
+
rows = []
|
| 874 |
+
all_x = features.reshape(-1, args.feature_dim)
|
| 875 |
+
all_y = y_train.reshape(-1)
|
| 876 |
+
for target in range(b_agents):
|
| 877 |
+
weights = simplex_weights(means, phi_all[target], steps=300)
|
| 878 |
+
schemes = {"local": torch.nn.functional.one_hot(torch.tensor(target, device=device), b_agents).float(),
|
| 879 |
+
"grandmean": torch.full((b_agents,), 1 / b_agents, device=device), "qaggregation": weights}
|
| 880 |
+
test_feat = x_test[target].reshape(args.test_per_agent, raw_dim) @ proj
|
| 881 |
+
for name, w in schemes.items():
|
| 882 |
+
model = torch.zeros((args.feature_dim, 62), device=device, requires_grad=True)
|
| 883 |
+
opt = torch.optim.Adam([model], lr=args.lr, weight_decay=1e-4)
|
| 884 |
+
sample_w = (w[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 885 |
+
for _ in range(args.epochs):
|
| 886 |
+
opt.zero_grad()
|
| 887 |
+
losses = torch.nn.functional.cross_entropy(all_x @ model, all_y, reduction="none")
|
| 888 |
+
(losses * sample_w).sum().backward(); opt.step()
|
| 889 |
+
acc = ((test_feat @ model).argmax(1) == y_test[target]).float().mean().item()
|
| 890 |
+
rows.append({"agent": target, "method": name, "accuracy": acc, "q_local_weight": float(weights[target])})
|
| 891 |
+
return rows
|
| 892 |
+
|
| 893 |
+
|
| 894 |
+
def write_rows(rows: list[dict], out: Path) -> None:
|
| 895 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 896 |
+
with out.open("w", newline="") as f:
|
| 897 |
+
writer = csv.DictWriter(f, fieldnames=list(rows[0]))
|
| 898 |
+
writer.writeheader(); writer.writerows(rows)
|
| 899 |
+
out.with_suffix(".json").write_text(json.dumps(rows, indent=2))
|
| 900 |
+
|
| 901 |
+
|
| 902 |
+
def main() -> None:
|
| 903 |
+
p = argparse.ArgumentParser()
|
| 904 |
+
p.add_argument("mode", choices=["concept", "rff", "femnist"])
|
| 905 |
+
p.add_argument("--output", type=Path, required=True)
|
| 906 |
+
p.add_argument("--device", default="auto")
|
| 907 |
+
p.add_argument("--seed", type=int, default=20260719)
|
| 908 |
+
p.add_argument("--repeats", type=int, default=30)
|
| 909 |
+
p.add_argument("--rff-dim", type=int, default=500)
|
| 910 |
+
p.add_argument("--sigmas", type=float, nargs="+", default=[0., .1, .25, .5, .75, 1.])
|
| 911 |
+
p.add_argument("--rff-grid", type=int, nargs="+", default=[16, 32, 64, 128, 256, 512, 1024])
|
| 912 |
+
p.add_argument("--agents", type=int, default=192)
|
| 913 |
+
p.add_argument("--train-per-agent", type=int, default=32)
|
| 914 |
+
p.add_argument("--test-per-agent", type=int, default=16)
|
| 915 |
+
p.add_argument("--feature-dim", type=int, default=64)
|
| 916 |
+
p.add_argument("--epochs", type=int, default=20)
|
| 917 |
+
p.add_argument("--lr", type=float, default=.08)
|
| 918 |
+
args = p.parse_args()
|
| 919 |
+
started = perf_counter()
|
| 920 |
+
rows = {"concept": run_concept, "rff": run_rff, "femnist": run_femnist}[args.mode](args)
|
| 921 |
+
write_rows(rows, args.output)
|
| 922 |
+
if args.mode == "concept":
|
| 923 |
+
summary = {str(s): {k: float(np.mean([r[k] for r in rows if r["sigma2"] == s])) for k in ["local_mse", "grandmean_mse", "oracle_mse", "qaggregation_mse", "q_local_weight", "q_same_group_weight"]} for s in args.sigmas}
|
| 924 |
+
print(json.dumps({"concept_summary": summary}, indent=2))
|
| 925 |
+
elif args.mode == "rff":
|
| 926 |
+
print(json.dumps({"rff_summary": {str(r["rff_dim"]): r["mean_abs_error"] for r in rows}}, indent=2))
|
| 927 |
+
elif args.mode == "femnist":
|
| 928 |
+
summary = {m: float(np.mean([r["accuracy"] for r in rows if r["method"] == m])) for m in ["local", "grandmean", "qaggregation"]}
|
| 929 |
+
print(json.dumps({"femnist_accuracy": summary}, indent=2))
|
| 930 |
+
print(json.dumps({"mode": args.mode, "rows": len(rows), "output": str(args.output), "seconds": round(perf_counter() - started, 2), "device": str(device_from_arg(args.device))}, indent=2))
|
| 931 |
+
|
| 932 |
+
|
| 933 |
+
if __name__ == "__main__":
|
| 934 |
+
main()
|
| 935 |
+
|
| 936 |
+
````
|
| 937 |
+
|
| 938 |
+
|
| 939 |
+
````output
|
| 940 |
+
{
|
| 941 |
+
"concept_summary": {
|
| 942 |
+
"0.0": {
|
| 943 |
+
"local_mse": 15.748318042755127,
|
| 944 |
+
"grandmean_mse": 40.606961507797244,
|
| 945 |
+
"oracle_mse": 2.0862513756752015,
|
| 946 |
+
"qaggregation_mse": 17.83958231449127,
|
| 947 |
+
"q_local_weight": 0.9771137142181396,
|
| 948 |
+
"q_same_group_weight": 0.9975556522607804
|
| 949 |
+
},
|
| 950 |
+
"0.1": {
|
| 951 |
+
"local_mse": 15.361917610168456,
|
| 952 |
+
"grandmean_mse": 45.73134832382202,
|
| 953 |
+
"oracle_mse": 6.119768922328949,
|
| 954 |
+
"qaggregation_mse": 18.07122127532959,
|
| 955 |
+
"q_local_weight": 0.9787336409091949,
|
| 956 |
+
"q_same_group_weight": 0.9981670784950256
|
| 957 |
+
},
|
| 958 |
+
"0.25": {
|
| 959 |
+
"local_mse": 15.827756361961365,
|
| 960 |
+
"grandmean_mse": 39.008377923965455,
|
| 961 |
+
"oracle_mse": 11.351614267826081,
|
| 962 |
+
"qaggregation_mse": 25.339054584503174,
|
| 963 |
+
"q_local_weight": 0.9825072956085205,
|
| 964 |
+
"q_same_group_weight": 0.99599778175354
|
| 965 |
+
},
|
| 966 |
+
"0.5": {
|
| 967 |
+
"local_mse": 14.459182372093201,
|
| 968 |
+
"grandmean_mse": 45.512830362319946,
|
| 969 |
+
"oracle_mse": 24.322485909461975,
|
| 970 |
+
"qaggregation_mse": 25.430337595939637,
|
| 971 |
+
"q_local_weight": 0.9876203048229217,
|
| 972 |
+
"q_same_group_weight": 0.9948384702205658
|
| 973 |
+
},
|
| 974 |
+
"0.75": {
|
| 975 |
+
"local_mse": 15.87236515045166,
|
| 976 |
+
"grandmean_mse": 39.63199781417847,
|
| 977 |
+
"oracle_mse": 30.853181953430177,
|
| 978 |
+
"qaggregation_mse": 33.74232290267944,
|
| 979 |
+
"q_local_weight": 0.9877495408058167,
|
| 980 |
+
"q_same_group_weight": 0.9943676108121872
|
| 981 |
+
},
|
| 982 |
+
"1.0": {
|
| 983 |
+
"local_mse": 15.390748682022094,
|
| 984 |
+
"grandmean_mse": 39.16119129180908,
|
| 985 |
+
"oracle_mse": 40.00151491165161,
|
| 986 |
+
"qaggregation_mse": 30.293080587387085,
|
| 987 |
+
"q_local_weight": 0.9896031093597412,
|
| 988 |
+
"q_same_group_weight": 0.9947122848033905
|
| 989 |
+
}
|
| 990 |
+
}
|
| 991 |
+
}
|
| 992 |
+
{
|
| 993 |
+
"mode": "concept",
|
| 994 |
+
"rows": 600,
|
| 995 |
+
"output": "outputs/concept_100agents_100reps.csv",
|
| 996 |
+
"seconds": 299.14,
|
| 997 |
+
"device": "cuda"
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
````
|
| 1001 |
+
|
| 1002 |
+
|
| 1003 |
+
---
|
| 1004 |
+
<!-- trackio-cell
|
| 1005 |
+
{"type": "artifact", "id": "cell_40a11b9e84e9", "created_at": "2026-07-19T09:50:42+00:00", "title": "Artifact: concept_100agents_100reps.csv", "path": "outputs/concept_100agents_100reps.csv", "size": 63718, "artifact_type": "dataset", "auto": true}
|
| 1006 |
+
-->
|
| 1007 |
+
**📦 Artifact** `outputs/concept_100agents_100reps.csv` · dataset · 63.7 kB
|
| 1008 |
+
|
| 1009 |
+
https://huggingface.co/buckets/vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts#logbook-files/outputs/concept_100agents_100reps.csv
|
| 1010 |
+
|
| 1011 |
+
|
| 1012 |
+
---
|
| 1013 |
+
<!-- trackio-cell
|
| 1014 |
+
{"type": "code", "id": "cell_09cae6dd6213", "created_at": "2026-07-19T09:51:35+00:00", "title": "Run: python reproduce.py (exit 0)", "command": ["/home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python", "src/reproduce.py", "--help"], "exit_code": 0, "duration_s": 0.941}
|
| 1015 |
+
-->
|
| 1016 |
+
````bash
|
| 1017 |
+
$ /home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python src/reproduce.py --help
|
| 1018 |
+
````
|
| 1019 |
+
|
| 1020 |
+
exit 0 · 0.9s
|
| 1021 |
+
|
| 1022 |
+
|
| 1023 |
+
````python title=reproduce.py
|
| 1024 |
+
#!/usr/bin/env python3
|
| 1025 |
+
"""Independent, GPU-capable checks for Fermanian et al. (2026), arXiv:2603.02233.
|
| 1026 |
+
|
| 1027 |
+
The implementation follows Algorithms 1--2 at a scaled experimental budget. It
|
| 1028 |
+
uses RFF KMEs to choose a target client's collaboration weights and fits the
|
| 1029 |
+
weighted empirical-risk minimizer exactly for linear regression. The FEMNIST
|
| 1030 |
+
mode uses the public natural writer partition and a linear softmax model.
|
| 1031 |
+
"""
|
| 1032 |
+
from __future__ import annotations
|
| 1033 |
+
|
| 1034 |
+
import argparse
|
| 1035 |
+
import csv
|
| 1036 |
+
import json
|
| 1037 |
+
import math
|
| 1038 |
+
from pathlib import Path
|
| 1039 |
+
from time import perf_counter
|
| 1040 |
+
|
| 1041 |
+
import numpy as np
|
| 1042 |
+
import torch
|
| 1043 |
+
|
| 1044 |
+
|
| 1045 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 1046 |
+
|
| 1047 |
+
|
| 1048 |
+
def device_from_arg(name: str) -> torch.device:
|
| 1049 |
+
if name == "auto":
|
| 1050 |
+
return torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 1051 |
+
return torch.device(name)
|
| 1052 |
+
|
| 1053 |
+
|
| 1054 |
+
def rff(z: torch.Tensor, d_rff: int, generator: torch.Generator, scale: torch.Tensor) -> torch.Tensor:
|
| 1055 |
+
"""Gaussian-kernel RFF, with a supplied coordinate rescaling."""
|
| 1056 |
+
w = torch.randn((z.shape[1], d_rff), generator=generator, device=z.device, dtype=z.dtype)
|
| 1057 |
+
w = w * scale[:, None]
|
| 1058 |
+
b = 2 * math.pi * torch.rand((d_rff,), generator=generator, device=z.device, dtype=z.dtype)
|
| 1059 |
+
return math.sqrt(2.0 / d_rff) * torch.cos(z @ w + b)
|
| 1060 |
+
|
| 1061 |
+
|
| 1062 |
+
def simplex_weights(means: torch.Tensor, target_phi: torch.Tensor, steps: int = 900) -> torch.Tensor:
|
| 1063 |
+
"""Solve Algorithm 1's empirical Q-aggregation objective by projected GD."""
|
| 1064 |
+
b_agents = means.shape[0]
|
| 1065 |
+
n1 = target_phi.shape[0]
|
| 1066 |
+
centered = target_phi - means[0]
|
| 1067 |
+
cov = centered.T @ centered / max(n1 - 1, 1)
|
| 1068 |
+
trace = torch.trace(cov)
|
| 1069 |
+
diffs = means[1:] - means[0]
|
| 1070 |
+
q_terms = torch.sqrt(torch.clamp(torch.einsum("bd,df,bf->b", diffs, cov, diffs), min=0.0) + 1e-12)
|
| 1071 |
+
p_terms = torch.linalg.vector_norm(diffs, dim=1)
|
| 1072 |
+
# Table 1 uses CQ^2=CP=log B: CQ=sqrt(log B), CP=log B.
|
| 1073 |
+
cq, cp = math.sqrt(math.log(b_agents)), math.log(b_agents)
|
| 1074 |
+
w = torch.full((b_agents,), 1.0 / b_agents, device=means.device, dtype=means.dtype)
|
| 1075 |
+
for _ in range(steps):
|
| 1076 |
+
w.requires_grad_(True)
|
| 1077 |
+
mixture = w @ means
|
| 1078 |
+
loss = torch.sum((mixture - means[0]) ** 2) + 2.0 * w[0] * trace / n1
|
| 1079 |
+
loss = loss + cq / math.sqrt(n1) * torch.dot(w[1:], q_terms)
|
| 1080 |
+
loss = loss + cp / n1 * torch.dot(w[1:], p_terms)
|
| 1081 |
+
(grad,) = torch.autograd.grad(loss, w)
|
| 1082 |
+
with torch.no_grad():
|
| 1083 |
+
# Euclidean projection on the simplex, Duchi et al. (2008).
|
| 1084 |
+
v = w - 0.04 * grad
|
| 1085 |
+
u, _ = torch.sort(v, descending=True)
|
| 1086 |
+
cssv = torch.cumsum(u, 0) - 1
|
| 1087 |
+
ind = torch.arange(1, b_agents + 1, device=v.device, dtype=v.dtype)
|
| 1088 |
+
rho = torch.nonzero(u - cssv / ind > 0, as_tuple=False)[-1, 0]
|
| 1089 |
+
theta = cssv[rho] / (rho + 1)
|
| 1090 |
+
w = torch.clamp(v - theta, min=0)
|
| 1091 |
+
return w.detach()
|
| 1092 |
+
|
| 1093 |
+
|
| 1094 |
+
def weighted_linear_fit(xs: torch.Tensor, ys: torch.Tensor, weights: torch.Tensor, ridge: float = 1e-3) -> torch.Tensor:
|
| 1095 |
+
"""Exact weighted empirical-risk minimizer for linear regression."""
|
| 1096 |
+
b_agents, n, dim = xs.shape
|
| 1097 |
+
x = torch.cat([xs, torch.ones((b_agents, n, 1), device=xs.device, dtype=xs.dtype)], dim=-1)
|
| 1098 |
+
sample_w = (weights[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 1099 |
+
flat_x, flat_y = x.reshape(-1, dim + 1), ys.reshape(-1)
|
| 1100 |
+
lhs = flat_x.T @ (flat_x * sample_w[:, None]) + ridge * torch.eye(dim + 1, device=xs.device)
|
| 1101 |
+
rhs = flat_x.T @ (flat_y * sample_w)
|
| 1102 |
+
return torch.linalg.solve(lhs, rhs)
|
| 1103 |
+
|
| 1104 |
+
|
| 1105 |
+
def concept_trial(seed: int, sigma2: float, d_rff: int, device: torch.device) -> dict:
|
| 1106 |
+
g = torch.Generator(device=device).manual_seed(seed)
|
| 1107 |
+
b_agents, n, dim, n_test = 100, 10, 20, 1000
|
| 1108 |
+
signs = torch.where(torch.rand((b_agents,), generator=g, device=device) > .5, 1., -1.)
|
| 1109 |
+
beta0 = torch.randn((dim,), generator=g, device=device)
|
| 1110 |
+
eps = torch.randn((b_agents, dim), generator=g, device=device)
|
| 1111 |
+
betas = signs[:, None] * math.sqrt(1 - sigma2) * beta0 + math.sqrt(sigma2) * eps
|
| 1112 |
+
x = 1.0 + torch.randn((b_agents, n, dim), generator=g, device=device)
|
| 1113 |
+
y = torch.einsum("bnd,bd->bn", x, betas) + math.sqrt(2.0) * torch.randn((b_agents, n), generator=g, device=device)
|
| 1114 |
+
x_test = 1.0 + torch.randn((n_test, dim), generator=g, device=device)
|
| 1115 |
+
y_test = x_test @ betas[0] + math.sqrt(2.0) * torch.randn((n_test,), generator=g, device=device)
|
| 1116 |
+
# The paper's weighted Gaussian KME kernel gives X a 1/sqrt(d) scaling.
|
| 1117 |
+
z = torch.cat([x, y[..., None]], dim=-1).reshape(-1, dim + 1)
|
| 1118 |
+
scale = torch.cat([torch.full((dim,), 1 / math.sqrt(dim), device=device), torch.ones((1,), device=device)])
|
| 1119 |
+
phi = rff(z, d_rff, g, scale).reshape(b_agents, n, d_rff)
|
| 1120 |
+
means = phi.mean(1)
|
| 1121 |
+
q_w = simplex_weights(means, phi[0])
|
| 1122 |
+
local = torch.zeros(b_agents, device=device); local[0] = 1
|
| 1123 |
+
grand = torch.full((b_agents,), 1 / b_agents, device=device)
|
| 1124 |
+
oracle = (signs == signs[0]).float(); oracle /= oracle.sum()
|
| 1125 |
+
result = {"sigma2": sigma2, "seed": seed, "q_local_weight": float(q_w[0]),
|
| 1126 |
+
"q_same_group_weight": float(q_w[signs == signs[0]].sum())}
|
| 1127 |
+
for name, weights in [("local", local), ("grandmean", grand), ("oracle", oracle), ("qaggregation", q_w)]:
|
| 1128 |
+
beta = weighted_linear_fit(x, y, weights)
|
| 1129 |
+
pred = x_test @ beta[:-1] + beta[-1]
|
| 1130 |
+
result[f"{name}_mse"] = float(torch.mean((pred - y_test) ** 2))
|
| 1131 |
+
return result
|
| 1132 |
+
|
| 1133 |
+
|
| 1134 |
+
def run_concept(args: argparse.Namespace) -> list[dict]:
|
| 1135 |
+
device = device_from_arg(args.device)
|
| 1136 |
+
rows = []
|
| 1137 |
+
for sigma2 in args.sigmas:
|
| 1138 |
+
for rep in range(args.repeats):
|
| 1139 |
+
rows.append(concept_trial(args.seed + rep * 101 + int(sigma2 * 1000), sigma2, args.rff_dim, device))
|
| 1140 |
+
return rows
|
| 1141 |
+
|
| 1142 |
+
|
| 1143 |
+
def exact_rbf_mmd(x: torch.Tensor, y: torch.Tensor, bandwidth: float = 1.0) -> torch.Tensor:
|
| 1144 |
+
def k(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
|
| 1145 |
+
return torch.exp(-torch.cdist(a, b).square() / (2 * bandwidth * bandwidth))
|
| 1146 |
+
return torch.sqrt(torch.clamp(k(x, x).mean() + k(y, y).mean() - 2 * k(x, y).mean(), min=0.0))
|
| 1147 |
+
|
| 1148 |
+
|
| 1149 |
+
def run_rff(args: argparse.Namespace) -> list[dict]:
|
| 1150 |
+
device = device_from_arg(args.device)
|
| 1151 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 1152 |
+
x = torch.randn((300, 8), generator=g, device=device)
|
| 1153 |
+
y = torch.randn((300, 8), generator=g, device=device) + torch.tensor([0.35] + [0.] * 7, device=device)
|
| 1154 |
+
exact = float(exact_rbf_mmd(x, y))
|
| 1155 |
+
rows = []
|
| 1156 |
+
for d_rff in args.rff_grid:
|
| 1157 |
+
errors = []
|
| 1158 |
+
for trial in range(args.repeats):
|
| 1159 |
+
tg = torch.Generator(device=device).manual_seed(args.seed + 1000 * d_rff + trial)
|
| 1160 |
+
phi = rff(torch.cat([x, y]), d_rff, tg, torch.ones(8, device=device))
|
| 1161 |
+
approx = torch.linalg.vector_norm(phi[:len(x)].mean(0) - phi[len(x):].mean(0)).item()
|
| 1162 |
+
errors.append(abs(approx - exact))
|
| 1163 |
+
rows.append({"rff_dim": d_rff, "exact_mmd": exact, "mean_abs_error": float(np.mean(errors)),
|
| 1164 |
+
"std_abs_error": float(np.std(errors)), "sqrt_logB_over_D": math.sqrt(math.log(100) / d_rff),
|
| 1165 |
+
"one_shot_floats_per_agent": d_rff})
|
| 1166 |
+
return rows
|
| 1167 |
+
|
| 1168 |
+
|
| 1169 |
+
def run_femnist(args: argparse.Namespace) -> list[dict]:
|
| 1170 |
+
"""Actual FEMNIST writer data, deliberately scaled in samples/features/epochs."""
|
| 1171 |
+
from datasets import load_dataset
|
| 1172 |
+
device = device_from_arg(args.device)
|
| 1173 |
+
local_parquet = ROOT / "data" / "femnist" / "data" / "train-00000-of-00001.parquet"
|
| 1174 |
+
dataset = load_dataset("parquet", data_files=str(local_parquet), split="train", streaming=True) if local_parquet.exists() else load_dataset("flwrlabs/femnist", split="train", streaming=True)
|
| 1175 |
+
by_writer: dict[str, list[tuple[np.ndarray, int]]] = {}
|
| 1176 |
+
want = args.agents
|
| 1177 |
+
for ex in dataset:
|
| 1178 |
+
writer = ex["writer_id"]
|
| 1179 |
+
if writer not in by_writer and len(by_writer) >= want:
|
| 1180 |
+
continue
|
| 1181 |
+
if writer in by_writer or len(by_writer) < want:
|
| 1182 |
+
by_writer.setdefault(writer, []).append((np.asarray(ex["image"], dtype=np.float32) / 255., int(ex["character"])))
|
| 1183 |
+
if len(by_writer) >= want and all(len(v) >= args.train_per_agent + args.test_per_agent for v in by_writer.values()):
|
| 1184 |
+
break
|
| 1185 |
+
eligible = [v for v in by_writer.values() if len(v) >= args.train_per_agent + args.test_per_agent][:want]
|
| 1186 |
+
if len(eligible) < want:
|
| 1187 |
+
raise RuntimeError(f"Only found {len(eligible)} eligible writers; need {want}")
|
| 1188 |
+
x_train = torch.tensor(np.stack([np.stack([a for a, _ in v[:args.train_per_agent]]) for v in eligible]), device=device)
|
| 1189 |
+
y_train = torch.tensor(np.stack([[b for _, b in v[:args.train_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 1190 |
+
x_test = torch.tensor(np.stack([np.stack([a for a, _ in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]]) for v in eligible]), device=device)
|
| 1191 |
+
y_test = torch.tensor(np.stack([[b for _, b in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 1192 |
+
b_agents, n, raw_dim = x_train.shape[0], x_train.shape[1], 784
|
| 1193 |
+
flat = x_train.reshape(b_agents, n, raw_dim)
|
| 1194 |
+
# Fixed random projection reduces the RFF input cost while retaining a reproducible vision proxy.
|
| 1195 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 1196 |
+
proj = torch.randn((raw_dim, args.feature_dim), generator=g, device=device) / math.sqrt(raw_dim)
|
| 1197 |
+
features = flat @ proj
|
| 1198 |
+
phi_all = rff(features.reshape(-1, args.feature_dim), args.rff_dim, g, torch.ones(args.feature_dim, device=device)).reshape(b_agents, n, args.rff_dim)
|
| 1199 |
+
means = phi_all.mean(1)
|
| 1200 |
+
# Fit one regularized softmax classifier for each target using its personalized weights.
|
| 1201 |
+
rows = []
|
| 1202 |
+
all_x = features.reshape(-1, args.feature_dim)
|
| 1203 |
+
all_y = y_train.reshape(-1)
|
| 1204 |
+
for target in range(b_agents):
|
| 1205 |
+
weights = simplex_weights(means, phi_all[target], steps=300)
|
| 1206 |
+
schemes = {"local": torch.nn.functional.one_hot(torch.tensor(target, device=device), b_agents).float(),
|
| 1207 |
+
"grandmean": torch.full((b_agents,), 1 / b_agents, device=device), "qaggregation": weights}
|
| 1208 |
+
test_feat = x_test[target].reshape(args.test_per_agent, raw_dim) @ proj
|
| 1209 |
+
for name, w in schemes.items():
|
| 1210 |
+
model = torch.zeros((args.feature_dim, 62), device=device, requires_grad=True)
|
| 1211 |
+
opt = torch.optim.Adam([model], lr=args.lr, weight_decay=1e-4)
|
| 1212 |
+
sample_w = (w[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 1213 |
+
for _ in range(args.epochs):
|
| 1214 |
+
opt.zero_grad()
|
| 1215 |
+
losses = torch.nn.functional.cross_entropy(all_x @ model, all_y, reduction="none")
|
| 1216 |
+
(losses * sample_w).sum().backward(); opt.step()
|
| 1217 |
+
acc = ((test_feat @ model).argmax(1) == y_test[target]).float().mean().item()
|
| 1218 |
+
rows.append({"agent": target, "method": name, "accuracy": acc, "q_local_weight": float(weights[target])})
|
| 1219 |
+
return rows
|
| 1220 |
+
|
| 1221 |
+
|
| 1222 |
+
def write_rows(rows: list[dict], out: Path) -> None:
|
| 1223 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 1224 |
+
with out.open("w", newline="") as f:
|
| 1225 |
+
writer = csv.DictWriter(f, fieldnames=list(rows[0]))
|
| 1226 |
+
writer.writeheader(); writer.writerows(rows)
|
| 1227 |
+
out.with_suffix(".json").write_text(json.dumps(rows, indent=2))
|
| 1228 |
+
|
| 1229 |
+
|
| 1230 |
+
def main() -> None:
|
| 1231 |
+
p = argparse.ArgumentParser()
|
| 1232 |
+
p.add_argument("mode", choices=["concept", "rff", "femnist"])
|
| 1233 |
+
p.add_argument("--output", type=Path, required=True)
|
| 1234 |
+
p.add_argument("--device", default="auto")
|
| 1235 |
+
p.add_argument("--seed", type=int, default=20260719)
|
| 1236 |
+
p.add_argument("--repeats", type=int, default=30)
|
| 1237 |
+
p.add_argument("--rff-dim", type=int, default=500)
|
| 1238 |
+
p.add_argument("--sigmas", type=float, nargs="+", default=[0., .1, .25, .5, .75, 1.])
|
| 1239 |
+
p.add_argument("--rff-grid", type=int, nargs="+", default=[16, 32, 64, 128, 256, 512, 1024])
|
| 1240 |
+
p.add_argument("--agents", type=int, default=192)
|
| 1241 |
+
p.add_argument("--train-per-agent", type=int, default=32)
|
| 1242 |
+
p.add_argument("--test-per-agent", type=int, default=16)
|
| 1243 |
+
p.add_argument("--feature-dim", type=int, default=64)
|
| 1244 |
+
p.add_argument("--epochs", type=int, default=20)
|
| 1245 |
+
p.add_argument("--lr", type=float, default=.08)
|
| 1246 |
+
args = p.parse_args()
|
| 1247 |
+
started = perf_counter()
|
| 1248 |
+
rows = {"concept": run_concept, "rff": run_rff, "femnist": run_femnist}[args.mode](args)
|
| 1249 |
+
write_rows(rows, args.output)
|
| 1250 |
+
if args.mode == "concept":
|
| 1251 |
+
summary = {str(s): {k: float(np.mean([r[k] for r in rows if r["sigma2"] == s])) for k in ["local_mse", "grandmean_mse", "oracle_mse", "qaggregation_mse", "q_local_weight", "q_same_group_weight"]} for s in args.sigmas}
|
| 1252 |
+
print(json.dumps({"concept_summary": summary}, indent=2))
|
| 1253 |
+
elif args.mode == "rff":
|
| 1254 |
+
print(json.dumps({"rff_summary": {str(r["rff_dim"]): r["mean_abs_error"] for r in rows}}, indent=2))
|
| 1255 |
+
elif args.mode == "femnist":
|
| 1256 |
+
summary = {m: float(np.mean([r["accuracy"] for r in rows if r["method"] == m])) for m in ["local", "grandmean", "qaggregation"]}
|
| 1257 |
+
print(json.dumps({"femnist_accuracy": summary}, indent=2))
|
| 1258 |
+
print(json.dumps({"mode": args.mode, "rows": len(rows), "output": str(args.output), "seconds": round(perf_counter() - started, 2), "device": str(device_from_arg(args.device))}, indent=2))
|
| 1259 |
+
|
| 1260 |
+
|
| 1261 |
+
if __name__ == "__main__":
|
| 1262 |
+
main()
|
| 1263 |
+
|
| 1264 |
+
````
|
| 1265 |
+
|
| 1266 |
+
|
| 1267 |
+
````output
|
| 1268 |
+
usage: reproduce.py [-h] --output OUTPUT [--device DEVICE] [--seed SEED]
|
| 1269 |
+
[--repeats REPEATS] [--rff-dim RFF_DIM]
|
| 1270 |
+
[--sigmas SIGMAS [SIGMAS ...]]
|
| 1271 |
+
[--rff-grid RFF_GRID [RFF_GRID ...]] [--agents AGENTS]
|
| 1272 |
+
[--train-per-agent TRAIN_PER_AGENT]
|
| 1273 |
+
[--test-per-agent TEST_PER_AGENT]
|
| 1274 |
+
[--feature-dim FEATURE_DIM] [--epochs EPOCHS] [--lr LR]
|
| 1275 |
+
{concept,rff,femnist}
|
| 1276 |
+
|
| 1277 |
+
positional arguments:
|
| 1278 |
+
{concept,rff,femnist}
|
| 1279 |
+
|
| 1280 |
+
options:
|
| 1281 |
+
-h, --help show this help message and exit
|
| 1282 |
+
--output OUTPUT
|
| 1283 |
+
--device DEVICE
|
| 1284 |
+
--seed SEED
|
| 1285 |
+
--repeats REPEATS
|
| 1286 |
+
--rff-dim RFF_DIM
|
| 1287 |
+
--sigmas SIGMAS [SIGMAS ...]
|
| 1288 |
+
--rff-grid RFF_GRID [RFF_GRID ...]
|
| 1289 |
+
--agents AGENTS
|
| 1290 |
+
--train-per-agent TRAIN_PER_AGENT
|
| 1291 |
+
--test-per-agent TEST_PER_AGENT
|
| 1292 |
+
--feature-dim FEATURE_DIM
|
| 1293 |
+
--epochs EPOCHS
|
| 1294 |
+
--lr LR
|
| 1295 |
+
|
| 1296 |
+
````
|
| 1297 |
+
|
| 1298 |
+
|
| 1299 |
+
---
|
| 1300 |
+
<!-- trackio-cell
|
| 1301 |
+
{"type": "markdown", "id": "cell_8356b325c920", "created_at": "2026-07-19T09:54:23+00:00", "title": "Evidence and status"}
|
| 1302 |
+
-->
|
| 1303 |
+
Independent CUDA reproduction used the paper’s , , , noise variance 2, , and 100 repetitions ([paper](https://arxiv.org/pdf/2603.02233), Sec. 6.1/Table 1). It uses an independent projected-gradient implementation of Algorithm 1 and exact weighted linear-risk minimization. Contrary to the paper’s transition claim, its Q weights remained almost local (mean target weight 0.977–0.990) and Q MSE was worse than Local at all tested (e.g. 17.84 vs 15.75 at 0; 25.43 vs 14.46 at .5). **Status: not reproduced by this independent implementation.** The full configuration, CUDA run, and CSV are captured here; no official code was found.
|
| 1304 |
+
|
| 1305 |
+
|
| 1306 |
+
---
|
| 1307 |
+
<!-- trackio-cell
|
| 1308 |
+
{"type": "markdown", "id": "cell_4a35924ff734", "created_at": "2026-07-19T09:57:06+00:00", "title": "Clarified evidence"}
|
| 1309 |
+
-->
|
| 1310 |
+
Clarification of measured scope: B=100, n=10/client, d=20, noise variance 2, D=500, 100 repetitions, CUDA. Q target weight was 0.977 to 0.990 across sigma_c squared values and Q MSE was worse than local at every tested value. This independent literal implementation does not reproduce the reported transition; it is not presented as a refutation because official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 7 |
+
-->
|
| 8 |
+
Document setup, runs, and results for **Claim 6: Section 6.3 FEMNIST 192-agent benchmark**.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
<!-- trackio-cell
|
| 13 |
+
{"type": "code", "id": "cell_5675f10a2abb", "created_at": "2026-07-19T09:52:42+00:00", "title": "Run: env reproduce.py (exit 0)", "command": ["env", "CUDA_VISIBLE_DEVICES=1", "/home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python", "src/reproduce.py", "femnist", "--agents", "192", "--train-per-agent", "32", "--test-per-agent", "16", "--feature-dim", "64", "--rff-dim", "1000", "--epochs", "20", "--lr", "0.08", "--output", "outputs/femnist_192agents_scaled.csv", "--device", "cuda"], "exit_code": 0, "duration_s": 33.426}
|
| 14 |
+
-->
|
| 15 |
+
````bash
|
| 16 |
+
$ env CUDA_VISIBLE_DEVICES=1 /home/vim/miniconda3/envs/pytorch-gpu-hf/bin/python src/reproduce.py femnist --agents 192 --train-per-agent 32 --test-per-agent 16 --feature-dim 64 --rff-dim 1000 --epochs 20 --lr 0.08 --output outputs/femnist_192agents_scaled.csv --device cuda
|
| 17 |
+
````
|
| 18 |
+
|
| 19 |
+
exit 0 · 33.4s
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
````python title=reproduce.py
|
| 23 |
+
#!/usr/bin/env python3
|
| 24 |
+
"""Independent, GPU-capable checks for Fermanian et al. (2026), arXiv:2603.02233.
|
| 25 |
+
|
| 26 |
+
The implementation follows Algorithms 1--2 at a scaled experimental budget. It
|
| 27 |
+
uses RFF KMEs to choose a target client's collaboration weights and fits the
|
| 28 |
+
weighted empirical-risk minimizer exactly for linear regression. The FEMNIST
|
| 29 |
+
mode uses the public natural writer partition and a linear softmax model.
|
| 30 |
+
"""
|
| 31 |
+
from __future__ import annotations
|
| 32 |
+
|
| 33 |
+
import argparse
|
| 34 |
+
import csv
|
| 35 |
+
import json
|
| 36 |
+
import math
|
| 37 |
+
from pathlib import Path
|
| 38 |
+
from time import perf_counter
|
| 39 |
+
|
| 40 |
+
import numpy as np
|
| 41 |
+
import torch
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def device_from_arg(name: str) -> torch.device:
|
| 48 |
+
if name == "auto":
|
| 49 |
+
return torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 50 |
+
return torch.device(name)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def rff(z: torch.Tensor, d_rff: int, generator: torch.Generator, scale: torch.Tensor) -> torch.Tensor:
|
| 54 |
+
"""Gaussian-kernel RFF, with a supplied coordinate rescaling."""
|
| 55 |
+
w = torch.randn((z.shape[1], d_rff), generator=generator, device=z.device, dtype=z.dtype)
|
| 56 |
+
w = w * scale[:, None]
|
| 57 |
+
b = 2 * math.pi * torch.rand((d_rff,), generator=generator, device=z.device, dtype=z.dtype)
|
| 58 |
+
return math.sqrt(2.0 / d_rff) * torch.cos(z @ w + b)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def simplex_weights(means: torch.Tensor, target_phi: torch.Tensor, steps: int = 900) -> torch.Tensor:
|
| 62 |
+
"""Solve Algorithm 1's empirical Q-aggregation objective by projected GD."""
|
| 63 |
+
b_agents = means.shape[0]
|
| 64 |
+
n1 = target_phi.shape[0]
|
| 65 |
+
centered = target_phi - means[0]
|
| 66 |
+
cov = centered.T @ centered / max(n1 - 1, 1)
|
| 67 |
+
trace = torch.trace(cov)
|
| 68 |
+
diffs = means[1:] - means[0]
|
| 69 |
+
q_terms = torch.sqrt(torch.clamp(torch.einsum("bd,df,bf->b", diffs, cov, diffs), min=0.0) + 1e-12)
|
| 70 |
+
p_terms = torch.linalg.vector_norm(diffs, dim=1)
|
| 71 |
+
# Table 1 uses CQ^2=CP=log B: CQ=sqrt(log B), CP=log B.
|
| 72 |
+
cq, cp = math.sqrt(math.log(b_agents)), math.log(b_agents)
|
| 73 |
+
w = torch.full((b_agents,), 1.0 / b_agents, device=means.device, dtype=means.dtype)
|
| 74 |
+
for _ in range(steps):
|
| 75 |
+
w.requires_grad_(True)
|
| 76 |
+
mixture = w @ means
|
| 77 |
+
loss = torch.sum((mixture - means[0]) ** 2) + 2.0 * w[0] * trace / n1
|
| 78 |
+
loss = loss + cq / math.sqrt(n1) * torch.dot(w[1:], q_terms)
|
| 79 |
+
loss = loss + cp / n1 * torch.dot(w[1:], p_terms)
|
| 80 |
+
(grad,) = torch.autograd.grad(loss, w)
|
| 81 |
+
with torch.no_grad():
|
| 82 |
+
# Euclidean projection on the simplex, Duchi et al. (2008).
|
| 83 |
+
v = w - 0.04 * grad
|
| 84 |
+
u, _ = torch.sort(v, descending=True)
|
| 85 |
+
cssv = torch.cumsum(u, 0) - 1
|
| 86 |
+
ind = torch.arange(1, b_agents + 1, device=v.device, dtype=v.dtype)
|
| 87 |
+
rho = torch.nonzero(u - cssv / ind > 0, as_tuple=False)[-1, 0]
|
| 88 |
+
theta = cssv[rho] / (rho + 1)
|
| 89 |
+
w = torch.clamp(v - theta, min=0)
|
| 90 |
+
return w.detach()
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def weighted_linear_fit(xs: torch.Tensor, ys: torch.Tensor, weights: torch.Tensor, ridge: float = 1e-3) -> torch.Tensor:
|
| 94 |
+
"""Exact weighted empirical-risk minimizer for linear regression."""
|
| 95 |
+
b_agents, n, dim = xs.shape
|
| 96 |
+
x = torch.cat([xs, torch.ones((b_agents, n, 1), device=xs.device, dtype=xs.dtype)], dim=-1)
|
| 97 |
+
sample_w = (weights[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 98 |
+
flat_x, flat_y = x.reshape(-1, dim + 1), ys.reshape(-1)
|
| 99 |
+
lhs = flat_x.T @ (flat_x * sample_w[:, None]) + ridge * torch.eye(dim + 1, device=xs.device)
|
| 100 |
+
rhs = flat_x.T @ (flat_y * sample_w)
|
| 101 |
+
return torch.linalg.solve(lhs, rhs)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def concept_trial(seed: int, sigma2: float, d_rff: int, device: torch.device) -> dict:
|
| 105 |
+
g = torch.Generator(device=device).manual_seed(seed)
|
| 106 |
+
b_agents, n, dim, n_test = 100, 10, 20, 1000
|
| 107 |
+
signs = torch.where(torch.rand((b_agents,), generator=g, device=device) > .5, 1., -1.)
|
| 108 |
+
beta0 = torch.randn((dim,), generator=g, device=device)
|
| 109 |
+
eps = torch.randn((b_agents, dim), generator=g, device=device)
|
| 110 |
+
betas = signs[:, None] * math.sqrt(1 - sigma2) * beta0 + math.sqrt(sigma2) * eps
|
| 111 |
+
x = 1.0 + torch.randn((b_agents, n, dim), generator=g, device=device)
|
| 112 |
+
y = torch.einsum("bnd,bd->bn", x, betas) + math.sqrt(2.0) * torch.randn((b_agents, n), generator=g, device=device)
|
| 113 |
+
x_test = 1.0 + torch.randn((n_test, dim), generator=g, device=device)
|
| 114 |
+
y_test = x_test @ betas[0] + math.sqrt(2.0) * torch.randn((n_test,), generator=g, device=device)
|
| 115 |
+
# The paper's weighted Gaussian KME kernel gives X a 1/sqrt(d) scaling.
|
| 116 |
+
z = torch.cat([x, y[..., None]], dim=-1).reshape(-1, dim + 1)
|
| 117 |
+
scale = torch.cat([torch.full((dim,), 1 / math.sqrt(dim), device=device), torch.ones((1,), device=device)])
|
| 118 |
+
phi = rff(z, d_rff, g, scale).reshape(b_agents, n, d_rff)
|
| 119 |
+
means = phi.mean(1)
|
| 120 |
+
q_w = simplex_weights(means, phi[0])
|
| 121 |
+
local = torch.zeros(b_agents, device=device); local[0] = 1
|
| 122 |
+
grand = torch.full((b_agents,), 1 / b_agents, device=device)
|
| 123 |
+
oracle = (signs == signs[0]).float(); oracle /= oracle.sum()
|
| 124 |
+
result = {"sigma2": sigma2, "seed": seed, "q_local_weight": float(q_w[0]),
|
| 125 |
+
"q_same_group_weight": float(q_w[signs == signs[0]].sum())}
|
| 126 |
+
for name, weights in [("local", local), ("grandmean", grand), ("oracle", oracle), ("qaggregation", q_w)]:
|
| 127 |
+
beta = weighted_linear_fit(x, y, weights)
|
| 128 |
+
pred = x_test @ beta[:-1] + beta[-1]
|
| 129 |
+
result[f"{name}_mse"] = float(torch.mean((pred - y_test) ** 2))
|
| 130 |
+
return result
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def run_concept(args: argparse.Namespace) -> list[dict]:
|
| 134 |
+
device = device_from_arg(args.device)
|
| 135 |
+
rows = []
|
| 136 |
+
for sigma2 in args.sigmas:
|
| 137 |
+
for rep in range(args.repeats):
|
| 138 |
+
rows.append(concept_trial(args.seed + rep * 101 + int(sigma2 * 1000), sigma2, args.rff_dim, device))
|
| 139 |
+
return rows
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def exact_rbf_mmd(x: torch.Tensor, y: torch.Tensor, bandwidth: float = 1.0) -> torch.Tensor:
|
| 143 |
+
def k(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
|
| 144 |
+
return torch.exp(-torch.cdist(a, b).square() / (2 * bandwidth * bandwidth))
|
| 145 |
+
return torch.sqrt(torch.clamp(k(x, x).mean() + k(y, y).mean() - 2 * k(x, y).mean(), min=0.0))
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def run_rff(args: argparse.Namespace) -> list[dict]:
|
| 149 |
+
device = device_from_arg(args.device)
|
| 150 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 151 |
+
x = torch.randn((300, 8), generator=g, device=device)
|
| 152 |
+
y = torch.randn((300, 8), generator=g, device=device) + torch.tensor([0.35] + [0.] * 7, device=device)
|
| 153 |
+
exact = float(exact_rbf_mmd(x, y))
|
| 154 |
+
rows = []
|
| 155 |
+
for d_rff in args.rff_grid:
|
| 156 |
+
errors = []
|
| 157 |
+
for trial in range(args.repeats):
|
| 158 |
+
tg = torch.Generator(device=device).manual_seed(args.seed + 1000 * d_rff + trial)
|
| 159 |
+
phi = rff(torch.cat([x, y]), d_rff, tg, torch.ones(8, device=device))
|
| 160 |
+
approx = torch.linalg.vector_norm(phi[:len(x)].mean(0) - phi[len(x):].mean(0)).item()
|
| 161 |
+
errors.append(abs(approx - exact))
|
| 162 |
+
rows.append({"rff_dim": d_rff, "exact_mmd": exact, "mean_abs_error": float(np.mean(errors)),
|
| 163 |
+
"std_abs_error": float(np.std(errors)), "sqrt_logB_over_D": math.sqrt(math.log(100) / d_rff),
|
| 164 |
+
"one_shot_floats_per_agent": d_rff})
|
| 165 |
+
return rows
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def run_femnist(args: argparse.Namespace) -> list[dict]:
|
| 169 |
+
"""Actual FEMNIST writer data, deliberately scaled in samples/features/epochs."""
|
| 170 |
+
from datasets import load_dataset
|
| 171 |
+
device = device_from_arg(args.device)
|
| 172 |
+
local_parquet = ROOT / "data" / "femnist" / "data" / "train-00000-of-00001.parquet"
|
| 173 |
+
dataset = load_dataset("parquet", data_files=str(local_parquet), split="train", streaming=True) if local_parquet.exists() else load_dataset("flwrlabs/femnist", split="train", streaming=True)
|
| 174 |
+
by_writer: dict[str, list[tuple[np.ndarray, int]]] = {}
|
| 175 |
+
want = args.agents
|
| 176 |
+
for ex in dataset:
|
| 177 |
+
writer = ex["writer_id"]
|
| 178 |
+
if writer not in by_writer and len(by_writer) >= want:
|
| 179 |
+
continue
|
| 180 |
+
if writer in by_writer or len(by_writer) < want:
|
| 181 |
+
by_writer.setdefault(writer, []).append((np.asarray(ex["image"], dtype=np.float32) / 255., int(ex["character"])))
|
| 182 |
+
if len(by_writer) >= want and all(len(v) >= args.train_per_agent + args.test_per_agent for v in by_writer.values()):
|
| 183 |
+
break
|
| 184 |
+
eligible = [v for v in by_writer.values() if len(v) >= args.train_per_agent + args.test_per_agent][:want]
|
| 185 |
+
if len(eligible) < want:
|
| 186 |
+
raise RuntimeError(f"Only found {len(eligible)} eligible writers; need {want}")
|
| 187 |
+
x_train = torch.tensor(np.stack([np.stack([a for a, _ in v[:args.train_per_agent]]) for v in eligible]), device=device)
|
| 188 |
+
y_train = torch.tensor(np.stack([[b for _, b in v[:args.train_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 189 |
+
x_test = torch.tensor(np.stack([np.stack([a for a, _ in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]]) for v in eligible]), device=device)
|
| 190 |
+
y_test = torch.tensor(np.stack([[b for _, b in v[args.train_per_agent:args.train_per_agent + args.test_per_agent]] for v in eligible]), device=device, dtype=torch.long)
|
| 191 |
+
b_agents, n, raw_dim = x_train.shape[0], x_train.shape[1], 784
|
| 192 |
+
flat = x_train.reshape(b_agents, n, raw_dim)
|
| 193 |
+
# Fixed random projection reduces the RFF input cost while retaining a reproducible vision proxy.
|
| 194 |
+
g = torch.Generator(device=device).manual_seed(args.seed)
|
| 195 |
+
proj = torch.randn((raw_dim, args.feature_dim), generator=g, device=device) / math.sqrt(raw_dim)
|
| 196 |
+
features = flat @ proj
|
| 197 |
+
phi_all = rff(features.reshape(-1, args.feature_dim), args.rff_dim, g, torch.ones(args.feature_dim, device=device)).reshape(b_agents, n, args.rff_dim)
|
| 198 |
+
means = phi_all.mean(1)
|
| 199 |
+
# Fit one regularized softmax classifier for each target using its personalized weights.
|
| 200 |
+
rows = []
|
| 201 |
+
all_x = features.reshape(-1, args.feature_dim)
|
| 202 |
+
all_y = y_train.reshape(-1)
|
| 203 |
+
for target in range(b_agents):
|
| 204 |
+
weights = simplex_weights(means, phi_all[target], steps=300)
|
| 205 |
+
schemes = {"local": torch.nn.functional.one_hot(torch.tensor(target, device=device), b_agents).float(),
|
| 206 |
+
"grandmean": torch.full((b_agents,), 1 / b_agents, device=device), "qaggregation": weights}
|
| 207 |
+
test_feat = x_test[target].reshape(args.test_per_agent, raw_dim) @ proj
|
| 208 |
+
for name, w in schemes.items():
|
| 209 |
+
model = torch.zeros((args.feature_dim, 62), device=device, requires_grad=True)
|
| 210 |
+
opt = torch.optim.Adam([model], lr=args.lr, weight_decay=1e-4)
|
| 211 |
+
sample_w = (w[:, None] / n).expand(b_agents, n).reshape(-1)
|
| 212 |
+
for _ in range(args.epochs):
|
| 213 |
+
opt.zero_grad()
|
| 214 |
+
losses = torch.nn.functional.cross_entropy(all_x @ model, all_y, reduction="none")
|
| 215 |
+
(losses * sample_w).sum().backward(); opt.step()
|
| 216 |
+
acc = ((test_feat @ model).argmax(1) == y_test[target]).float().mean().item()
|
| 217 |
+
rows.append({"agent": target, "method": name, "accuracy": acc, "q_local_weight": float(weights[target])})
|
| 218 |
+
return rows
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def write_rows(rows: list[dict], out: Path) -> None:
|
| 222 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 223 |
+
with out.open("w", newline="") as f:
|
| 224 |
+
writer = csv.DictWriter(f, fieldnames=list(rows[0]))
|
| 225 |
+
writer.writeheader(); writer.writerows(rows)
|
| 226 |
+
out.with_suffix(".json").write_text(json.dumps(rows, indent=2))
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def main() -> None:
|
| 230 |
+
p = argparse.ArgumentParser()
|
| 231 |
+
p.add_argument("mode", choices=["concept", "rff", "femnist"])
|
| 232 |
+
p.add_argument("--output", type=Path, required=True)
|
| 233 |
+
p.add_argument("--device", default="auto")
|
| 234 |
+
p.add_argument("--seed", type=int, default=20260719)
|
| 235 |
+
p.add_argument("--repeats", type=int, default=30)
|
| 236 |
+
p.add_argument("--rff-dim", type=int, default=500)
|
| 237 |
+
p.add_argument("--sigmas", type=float, nargs="+", default=[0., .1, .25, .5, .75, 1.])
|
| 238 |
+
p.add_argument("--rff-grid", type=int, nargs="+", default=[16, 32, 64, 128, 256, 512, 1024])
|
| 239 |
+
p.add_argument("--agents", type=int, default=192)
|
| 240 |
+
p.add_argument("--train-per-agent", type=int, default=32)
|
| 241 |
+
p.add_argument("--test-per-agent", type=int, default=16)
|
| 242 |
+
p.add_argument("--feature-dim", type=int, default=64)
|
| 243 |
+
p.add_argument("--epochs", type=int, default=20)
|
| 244 |
+
p.add_argument("--lr", type=float, default=.08)
|
| 245 |
+
args = p.parse_args()
|
| 246 |
+
started = perf_counter()
|
| 247 |
+
rows = {"concept": run_concept, "rff": run_rff, "femnist": run_femnist}[args.mode](args)
|
| 248 |
+
write_rows(rows, args.output)
|
| 249 |
+
if args.mode == "concept":
|
| 250 |
+
summary = {str(s): {k: float(np.mean([r[k] for r in rows if r["sigma2"] == s])) for k in ["local_mse", "grandmean_mse", "oracle_mse", "qaggregation_mse", "q_local_weight", "q_same_group_weight"]} for s in args.sigmas}
|
| 251 |
+
print(json.dumps({"concept_summary": summary}, indent=2))
|
| 252 |
+
elif args.mode == "rff":
|
| 253 |
+
print(json.dumps({"rff_summary": {str(r["rff_dim"]): r["mean_abs_error"] for r in rows}}, indent=2))
|
| 254 |
+
elif args.mode == "femnist":
|
| 255 |
+
summary = {m: float(np.mean([r["accuracy"] for r in rows if r["method"] == m])) for m in ["local", "grandmean", "qaggregation"]}
|
| 256 |
+
print(json.dumps({"femnist_accuracy": summary}, indent=2))
|
| 257 |
+
print(json.dumps({"mode": args.mode, "rows": len(rows), "output": str(args.output), "seconds": round(perf_counter() - started, 2), "device": str(device_from_arg(args.device))}, indent=2))
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
if __name__ == "__main__":
|
| 261 |
+
main()
|
| 262 |
+
|
| 263 |
+
````
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
````output
|
| 267 |
+
{
|
| 268 |
+
"femnist_accuracy": {
|
| 269 |
+
"local": 0.2503255208333333,
|
| 270 |
+
"grandmean": 0.24283854166666666,
|
| 271 |
+
"qaggregation": 0.17578125
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
{
|
| 275 |
+
"mode": "femnist",
|
| 276 |
+
"rows": 576,
|
| 277 |
+
"output": "outputs/femnist_192agents_scaled.csv",
|
| 278 |
+
"seconds": 32.19,
|
| 279 |
+
"device": "cuda"
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
````
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
---
|
| 286 |
+
<!-- trackio-cell
|
| 287 |
+
{"type": "artifact", "id": "cell_a404932005b6", "created_at": "2026-07-19T09:52:42+00:00", "title": "Artifact: femnist_192agents_scaled.csv", "path": "outputs/femnist_192agents_scaled.csv", "size": 14226, "artifact_type": "dataset", "auto": true}
|
| 288 |
+
-->
|
| 289 |
+
**�� Artifact** `outputs/femnist_192agents_scaled.csv` · dataset · 14.2 kB
|
| 290 |
+
|
| 291 |
+
https://huggingface.co/buckets/vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts#logbook-files/outputs/femnist_192agents_scaled.csv
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
---
|
| 295 |
+
<!-- trackio-cell
|
| 296 |
+
{"type": "markdown", "id": "cell_87c9b71c7614", "created_at": "2026-07-19T09:57:23+00:00", "title": "Clarified evidence"}
|
| 297 |
+
-->
|
| 298 |
+
Actual public dataset: https://huggingface.co/datasets/flwrlabs/femnist . Scope: 192 natural writer partitions, D=1000, CUDA; scaled to 32 train and 16 test examples/writer, 64 projected features, and 20 linear-softmax epochs. Mean accuracy: local 0.2503, grand mean 0.2428, Q aggregation 0.1758. The full paper MLP uses 2000 epochs, so this is a non-reproducing scaled check, not a full replication.
|
pages/conclusion/page.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Conclusion
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
---
|
| 5 |
+
<!-- trackio-cell
|
| 6 |
+
{"type": "markdown", "id": "cell_5ef64984e3ab", "created_at": "2026-07-19T09:32:03+00:00", "title": "Reproduction bundle"}
|
| 7 |
+
-->
|
| 8 |
+
The reproduction bundle contains the independent GPU-capable implementation, CSV results, rendered Posterly artifact, gate report, and rerun instructions. It excludes local caches and the replaceable FEMNIST Parquet download.
|
| 9 |
+
|
| 10 |
+
After publication, download the bundle from the artifact cell, open `README.md`, and run its CUDA commands. Public data source: https://huggingface.co/datasets/flwrlabs/femnist .
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
---
|
| 14 |
+
<!-- trackio-cell
|
| 15 |
+
{"type": "artifact", "id": "cell_175c3d4d70bd", "created_at": "2026-07-19T10:07:56+00:00", "title": "Reproduction bundle", "artifact": "repro-adaptive-personalized-federated-learning-via-multi-task-averaging-of-kernel-mean-embedding/repro-bundle:v0", "artifact_type": "dataset"}
|
| 16 |
+
-->
|
| 17 |
+
**📦 Artifact** `repro-adaptive-personalized-federated-learning-via-multi-task-averaging-of-kernel-mean-embedding/repro-bundle:v0` · dataset
|
| 18 |
+
|
| 19 |
+
https://huggingface.co/buckets/vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts#repro-adaptive-personalized-federated-learning-via-multi-task-averaging-of-kernel-mean-embedding/repro-bundle:v0
|
pages/executive-summary/page.md
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pages/index.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Reproduction: Adaptive Personalized Federated Learning via Multi-task Averaging of Kernel Mean Embeddings
|
| 2 |
+
|
| 3 |
+
[OpenReview paper](https://openreview.net/forum?id=ADHGbxsREr)
|
| 4 |
+
|
| 5 |
+
## Pages
|
| 6 |
+
|
| 7 |
+
| Page |
|
| 8 |
+
| --- |
|
| 9 |
+
| [Executive summary](#/executive-summary) |
|
| 10 |
+
| [Claim 1: Theorem 4.4 finite-sample KME guarantee](#/claim-1-theorem-4-4-finite-sample-kme-guarantee) |
|
| 11 |
+
| [Claim 2: Corollary 4.6 downstream excess-risk transfer](#/claim-2-corollary-4-6-downstream-excess-risk-transfer) |
|
| 12 |
+
| [Claim 3: Example 4.5 automatic adaptive collaboration](#/claim-3-example-4-5-automatic-adaptive-collaboration) |
|
| 13 |
+
| [Claim 4: Theorem 5.2 random Fourier-feature tradeoff](#/claim-4-theorem-5-2-random-fourier-feature-tradeoff) |
|
| 14 |
+
| [Claim 5: Section 6.1 100-agent synthetic concept shift](#/claim-5-section-6-1-100-agent-synthetic-concept-shift) |
|
| 15 |
+
| [Claim 6: Section 6.3 FEMNIST 192-agent benchmark](#/claim-6-section-6-3-femnist-192-agent-benchmark) |
|
| 16 |
+
| [Conclusion](#/conclusion) |
|
trackio-logo-light.png
ADDED
|
trackio-logo.png
ADDED
|
trackio-wordmark-dark.png
ADDED
|
workspace.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 1,
|
| 3 |
+
"file_count": 0,
|
| 4 |
+
"total_size": 0,
|
| 5 |
+
"files": [],
|
| 6 |
+
"hub_refs": [
|
| 7 |
+
{
|
| 8 |
+
"url": "https://huggingface.co/jobs/vimarsh/6a5c9e7cbee6ee1cf4ed0df8",
|
| 9 |
+
"type": "Jobs",
|
| 10 |
+
"label": "vimarsh/6a5c9e7cbee6ee1cf4ed0df8"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"url": "https://huggingface.co/buckets/vimarsh/jobs-artifacts",
|
| 14 |
+
"type": "Buckets",
|
| 15 |
+
"label": "vimarsh/jobs-artifacts"
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"url": "https://huggingface.co/buckets/vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts#logbook-files/outputs/rff_tradeoff_100seeds.csv",
|
| 19 |
+
"type": "Buckets",
|
| 20 |
+
"label": "vimarsh/repro-adaptive-personalized-fl-multi-task-averaging-kernel-mean-embedding-artifacts"
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"url": "https://huggingface.co/datasets/flwrlabs/femnist",
|
| 24 |
+
"type": "Datasets",
|
| 25 |
+
"label": "flwrlabs/femnist"
|
| 26 |
+
}
|
| 27 |
+
],
|
| 28 |
+
"reference_only": true
|
| 29 |
+
}
|