ffreemt commited on
Commit
9c042fd
1 Parent(s): 90cb722
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -2,17 +2,18 @@
2
  # pylint: disable=invalid-name, line-too-long,broad-exception-caught, protected-access
3
  import os
4
  import time
 
 
 
 
 
5
 
6
  # ruff: noqa: E402
7
  # os.system("pip install --upgrade torch transformers sentencepiece scipy cpm_kernels accelerate bitsandbytes loguru")
8
 
9
  # os.system("pip install torch transformers sentencepiece loguru")
10
 
11
- from pathlib import Path
12
 
13
- import torch
14
- from loguru import logger
15
- from transformers import AutoModel, AutoTokenizer
16
 
17
  # fix timezone in Linux
18
  os.environ["TZ"] = "Asia/Shanghai"
@@ -50,13 +51,15 @@ logger.debug("done load")
50
  # tokenizer = AutoTokenizer.from_pretrained("openchat/openchat_v2_w")
51
  # model = AutoModelForCausalLM.from_pretrained("openchat/openchat_v2_w", load_in_8bit_fp32_cpu_offload=True, load_in_8bit=True)
52
 
53
- # model_path = model.config._dict["model_name_or_path"]
54
- # logger.debug(f"{model.config=} {type(model.config)=} {model_path=}")
55
- logger.debug(f"{model.config=}, {type(model.config)=} ")
56
 
57
- # model_size_gb = Path(model_path).stat().st_size / 2**30
58
 
59
- # logger.info(f"{model_name=} {model_size_gb=:.2f} GB")
 
 
60
 
61
  # with gr.Blocks() as demo:
62
  # chatbot = gr.Chatbot()
 
2
  # pylint: disable=invalid-name, line-too-long,broad-exception-caught, protected-access
3
  import os
4
  import time
5
+ from pathlib import Path
6
+
7
+ import torch
8
+ from loguru import logger
9
+ from transformers import AutoModel, AutoTokenizer
10
 
11
  # ruff: noqa: E402
12
  # os.system("pip install --upgrade torch transformers sentencepiece scipy cpm_kernels accelerate bitsandbytes loguru")
13
 
14
  # os.system("pip install torch transformers sentencepiece loguru")
15
 
 
16
 
 
 
 
17
 
18
  # fix timezone in Linux
19
  os.environ["TZ"] = "Asia/Shanghai"
 
51
  # tokenizer = AutoTokenizer.from_pretrained("openchat/openchat_v2_w")
52
  # model = AutoModelForCausalLM.from_pretrained("openchat/openchat_v2_w", load_in_8bit_fp32_cpu_offload=True, load_in_8bit=True)
53
 
54
+ # locate model file cache
55
+ cache_loc = Path("~/.cache/huggingface/hub").expanduser()
56
+ model_cache_path = [elm for elm in Path(cache_loc).rglob("*") if Path(model_name).name in elm.as_posix() and "pytorch_model.bin" in elm.as_posix()]
57
 
58
+ logger.debug(f"{model_cache_path=}")
59
 
60
+ if model_cache_path:
61
+ model_size_gb = Path(model_cache_path).stat().st_size / 2**30
62
+ logger.info(f"{model_name=} {model_size_gb=:.2f} GB")
63
 
64
  # with gr.Blocks() as demo:
65
  # chatbot = gr.Chatbot()