File size: 3,406 Bytes
81d60af
 
 
 
 
dbcd9e0
81d60af
88f2eb5
81d60af
 
88f2eb5
 
9d65593
6f1ac4c
dbcd9e0
88f2eb5
 
 
81d60af
 
 
0d5efff
6f1ac4c
81d60af
 
6f1ac4c
81d60af
d3336ac
6f1ac4c
 
 
d3336ac
6f1ac4c
 
d3336ac
81d60af
 
 
 
0d5efff
6f1ac4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88f2eb5
 
 
 
 
9d65593
6f1ac4c
9d65593
6f1ac4c
88f2eb5
 
 
 
 
 
 
 
 
 
fe55b90
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# app.py
"""
Wang's Five Laws โ€” LLM Spectral Analyzer
ไธปๅ…ฅๅฃ๏ผŒ็ป„่ฃ…ๆ‰€ๆœ‰ Tab
"""

import gradio as gr
from db.schema import init_db
from ui.tab_inspect import build_tab_inspect
from ui.tab_analyze import build_tab_analyze
from ui.tab_leaderboard import build_tab_leaderboard
from ui.tab_database import build_tab_database
from ui.tab_plot import build_tab_plot
from ui.tab_tables import build_tab_tables

# โ”€โ”€ ๅฏๅŠจๆ—ถๅˆๅง‹ๅŒ–ๆ•ฐๆฎๅบ“ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
init_db()

with gr.Blocks(
    title="Wang's Five Laws โ€” LLM Spectral Analyzer",
) as demo:

    # โ”€โ”€ ๅŒ่ฏญๆ ‡้ข˜ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    gr.Markdown("""
    # ๐Ÿ”ฌ Wang's Five Laws โ€” LLM Spectral Analyzer
    ### ็Ž‹ๆฐไบ”ๅฎšๅพ‹ โ€” ๅคงๆจกๅž‹่ฐฑๅˆ†ๆžๅทฅๅ…ท
    **Mathematical Foundations of Large Language Models (MF-LLM)**

    Reads HF weights via **HTTP Range Request** โ€” no full model download required.
    Auto-detects model structure (GQA / MHA / K=V shared / heterogeneous head_dim),
    computes all Five Laws metrics per attention head, persists results to SQLite.

    ้€š่ฟ‡ **HTTP Range Request** ็›ดๆŽฅ่ฏปๅ– HF ๆƒ้‡๏ผŒๆ— ้œ€ไธ‹่ฝฝๆ•ดไธชๆจกๅž‹ใ€‚
    ่‡ชๅŠจ่ฏ†ๅˆซๆจกๅž‹็ป“ๆž„๏ผŒ้€ๅคด่ฎก็ฎ—็Ž‹ๆฐไบ”ๅฎšๅพ‹ๅ…จ้ƒจๆŒ‡ๆ ‡๏ผŒ็ป“ๆžœๆŒไน…ๅŒ–ๅˆฐ SQLiteใ€‚

    [![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.19707844-blue)](https://doi.org/10.5281/zenodo.19707844)
    [![HAL](https://img.shields.io/badge/HAL-hal--05609398-red)](https://hal.science/hal-05609398)
    [![Wang's Law](https://img.shields.io/badge/Wang%27s%20Law-r%3D1-blue)](https://github.com/emis-framework/math-under-llm)
    """)

    # โ”€โ”€ ๅŒ่ฏญ่กจๆ ผๅนถๆŽ’ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    with gr.Row():
        gr.Markdown("""
| Law | Metric | Ideal |
|-----|--------|-------|
| Law 1 | Pearson r (Qโ€“K spectral alignment) | โ†’ 1 |
| Law 2 | SSR (spectral shape residual) | โ†’ 0 |
| Law 3 | Condition number ฮบ | smaller = more stable |
| Law 4 | cosU(Uq, Uv)  super-orthogonal | < 1/โˆšd_head |
| Law 5 | cosV  input subspace random orthogonal | โ‰ˆ 1/โˆšd_model |
        """)
        gr.Markdown("""
| ๅฎšๅพ‹ | ๆŒ‡ๆ ‡ | ็†่ฎบๆžๅ€ผ |
|------|------|---------|
| ็ฌฌไธ€ๅฎšๅพ‹ | Pearson r๏ผˆQ-K ่ฐฑ็บฟๆ€งๅฏน้ฝ๏ผ‰ | โ†’ 1 |
| ็ฌฌไบŒๅฎšๅพ‹ | SSR๏ผˆ่ฐฑๅฝข็Šถๆฎ‹ๅทฎ๏ผ‰ | โ†’ 0 |
| ็ฌฌไธ‰ๅฎšๅพ‹ | ๆกไปถๆ•ฐ ฮบ | ่ถŠๅฐ่ถŠ็จณๅฎš |
| ็ฌฌๅ››ๅฎšๅพ‹ | cosU(Uq, Uv)๏ผˆ่ถ…ๆญฃไบค๏ผ‰ | < 1/โˆšd_head |
| ็ฌฌไบ”ๅฎšๅพ‹ | cosV๏ผˆ่พ“ๅ…ฅๅญ็ฉบ้—ด้šๆœบๆญฃไบค๏ผ‰ | โ‰ˆ 1/โˆšd_model |
        """)

    # โ”€โ”€ Tabs โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    with gr.Tabs():
        inspect_model_id, inspect_token = build_tab_inspect()
        analyze_model_id, analyze_token = build_tab_analyze()
        build_tab_leaderboard()
        build_tab_database()
        build_tab_plot()
        build_tab_tables()

    # โ”€โ”€ Tab1 โ†’ Tab2 ่”ๅŠจ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    inspect_model_id.change(
        fn=lambda x: x,
        inputs=inspect_model_id,
        outputs=analyze_model_id,
    )
    inspect_token.change(
        fn=lambda x: x,
        inputs=inspect_token,
        outputs=analyze_token,
    )

if __name__ == "__main__":
    demo.launch()