BlinkDL mollysama commited on
Commit
1bf8cb8
·
verified ·
1 Parent(s): 7b6e845

update gradio version (#10)

Browse files

- update gradio version (51b08599b9d1e6c80fb0bfd8df22570eddcafd78)


Co-authored-by: Molly Sophia <mollysama@users.noreply.huggingface.co>

Files changed (2) hide show
  1. app.py +15 -14
  2. requirements.txt +1 -2
app.py CHANGED
@@ -24,12 +24,13 @@ gen_limit = 1000
24
  ########################## text rwkv ################################################################
25
  from rwkv.utils import PIPELINE, PIPELINE_ARGS
26
 
27
- title_v6 = "rwkv7-g0a-7.2b-20250829-ctx4096"
28
- model_path_v6 = hf_hub_download(repo_id="BlinkDL/rwkv7-g1", filename=f"{title_v6}.pth")
29
- model_v6 = RWKV(model=model_path_v6.replace('.pth',''), strategy='cuda fp16')
30
- pipeline_v6 = PIPELINE(model_v6, "rwkv_vocab_v20230424")
 
31
 
32
- args = model_v6.args
33
 
34
  penalty_decay = 0.996
35
 
@@ -67,23 +68,23 @@ def evaluate(
67
  state = None
68
  for i in range(int(token_count)):
69
 
70
- input_ids = pipeline_v6.encode(ctx)[-ctx_limit:] if i == 0 else [token]
71
  CHUNK_LEN = 512
72
- # out, state = model_v6.forward(input_ids, state)
73
  while len(input_ids) > 0:
74
- out, state = model_v6.forward(input_ids[:CHUNK_LEN], state)
75
  input_ids = input_ids[CHUNK_LEN:]
76
  for n in occurrence:
77
  out[n] -= (args.alpha_presence + occurrence[n] * args.alpha_frequency)
78
 
79
- token = pipeline_v6.sample_logits(out, temperature=args.temperature, top_p=args.top_p)
80
  if token in args.token_stop:
81
  break
82
  all_tokens += [token]
83
  for xxx in occurrence:
84
  occurrence[xxx] *= penalty_decay
85
 
86
- ttt = pipeline_v6.decode([token])
87
  www = 1
88
  if ttt in ' \t0123456789':
89
  www = 0
@@ -94,7 +95,7 @@ def evaluate(
94
  else:
95
  occurrence[token] += www
96
 
97
- tmp = pipeline_v6.decode(all_tokens[out_last:])
98
  if '\ufffd' not in tmp:
99
  out_str += tmp
100
  yield out_str.strip()
@@ -128,8 +129,8 @@ examples = [
128
  ]
129
 
130
  ##################################################################################################################
131
- with gr.Blocks(title=title_v6) as demo:
132
- gr.HTML(f"<div style=\"text-align: center;\">\n<h1>{title_v6}</h1>\n</div>")
133
 
134
  with gr.Tab("=== Base Model (Raw Generation) ==="):
135
  gr.Markdown(f'This is [RWKV7 G0a](https://huggingface.co/BlinkDL/rwkv7-g1) 7.2B reasoning base LM - an attention-free pure RNN [RWKV-LM](https://github.com/BlinkDL/RWKV-LM). Try topp0 penalty0 for math/code/translation. Supports 100+ world languages and code. Check [500+ Github RWKV projects](https://github.com/search?o=desc&p=1&q=rwkv&s=updated&type=Repositories). *** Can try examples (bottom of page) *** (can edit them). Demo limited to ctxlen {ctx_limit}.')
@@ -151,5 +152,5 @@ with gr.Blocks(title=title_v6) as demo:
151
  clear.click(lambda: None, [], [output])
152
  data.click(lambda x: x, [data], [prompt, token_count, temperature, top_p, presence_penalty, count_penalty])
153
 
154
- demo.queue(concurrency_count=1, max_size=10)
155
  demo.launch(share=False)
 
24
  ########################## text rwkv ################################################################
25
  from rwkv.utils import PIPELINE, PIPELINE_ARGS
26
 
27
+ title = "rwkv7-g0a-7.2b-20250829-ctx4096"
28
+ model_path = hf_hub_download(repo_id="BlinkDL/rwkv7-g1", filename=f"{title}.pth")
29
+ # model_path = "/home/molly/rwkv7-g0a-7.2b-20250829-ctx4096.pth"
30
+ model = RWKV(model=model_path.replace('.pth',''), strategy='cuda fp16')
31
+ pipeline = PIPELINE(model, "rwkv_vocab_v20230424")
32
 
33
+ args = model.args
34
 
35
  penalty_decay = 0.996
36
 
 
68
  state = None
69
  for i in range(int(token_count)):
70
 
71
+ input_ids = pipeline.encode(ctx)[-ctx_limit:] if i == 0 else [token]
72
  CHUNK_LEN = 512
73
+ # out, state = model.forward(input_ids, state)
74
  while len(input_ids) > 0:
75
+ out, state = model.forward(input_ids[:CHUNK_LEN], state)
76
  input_ids = input_ids[CHUNK_LEN:]
77
  for n in occurrence:
78
  out[n] -= (args.alpha_presence + occurrence[n] * args.alpha_frequency)
79
 
80
+ token = pipeline.sample_logits(out, temperature=args.temperature, top_p=args.top_p)
81
  if token in args.token_stop:
82
  break
83
  all_tokens += [token]
84
  for xxx in occurrence:
85
  occurrence[xxx] *= penalty_decay
86
 
87
+ ttt = pipeline.decode([token])
88
  www = 1
89
  if ttt in ' \t0123456789':
90
  www = 0
 
95
  else:
96
  occurrence[token] += www
97
 
98
+ tmp = pipeline.decode(all_tokens[out_last:])
99
  if '\ufffd' not in tmp:
100
  out_str += tmp
101
  yield out_str.strip()
 
129
  ]
130
 
131
  ##################################################################################################################
132
+ with gr.Blocks(title=title) as demo:
133
+ gr.HTML(f"<div style=\"text-align: center;\">\n<h1>{title}</h1>\n</div>")
134
 
135
  with gr.Tab("=== Base Model (Raw Generation) ==="):
136
  gr.Markdown(f'This is [RWKV7 G0a](https://huggingface.co/BlinkDL/rwkv7-g1) 7.2B reasoning base LM - an attention-free pure RNN [RWKV-LM](https://github.com/BlinkDL/RWKV-LM). Try topp0 penalty0 for math/code/translation. Supports 100+ world languages and code. Check [500+ Github RWKV projects](https://github.com/search?o=desc&p=1&q=rwkv&s=updated&type=Repositories). *** Can try examples (bottom of page) *** (can edit them). Demo limited to ctxlen {ctx_limit}.')
 
152
  clear.click(lambda: None, [], [output])
153
  data.click(lambda x: x, [data], [prompt, token_count, temperature, top_p, presence_penalty, count_penalty])
154
 
155
+ demo.queue(default_concurrency_limit=1, max_size=10)
156
  demo.launch(share=False)
requirements.txt CHANGED
@@ -1,8 +1,7 @@
1
- gradio==3.28.1
2
  torch
3
  ninja
4
  tokenizers
5
  rwkv>=0.8.29
6
  pynvml
7
  huggingface_hub
8
- gradio==3.28.1
 
 
1
  torch
2
  ninja
3
  tokenizers
4
  rwkv>=0.8.29
5
  pynvml
6
  huggingface_hub
7
+ gradio==5.44.1