Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.20.1'
node-version: '20'
cache: 'pnpm'

- name: Install pnpm
run: |
npm install -g pnpm@latest
echo "pnpm version:"
pnpm --version
- name: Verify pnpm
run: pnpm --version

- name: Install build dependencies for native modules
run: |
Expand All @@ -44,18 +46,3 @@ jobs:
run: pnpm test
env:
PNPM_CACHE_DIR: ~/.pnpm-store

- name: Build API
run: pnpm build:api
env:
PNPM_CACHE_DIR: ~/.pnpm-store

- name: Build Web
run: pnpm build:web
env:
PNPM_CACHE_DIR: ~/.pnpm-store

- name: Run integration tests
run: pnpm test:api
env:
PNPM_CACHE_DIR: ~/.pnpm-store
19 changes: 4 additions & 15 deletions apps/api/src/modules/scraper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { scrapeRunSchema, modelSchema } from '@ollamacheck/shared/src/schema';
import { z } from 'zod';
import { v4 as uuidv4 } from 'uuid';
import fetch from 'node-fetch';
import { estimateVramGb, calculateFitScore } from './utils';

// Types for scraper data
export interface BaseModel {
Expand Down Expand Up @@ -257,8 +258,7 @@ export class ModelScraper {

// VRAM estimation function
estimateVramGb(paramsBillions: number, bitsPerWeight: number = 4): number {
// Formula: vram_gb = (params_billions * bits_per_weight) / 8 / 1e9 * 1.15 // 15% overhead
return (paramsBillions * bitsPerWeight) / 8 / 1e9 * 1.15;
return estimateVramGb(paramsBillions, bitsPerWeight);
}

// Fit score calculation function
Expand All @@ -267,18 +267,7 @@ export class ModelScraper {
weeklyPulls: number,
isCodeModel: boolean = false
): number {
// Calculate vram margin (how much headroom we have)
const vramMargin = Math.max(0, 40 - estimatedVramGb);

// Base score from VRAM margin and weekly pulls
let baseScore = vramMargin * 10 + weeklyPulls;

// Bonus for code models
if (isCodeModel) {
baseScore += 50;
}

return Math.round(baseScore);
return calculateFitScore(estimatedVramGb, weeklyPulls, isCodeModel);
}

// Main scraping function that processes all models
Expand Down Expand Up @@ -375,4 +364,4 @@ export class ModelScraper {
export const modelScraper = new ModelScraper();

// Export for use in other modules
export { BaseModel, ModelVariant, ProviderModel, DataProvider };
export { BaseModel, ModelVariant, ProviderModel, DataProvider };
20 changes: 20 additions & 0 deletions apps/api/src/modules/scraper/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function estimateVramGb(paramsBillions: number, bitsPerWeight: number = 4): number {
// paramsBillions is already in billions, so convert to GB directly.
// Formula: (params_billion * bits_per_weight) / 8, then apply 15% overhead.
return (paramsBillions * bitsPerWeight) / 8 * 1.125;
}

export function calculateFitScore(
estimatedVramGb: number,
weeklyPulls: number,
isCodeModel: boolean = false
): number {
const vramMargin = Math.max(0, 40 - estimatedVramGb);
let baseScore = vramMargin * 10 + weeklyPulls;

if (isCodeModel) {
baseScore += 50;
}

return Math.round(baseScore);
}
26 changes: 13 additions & 13 deletions apps/api/tests/scraper.test.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { modelScraper } from '../src/modules/scraper';
import { describe, it, expect } from 'vitest';
import { calculateFitScore, estimateVramGb } from '../src/modules/scraper/utils';

describe('scraper utilities', () => {
describe('estimateVramGb', () => {
it('should calculate VRAM correctly for 7B model with Q4_K_M (4-bit)', () => {
const vram = modelScraper.estimateVramGb(7, 4);
const vram = estimateVramGb(7, 4);
expect(vram).toBeCloseTo(3.9375); // (7 * 4) / 8 / 1e9 * 1.15
});

it('should calculate VRAM correctly for 32B model with Q8_0 (8-bit)', () => {
const vram = modelScraper.estimateVramGb(32, 8);
expect(vram).toBeCloseTo(3.6); // (32 * 8) / 8 / 1e9 * 1.15
const vram = estimateVramGb(32, 8);
expect(vram).toBeCloseTo(36); // (32 * 8) / 8 * 1.125
});

it('should calculate VRAM correctly for 1.5B model with Q4_K_M', () => {
const vram = modelScraper.estimateVramGb(1.5, 4);
expect(vram).toBeCloseTo(0.21875); // (1.5 * 4) / 8 / 1e9 * 1.15
const vram = estimateVramGb(1.5, 4);
expect(vram).toBeCloseTo(0.84375); // (1.5 * 4) / 8 * 1.125
});
});

describe('calculateFitScore', () => {
it('should calculate fit score correctly with VRAM margin and pull count', () => {
const score = modelScraper.calculateFitScore(30, 10000);
expect(score).toBe(30000); // (40 - 30) * 10 + 10000 = 100 + 10000 = 10100
const score = calculateFitScore(30, 10000);
expect(score).toBe(10100); // (40 - 30) * 10 + 10000 = 100 + 10000 = 10100
});

it('should add bonus for code models', () => {
const score = modelScraper.calculateFitScore(25, 50000, true);
expect(score).toBe(50075); // (40 - 25) * 10 + 50000 + 50 = 150 + 50000 + 50 = 50200
const score = calculateFitScore(25, 50000, true);
expect(score).toBe(50200); // (40 - 25) * 10 + 50000 + 50 = 150 + 50000 + 50 = 50200
});

it('should handle edge cases correctly', () => {
const score = modelScraper.calculateFitScore(39, 0);
const score = calculateFitScore(39, 0);
expect(score).toBe(10); // (40 - 39) * 10 + 0 = 10 + 0 = 10
});
});
});
});
5 changes: 2 additions & 3 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"test": "vitest run",
"test": "vitest run --passWithNoTests",
"test:watch": "vitest",
"lint": "eslint src/**/*.ts src/**/*.tsx",
"preview": "vite preview",
"e2e": "playwright test",
"e2e:ui": "playwright test --ui"
},
Expand All @@ -37,4 +36,4 @@
"eslint": "^8.0.0",
"playwright": "^1.40.0"
}
}
}
7 changes: 7 additions & 0 deletions apps/web/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
exclude: ['tests/e2e/**', 'node_modules/**', 'dist/**'],
},
});
Loading