whitphx HF Staff commited on
Commit
4f0e494
·
1 Parent(s): 0a2c317

Fix exclusion logic

Browse files
Files changed (1) hide show
  1. client/src/index.ts +42 -25
client/src/index.ts CHANGED
@@ -105,6 +105,7 @@ async function fetchExistingBenchmarks(datasetRepo: string, token?: string): Pro
105
  name: datasetRepo,
106
  },
107
  credentials: token ? { accessToken: token } : undefined,
 
108
  })) {
109
  if (file.path.endsWith(".json")) {
110
  existingFiles.add(file.path);
@@ -120,10 +121,15 @@ async function fetchExistingBenchmarks(datasetRepo: string, token?: string): Pro
120
  }
121
 
122
  /**
123
- * Generate the expected file path for a benchmark combination
124
- * Must match the path generation logic in the server
 
 
 
 
 
125
  */
126
- function generateBenchmarkPath(combo: {
127
  task: string;
128
  modelId: string;
129
  platform: string;
@@ -134,43 +140,54 @@ function generateBenchmarkPath(combo: {
134
  browser?: string;
135
  headed?: boolean;
136
  }): string {
137
- // Extract org and model name from modelId
138
- const parts = combo.modelId.split("/");
139
- const org = parts.length > 1 ? parts[0] : "default";
140
- const modelName = parts.length > 1 ? parts[1] : parts[0];
141
-
142
- // Build path components similar to server logic
143
- const pathParts = [
144
- combo.task,
145
- org,
146
- modelName,
147
- ];
148
 
149
- // Build filename parts
150
  const filenameParts = [
151
  combo.platform,
152
  combo.mode,
153
  combo.device,
154
- `b${combo.batchSize}`,
155
  ];
156
 
157
- // Add dtype if specified and not fp32 (default)
158
- if (combo.dtype && combo.dtype !== "fp32") {
159
  filenameParts.push(combo.dtype);
160
  }
161
 
162
- // Add browser for web platform
 
 
 
163
  if (combo.platform === "web" && combo.browser) {
164
  filenameParts.push(combo.browser);
165
  }
166
 
167
- // Add headed indicator for web platform
168
  if (combo.platform === "web" && combo.headed) {
169
  filenameParts.push("headed");
170
  }
171
 
172
- const filename = filenameParts.join("_") + ".json";
173
- return [...pathParts, filename].join("/");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  }
175
 
176
  yargs(hideBin(process.argv))
@@ -547,10 +564,10 @@ yargs(hideBin(process.argv))
547
 
548
  const existingFiles = await fetchExistingBenchmarks(datasetRepo, hfToken);
549
 
550
- // Filter combinations
551
  filteredCombinations = combinations.filter((combo) => {
552
  const modelTask = task || combo.task || "feature-extraction";
553
- const benchmarkPath = generateBenchmarkPath({
554
  task: modelTask,
555
  modelId: combo.modelId,
556
  platform: combo.platform,
@@ -561,7 +578,7 @@ yargs(hideBin(process.argv))
561
  browser: combo.browser,
562
  headed: false, // Default, as it's not in the combination
563
  });
564
- return !existingFiles.has(benchmarkPath);
565
  });
566
 
567
  const excludedCount = combinations.length - filteredCombinations.length;
 
105
  name: datasetRepo,
106
  },
107
  credentials: token ? { accessToken: token } : undefined,
108
+ recursive: true,
109
  })) {
110
  if (file.path.endsWith(".json")) {
111
  existingFiles.add(file.path);
 
121
  }
122
 
123
  /**
124
+ * Generate a path pattern to match existing benchmarks
125
+ * Since we can't predict environment info (CPU cores, memory), we use pattern matching
126
+ *
127
+ * Server path format: {task}/{org}/{model}/{platform}_{mode}_{device}_{dtype?}_{batch}_{browser?}_{headed?}_{env...}.json
128
+ * Example: image-classification/Xenova/beit-large-patch16-384/web_warm_wasm_fp32_b1_chromium_32c_8gb.json
129
+ *
130
+ * We generate a prefix pattern and check if any existing file starts with it
131
  */
132
+ function generateBenchmarkPattern(combo: {
133
  task: string;
134
  modelId: string;
135
  platform: string;
 
140
  browser?: string;
141
  headed?: boolean;
142
  }): string {
143
+ // Build directory path: task/modelId/
144
+ const dirPath = `${combo.task}/${combo.modelId}`;
 
 
 
 
 
 
 
 
 
145
 
146
+ // Build filename parts (same order as server's generateFilenameParts)
147
  const filenameParts = [
148
  combo.platform,
149
  combo.mode,
150
  combo.device,
 
151
  ];
152
 
153
+ // Add dtype if specified
154
+ if (combo.dtype) {
155
  filenameParts.push(combo.dtype);
156
  }
157
 
158
+ // Batch size
159
+ filenameParts.push(`b${combo.batchSize}`);
160
+
161
+ // Browser for web platform
162
  if (combo.platform === "web" && combo.browser) {
163
  filenameParts.push(combo.browser);
164
  }
165
 
166
+ // Headed indicator for web platform
167
  if (combo.platform === "web" && combo.headed) {
168
  filenameParts.push("headed");
169
  }
170
 
171
+ // Return pattern: everything before environment info
172
+ // The server may add: cpu-name, cores (e.g., "32c"), memory (e.g., "8gb"), arch, gpu-vendor
173
+ const filenamePrefix = filenameParts.join("_");
174
+ return `${dirPath}/${filenamePrefix}`;
175
+ }
176
+
177
+ /**
178
+ * Check if a benchmark combination matches any existing file
179
+ * Handles the fact that server adds environment info that we can't predict
180
+ */
181
+ function matchesExistingBenchmark(pattern: string, existingFiles: Set<string>): boolean {
182
+ // Check if any existing file starts with our pattern
183
+ // Example pattern: "image-classification/Xenova/beit-large-patch16-384/web_warm_wasm_fp32_b1_chromium"
184
+ // Example file: "image-classification/Xenova/beit-large-patch16-384/web_warm_wasm_fp32_b1_chromium_32c_8gb.json"
185
+ for (const file of existingFiles) {
186
+ if (file.startsWith(pattern)) {
187
+ return true;
188
+ }
189
+ }
190
+ return false;
191
  }
192
 
193
  yargs(hideBin(process.argv))
 
564
 
565
  const existingFiles = await fetchExistingBenchmarks(datasetRepo, hfToken);
566
 
567
+ // Filter combinations using pattern matching
568
  filteredCombinations = combinations.filter((combo) => {
569
  const modelTask = task || combo.task || "feature-extraction";
570
+ const pattern = generateBenchmarkPattern({
571
  task: modelTask,
572
  modelId: combo.modelId,
573
  platform: combo.platform,
 
578
  browser: combo.browser,
579
  headed: false, // Default, as it's not in the combination
580
  });
581
+ return !matchesExistingBenchmark(pattern, existingFiles);
582
  });
583
 
584
  const excludedCount = combinations.length - filteredCombinations.length;