File size: 2,365 Bytes
758c11a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 034 · Model Diff

**title:** Model Diff — side-by-side diff of two model repos: config, tokenizer, files, license
**status:** MVP ready
**license:** MIT

## why

Choosing between two similar models is currently a manual dance of opening tabs and squinting at `config.json`. Model Diff turns it into a table: param count, context length, quantization, architectures, license, file tree, last commit — with a real line-level diff on configs. It kills the "which one do I deploy?" 30-minute rabbit hole and is fully static + Hub API.

## what

- Inputs: two repo ids (models; optionally datasets/spaces).
- Fetches `config.json`, `tokenizer_config.json`, `README.md` (first 2k), file tree, and metadata.
- Renders: stat table (diff-colored), file tree union, and a side-by-side YAML/JSON diff.
- Deep-linkable: `/diff?left=openai/whisper-tiny&right=openai/whisper-small`.

## plan

1. Static page + simple `diff` algorithm (LCS) in JS.
2. Normalize configs (sort keys, drop `_name_or_path`) before diffing to reduce noise.
3. Add "why different" hints: param ratio, vocab, context length differences.
4. Export diff as markdown for pasting into PRs/notes.

## code

```js
async function getJson(repo, file) {
  const r = await fetch(`https://huggingface.co/${repo}/raw/main/${file}`);
  return r.ok ? r.json() : null;
}
function diffLines(a, b) {              // tiny LCS line diff
  const A = a.split('\n'), B = b.split('\n');
  const dp = Array.from({ length: A.length + 1 }, () => new Array(B.length + 1).fill(0));
  for (let i = A.length - 1; i >= 0; i--) for (let j = B.length - 1; j >= 0; j--)
    dp[i][j] = A[i] === B[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
  let out = [], i = 0, j = 0;
  while (i < A.length && j < B.length)
    A[i] === B[j] ? (out.push('  ' + A[i]), i++, j++)
    : dp[i + 1][j] >= dp[i][j + 1] ? (out.push('- ' + A[i++]), 0)
    : (out.push('+ ' + B[j++]), 0);
  while (i < A.length) out.push('- ' + A[i++]);
  while (j < B.length) out.push('+ ' + B[j++]);
  return out.join('\n');
}
// call: diffLines(JSON.stringify(l.config, null, 2), JSON.stringify(r.config, null, 2))
```

## next

- GPU-memory estimator based on params × precision (ties into #035).
- Watch mode: subscribe a pair, get pinged when either file changes (#049 cron).
- Tokenizer diff: load both tokenizer files and show vocab overlap.