jiajun commited on
Commit
b1daed3
·
verified ·
1 Parent(s): a1e44ed

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +1 -5
  2. app.py +61 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,12 +1,8 @@
1
  ---
2
  title: CortexNet Demo
3
- emoji: 📉
4
- colorFrom: red
5
- colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 6.7.0
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: CortexNet Demo
 
 
 
3
  sdk: gradio
 
4
  app_file: app.py
5
  pinned: false
6
  ---
7
 
8
+ CortexNet demo Space.
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import time
4
+
5
+ import gradio as gr
6
+ import torch
7
+
8
+ from cortexnet import CortexNet, CortexNetConfig, __version__
9
+
10
+
11
+ def run_smoke(seq_len: int, iters: int) -> str:
12
+ cfg = CortexNetConfig(
13
+ vocab_size=4096,
14
+ hidden_size=128,
15
+ num_layers=2,
16
+ num_heads=4,
17
+ max_seq_len=max(128, seq_len),
18
+ lite=True,
19
+ )
20
+
21
+ model = CortexNet(cfg).eval()
22
+ input_ids = torch.randint(0, cfg.vocab_size, (1, seq_len))
23
+
24
+ with torch.no_grad():
25
+ _ = model(input_ids)
26
+
27
+ t0 = time.perf_counter()
28
+ with torch.no_grad():
29
+ for _ in range(iters):
30
+ out = model(input_ids)
31
+ dt = (time.perf_counter() - t0) / max(iters, 1)
32
+
33
+ msg = (
34
+ f"CortexNet version: {__version__}\n"
35
+ f"Average forward latency: {dt * 1000:.4f} ms\n"
36
+ f"Logits shape: {tuple(out['logits'].shape)}"
37
+ )
38
+ return msg
39
+
40
+
41
+ DESCRIPTION = """
42
+ # CortexNet Space Demo
43
+
44
+ This Space runs a lightweight smoke benchmark of CortexNet to verify runtime health.
45
+
46
+ - Source: https://github.com/chaojixiaokeai/CortexNet
47
+ - PyPI: https://pypi.org/project/cortexnet/
48
+ """
49
+
50
+
51
+ with gr.Blocks() as demo:
52
+ gr.Markdown(DESCRIPTION)
53
+ seq_len = gr.Slider(minimum=8, maximum=256, value=64, step=8, label="Sequence Length")
54
+ iters = gr.Slider(minimum=1, maximum=100, value=20, step=1, label="Iterations")
55
+ run_btn = gr.Button("Run Smoke Benchmark")
56
+ output = gr.Textbox(label="Result", lines=8)
57
+ run_btn.click(fn=run_smoke, inputs=[seq_len, iters], outputs=[output])
58
+
59
+
60
+ if __name__ == "__main__":
61
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ cortexnet>=3.2.5
2
+ torch>=2.0.0
3
+ gradio>=4.0.0