Spaces:
Running
Running
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ใ
[](https://doi.org/10.5281/zenodo.19707844)
[](https://hal.science/hal-05609398)
[](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() |