Spaces:
Runtime error
Runtime error
ffreemt
commited on
Commit
•
8d030a2
1
Parent(s):
da75503
Fix E402 Module level import not at top of file
Browse files- .ruff.toml +21 -0
- app.py +12 -6
- ultrachat-13B-test.py +3 -2
.ruff.toml
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Assume Python 3.10.
|
2 |
+
target-version = "py310"
|
3 |
+
# Decrease the maximum line length to 79 characters.
|
4 |
+
line-length = 300
|
5 |
+
|
6 |
+
# pyflakes, pycodestyle, isort
|
7 |
+
# flake8 YTT, pydocstyle D, pylint PLC
|
8 |
+
select = ["F", "E", "W", "I001", "YTT", "D", "PLC"]
|
9 |
+
# select = ["ALL"]
|
10 |
+
|
11 |
+
# E501 Line too long
|
12 |
+
# D102 Missing docstring in public method
|
13 |
+
# D100 Missing docstring in public module
|
14 |
+
# E501 Line too long
|
15 |
+
# D103 Missing docstring in public function
|
16 |
+
# D101 Missing docstring in public class
|
17 |
+
# `multi-line-summary-first-line` (D212)
|
18 |
+
# `one-blank-line-before-class` (D203)
|
19 |
+
extend-ignore = ["E501", "D100", "D101", "D102", "D103", "D212", "D203"]
|
20 |
+
|
21 |
+
exclude = [".venv", "ultrachat-13B-test.py"]
|
app.py
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
-
import os
|
|
|
2 |
|
|
|
3 |
# os.system("pip install --upgrade torch transformers sentencepiece scipy cpm_kernels accelerate bitsandbytes loguru")
|
|
|
4 |
os.system("pip install torch transformers sentencepiece loguru")
|
5 |
|
6 |
-
|
7 |
-
|
8 |
import torch
|
9 |
-
from
|
|
|
10 |
|
11 |
# fix timezone in Linux
|
12 |
os.environ["TZ"] = "Asia/Shanghai"
|
@@ -18,7 +22,9 @@ except Exception:
|
|
18 |
|
19 |
model_name = "THUDM/chatglm2-6b-int4" # 3.9G
|
20 |
|
21 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
|
22 |
|
23 |
has_cuda = torch.cuda.is_available()
|
24 |
# has_cuda = False # force cpu
|
@@ -42,7 +48,7 @@ logger.debug("done load")
|
|
42 |
# tokenizer = AutoTokenizer.from_pretrained("openchat/openchat_v2_w")
|
43 |
# model = AutoModelForCausalLM.from_pretrained("openchat/openchat_v2_w", load_in_8bit_fp32_cpu_offload=True, load_in_8bit=True)
|
44 |
|
45 |
-
model_path = model.config._dict[
|
46 |
logger.debug(f"{model_path=}")
|
47 |
|
48 |
model_size_gb = Path(model_path).stat().st_size / 2**30
|
|
|
1 |
+
import os
|
2 |
+
import time
|
3 |
|
4 |
+
# ruff: noqa: E402
|
5 |
# os.system("pip install --upgrade torch transformers sentencepiece scipy cpm_kernels accelerate bitsandbytes loguru")
|
6 |
+
|
7 |
os.system("pip install torch transformers sentencepiece loguru")
|
8 |
|
9 |
+
from pathlib import Path
|
10 |
+
|
11 |
import torch
|
12 |
+
from logru import logger
|
13 |
+
from transformers import AutoModel, AutoTokenizer
|
14 |
|
15 |
# fix timezone in Linux
|
16 |
os.environ["TZ"] = "Asia/Shanghai"
|
|
|
22 |
|
23 |
model_name = "THUDM/chatglm2-6b-int4" # 3.9G
|
24 |
|
25 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
26 |
+
"THUDM/chatglm2-6b-int4", trust_remote_code=True
|
27 |
+
)
|
28 |
|
29 |
has_cuda = torch.cuda.is_available()
|
30 |
# has_cuda = False # force cpu
|
|
|
48 |
# tokenizer = AutoTokenizer.from_pretrained("openchat/openchat_v2_w")
|
49 |
# model = AutoModelForCausalLM.from_pretrained("openchat/openchat_v2_w", load_in_8bit_fp32_cpu_offload=True, load_in_8bit=True)
|
50 |
|
51 |
+
model_path = model.config._dict["model_name_or_path"]
|
52 |
logger.debug(f"{model_path=}")
|
53 |
|
54 |
model_size_gb = Path(model_path).stat().st_size / 2**30
|
ultrachat-13B-test.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
import os
|
|
|
2 |
os.system("pip install llama-cpp-python")
|
3 |
|
4 |
-
from gradio import Interface, Textbox, Slider
|
5 |
import requests
|
|
|
6 |
from llama_cpp import Llama
|
7 |
|
8 |
url = "https://huggingface.co/TheBloke/UltraLM-13B-GGML/resolve/main/ultralm-13b.ggmlv3.q4_0.bin"
|
@@ -24,4 +25,4 @@ ASSISTANT:'''
|
|
24 |
return output
|
25 |
|
26 |
|
27 |
-
Interface(fn=generate_text, inputs=[Textbox(type="text", lines=10), Slider(minimum=0, maximum=2, step=0.1, value=0.7), Slider(minimum=1, maximum=2048, step=2, value=256)], outputs=Textbox(type="text", lines=20), title="UltraChat 13B Text Generation", description="Enter a prompt to generate text.").launch()
|
|
|
1 |
import os
|
2 |
+
|
3 |
os.system("pip install llama-cpp-python")
|
4 |
|
|
|
5 |
import requests
|
6 |
+
from gradio import Interface, Slider, Textbox
|
7 |
from llama_cpp import Llama
|
8 |
|
9 |
url = "https://huggingface.co/TheBloke/UltraLM-13B-GGML/resolve/main/ultralm-13b.ggmlv3.q4_0.bin"
|
|
|
25 |
return output
|
26 |
|
27 |
|
28 |
+
Interface(fn=generate_text, inputs=[Textbox(type="text", lines=10), Slider(minimum=0, maximum=2, step=0.1, value=0.7), Slider(minimum=1, maximum=2048, step=2, value=256)], outputs=Textbox(type="text", lines=20), title="UltraChat 13B Text Generation", description="Enter a prompt to generate text.").launch()
|