Quazim0t0 commited on
Commit
d446697
·
verified ·
1 Parent(s): 9f6ed60

FineWeb-Edu parquet streaming: /data endpoint (hyparquet over CDN range requests)

Browse files
Files changed (1) hide show
  1. server.js +46 -0
server.js CHANGED
@@ -30,6 +30,39 @@ const PUB = path.join(__dirname, "public");
30
  const TYPES = { ".html": "text/html", ".js": "text/javascript",
31
  ".css": "text/css", ".json": "application/json" };
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  // keepalive: proxies (incl. HuggingFace's) close idle WebSockets — ping every
34
  // 30s keeps the pipe warm and detects dead clients within a minute
35
  setInterval(() => {
@@ -53,6 +86,19 @@ const server = http.createServer((req, res) => {
53
  try { if (process.env.DAISY_RTC_CONFIG) rtc = JSON.parse(process.env.DAISY_RTC_CONFIG); } catch (e) {}
54
  return res.end(JSON.stringify({ forceRooms: !!process.env.DAISY_FORCE_ROOMS, rtc }));
55
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  if (p === "/") p = "/index.html";
57
  const file = path.join(PUB, path.normalize(p));
58
  if (!file.startsWith(PUB)) { res.writeHead(403); return res.end(); }
 
30
  const TYPES = { ".html": "text/html", ".js": "text/javascript",
31
  ".css": "text/css", ".json": "application/json" };
32
 
33
+ // ---- training text: FineWeb-Edu, served by THIS server ----------------------
34
+ // The browser used to call datasets-server.huggingface.co/rows directly, which
35
+ // 503s routinely under load. The parquet files themselves sit on the HF CDN
36
+ // behind plain resolve/ URLs — public, range-request friendly, and far more
37
+ // reliable than the rows API. So this endpoint reads a random slice of a
38
+ // random shard of the 10BT sample straight off the CDN with hyparquet (pure
39
+ // JS, no native deps) and hands the browser plain text. FineWeb-Edu is the
40
+ // ONLY dataset; there is no pass-through of client-chosen dataset ids.
41
+ const FWE_BASE = "https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu/resolve/main/sample/10BT/";
42
+ const FWE_SHARDS = Array.from({ length: 14 }, (_, i) => `${String(i).padStart(3, "0")}_00000.parquet`);
43
+ const FWE_ROWS_PER_SLICE = 130; // ~550k chars, what one training run consumes
44
+ const fweCache = new Map(); // shard -> { file, metadata } (metadata is ~kBs)
45
+ let hyparquet = null; // ESM — loaded on first use
46
+
47
+ async function fweSlice() {
48
+ hyparquet = hyparquet || await import("hyparquet");
49
+ const shard = FWE_SHARDS[Math.floor(Math.random() * FWE_SHARDS.length)];
50
+ let entry = fweCache.get(shard);
51
+ if (!entry) {
52
+ const file = await hyparquet.asyncBufferFromUrl({ url: FWE_BASE + shard });
53
+ const metadata = await hyparquet.parquetMetadataAsync(file);
54
+ entry = { file, metadata };
55
+ fweCache.set(shard, entry);
56
+ }
57
+ const total = Number(entry.metadata.num_rows);
58
+ const start = Math.floor(Math.random() * Math.max(1, total - FWE_ROWS_PER_SLICE));
59
+ const rows = await hyparquet.parquetReadObjects({
60
+ file: entry.file, metadata: entry.metadata, columns: ["text"],
61
+ rowStart: start, rowEnd: start + FWE_ROWS_PER_SLICE,
62
+ });
63
+ return { shard, start, text: rows.map(r => r.text).join("\n") };
64
+ }
65
+
66
  // keepalive: proxies (incl. HuggingFace's) close idle WebSockets — ping every
67
  // 30s keeps the pipe warm and detects dead clients within a minute
68
  setInterval(() => {
 
86
  try { if (process.env.DAISY_RTC_CONFIG) rtc = JSON.parse(process.env.DAISY_RTC_CONFIG); } catch (e) {}
87
  return res.end(JSON.stringify({ forceRooms: !!process.env.DAISY_FORCE_ROOMS, rtc }));
88
  }
89
+ if (p === "/data") { // a fresh random slice of FineWeb-Edu
90
+ return fweSlice()
91
+ .then(({ shard, start, text }) => {
92
+ res.writeHead(200, { "Content-Type": "text/plain; charset=utf-8",
93
+ "X-FWE-Shard": shard, "X-FWE-Row": String(start) });
94
+ res.end(text);
95
+ })
96
+ .catch((e) => {
97
+ console.error("fineweb slice failed:", e.message);
98
+ res.writeHead(503, { "Content-Type": "text/plain" });
99
+ res.end("fineweb-edu unavailable: " + e.message);
100
+ });
101
+ }
102
  if (p === "/") p = "/index.html";
103
  const file = path.join(PUB, path.normalize(p));
104
  if (!file.startsWith(PUB)) { res.writeHead(403); return res.end(); }