Spaces:
Runtime error
Runtime error
Dockerize
Browse files- .dockerignore +17 -0
- Dockerfile +54 -0
- README.md +106 -13
- bench/src/server/index.ts +1 -1
.dockerignore
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
.git
|
| 3 |
+
.gitignore
|
| 4 |
+
*.md
|
| 5 |
+
!README.md
|
| 6 |
+
*.log
|
| 7 |
+
.DS_Store
|
| 8 |
+
.env
|
| 9 |
+
.env.*
|
| 10 |
+
!.env.example
|
| 11 |
+
dist
|
| 12 |
+
.bench-cache
|
| 13 |
+
benchmark-results.jsonl
|
| 14 |
+
bench-node
|
| 15 |
+
bench-web
|
| 16 |
+
.vscode
|
| 17 |
+
.idea
|
Dockerfile
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:22-slim
|
| 2 |
+
|
| 3 |
+
# Install dependencies for Playwright browsers
|
| 4 |
+
RUN apt-get update && apt-get install -y \
|
| 5 |
+
wget \
|
| 6 |
+
gnupg \
|
| 7 |
+
ca-certificates \
|
| 8 |
+
fonts-liberation \
|
| 9 |
+
libasound2 \
|
| 10 |
+
libatk-bridge2.0-0 \
|
| 11 |
+
libatk1.0-0 \
|
| 12 |
+
libatspi2.0-0 \
|
| 13 |
+
libcups2 \
|
| 14 |
+
libdbus-1-3 \
|
| 15 |
+
libdrm2 \
|
| 16 |
+
libgbm1 \
|
| 17 |
+
libgtk-3-0 \
|
| 18 |
+
libnspr4 \
|
| 19 |
+
libnss3 \
|
| 20 |
+
libwayland-client0 \
|
| 21 |
+
libxcomposite1 \
|
| 22 |
+
libxdamage1 \
|
| 23 |
+
libxfixes3 \
|
| 24 |
+
libxkbcommon0 \
|
| 25 |
+
libxrandr2 \
|
| 26 |
+
xdg-utils \
|
| 27 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 28 |
+
|
| 29 |
+
WORKDIR /app
|
| 30 |
+
|
| 31 |
+
# Copy bench package files
|
| 32 |
+
COPY bench/package*.json ./bench/
|
| 33 |
+
|
| 34 |
+
# Install dependencies
|
| 35 |
+
WORKDIR /app/bench
|
| 36 |
+
RUN npm ci
|
| 37 |
+
|
| 38 |
+
# Install Playwright browsers
|
| 39 |
+
RUN npx playwright install chromium firefox webkit
|
| 40 |
+
|
| 41 |
+
# Copy source code
|
| 42 |
+
WORKDIR /app
|
| 43 |
+
COPY bench/ ./bench/
|
| 44 |
+
|
| 45 |
+
# Expose port
|
| 46 |
+
EXPOSE 7860
|
| 47 |
+
|
| 48 |
+
# Health check
|
| 49 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
| 50 |
+
CMD node -e "require('http').get('http://localhost:7860/', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
| 51 |
+
|
| 52 |
+
# Start the server
|
| 53 |
+
WORKDIR /app/bench
|
| 54 |
+
CMD ["npm", "run", "server"]
|
README.md
CHANGED
|
@@ -1,19 +1,112 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
- `bench-node/`: Node CLI with `--mode warm|cold`, `--repeats`, `--cache-dir`.
|
| 5 |
-
- `bench-web/`: Browser app with warm (prefetch+reload) / cold (clear caches) and repeats.
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
```bash
|
| 10 |
-
|
| 11 |
-
npm i
|
| 12 |
-
npm run bench -- Xenova/distilbert-base-uncased feature-extraction --mode warm --repeats 5 --cache-dir .bench-cache/warm
|
| 13 |
```
|
| 14 |
-
|
|
|
|
| 15 |
```bash
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Transformers.js Benchmark Server
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
| 9 |
|
| 10 |
+
# Transformers.js Benchmark Server
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
A REST API server for running and managing Transformers.js benchmarks on both Node.js and browser (via Playwright) platforms.
|
| 13 |
+
|
| 14 |
+
## Features
|
| 15 |
+
|
| 16 |
+
- **Queue-based benchmark execution**: Submit benchmarks via REST API and process them sequentially
|
| 17 |
+
- **Multi-platform support**: Run benchmarks on Node.js or in browsers (via Playwright)
|
| 18 |
+
- **Result persistence**: Store benchmark results in JSONL format
|
| 19 |
+
- **Validation**: Request validation using Zod schemas
|
| 20 |
+
- **CLI client**: Command-line interface for interacting with the server
|
| 21 |
+
|
| 22 |
+
## API Endpoints
|
| 23 |
+
|
| 24 |
+
### Submit Benchmark
|
| 25 |
+
```bash
|
| 26 |
+
POST /api/benchmark
|
| 27 |
+
Content-Type: application/json
|
| 28 |
+
|
| 29 |
+
{
|
| 30 |
+
"platform": "node", # "node" or "web"
|
| 31 |
+
"modelId": "Xenova/all-MiniLM-L6-v2",
|
| 32 |
+
"task": "feature-extraction",
|
| 33 |
+
"mode": "warm", # "warm" or "cold"
|
| 34 |
+
"repeats": 3,
|
| 35 |
+
"dtype": "fp32", # fp32, fp16, q8, int8, uint8, q4, bnb4, q4f16
|
| 36 |
+
"batchSize": 1,
|
| 37 |
+
"device": "webgpu", # For web: "webgpu" or "wasm"
|
| 38 |
+
"browser": "chromium", # For web: "chromium", "firefox", "webkit"
|
| 39 |
+
"headed": false
|
| 40 |
+
}
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
### Get Benchmark Result
|
| 44 |
```bash
|
| 45 |
+
GET /api/benchmark/:id
|
|
|
|
|
|
|
| 46 |
```
|
| 47 |
+
|
| 48 |
+
### List All Benchmarks
|
| 49 |
```bash
|
| 50 |
+
GET /api/benchmarks
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
### Queue Status
|
| 54 |
+
```bash
|
| 55 |
+
GET /api/queue
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
### Clear Results
|
| 59 |
+
```bash
|
| 60 |
+
DELETE /api/benchmarks
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
## Architecture
|
| 64 |
+
|
| 65 |
+
```
|
| 66 |
+
.
|
| 67 |
+
βββ bench/ # Benchmark server and execution logic
|
| 68 |
+
β βββ src/
|
| 69 |
+
β β βββ core/ # Shared types and utilities
|
| 70 |
+
β β βββ node/ # Node.js benchmark runner
|
| 71 |
+
β β βββ web/ # Browser benchmark runner (Playwright)
|
| 72 |
+
β β βββ server/ # REST API server (Hono)
|
| 73 |
+
β βββ package.json
|
| 74 |
+
βββ client/ # CLI client for the server
|
| 75 |
+
β βββ src/
|
| 76 |
+
β β βββ index.ts # Yargs-based CLI
|
| 77 |
+
β βββ package.json
|
| 78 |
+
βββ Dockerfile
|
| 79 |
```
|
| 80 |
+
|
| 81 |
+
## Development
|
| 82 |
+
|
| 83 |
+
### Running locally
|
| 84 |
+
|
| 85 |
+
1. Install dependencies:
|
| 86 |
+
```bash
|
| 87 |
+
cd bench && npm install
|
| 88 |
+
cd ../client && npm install
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
2. Install Playwright browsers:
|
| 92 |
+
```bash
|
| 93 |
+
cd bench && npm run bench:install
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
3. Start the server:
|
| 97 |
+
```bash
|
| 98 |
+
cd bench && npm run server
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
4. Use the CLI client:
|
| 102 |
+
```bash
|
| 103 |
+
cd client && npm run cli -- submit Xenova/all-MiniLM-L6-v2 feature-extraction --wait
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
## Deployment
|
| 107 |
+
|
| 108 |
+
This server is designed to run on Hugging Face Spaces using Docker. The Dockerfile includes all necessary dependencies including Playwright browsers for running web-based benchmarks.
|
| 109 |
+
|
| 110 |
+
## License
|
| 111 |
+
|
| 112 |
+
MIT
|
bench/src/server/index.ts
CHANGED
|
@@ -232,7 +232,7 @@ curl -X POST http://localhost:3000/api/benchmark \\
|
|
| 232 |
`);
|
| 233 |
});
|
| 234 |
|
| 235 |
-
const PORT = Number(process.env.PORT) ||
|
| 236 |
|
| 237 |
serve({
|
| 238 |
fetch: app.fetch,
|
|
|
|
| 232 |
`);
|
| 233 |
});
|
| 234 |
|
| 235 |
+
const PORT = Number(process.env.PORT) || 7860;
|
| 236 |
|
| 237 |
serve({
|
| 238 |
fetch: app.fetch,
|