nlpertools 1.0.8__tar.gz → 1.0.9__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. {nlpertools-1.0.8/src/nlpertools.egg-info → nlpertools-1.0.9}/PKG-INFO +8 -6
  2. {nlpertools-1.0.8 → nlpertools-1.0.9}/README.md +4 -4
  3. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/__init__.py +1 -1
  4. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/cli.py +60 -4
  5. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/draw/draw.py +5 -7
  6. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/io/dir.py +2 -2
  7. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/io/file.py +2 -2
  8. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/ml.py +22 -0
  9. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/other.py +17 -0
  10. {nlpertools-1.0.8 → nlpertools-1.0.9/src/nlpertools.egg-info}/PKG-INFO +8 -6
  11. {nlpertools-1.0.8 → nlpertools-1.0.9}/LICENSE +0 -0
  12. {nlpertools-1.0.8 → nlpertools-1.0.9}/pyproject.toml +0 -0
  13. {nlpertools-1.0.8 → nlpertools-1.0.9}/setup.cfg +0 -0
  14. {nlpertools-1.0.8 → nlpertools-1.0.9}/setup.py +0 -0
  15. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/algo/__init__.py +0 -0
  16. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/algo/ac.py +0 -0
  17. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/algo/bit_ops.py +0 -0
  18. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/algo/kmp.py +0 -0
  19. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/algo/num_ops.py +0 -0
  20. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/algo/template.py +0 -0
  21. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/algo/union.py +0 -0
  22. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/data_client.py +0 -0
  23. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/data_structure/__init__.py +0 -0
  24. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/data_structure/base_structure.py +0 -0
  25. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/dataprocess.py +0 -0
  26. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/default_db_config.yml +0 -0
  27. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/draw/__init__.py +0 -0
  28. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/draw/math_func.py +0 -0
  29. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/get_2fa.py +0 -0
  30. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/io/__init__.py +0 -0
  31. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/monitor/__init__.py +0 -0
  32. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/monitor/gpu.py +0 -0
  33. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/monitor/memory.py +0 -0
  34. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/movie.py +0 -0
  35. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/nlpertools_config.yml +0 -0
  36. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/open_api.py +0 -0
  37. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/pic.py +0 -0
  38. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/plugin.py +0 -0
  39. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/reminder.py +0 -0
  40. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/template/__init__.py +0 -0
  41. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/utils/__init__.py +0 -0
  42. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/utils/lazy.py +0 -0
  43. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/utils/log_util.py +0 -0
  44. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/utils/package.py +0 -0
  45. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/utils/package_v1.py +0 -0
  46. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/utils/package_v2.py +0 -0
  47. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/utils_for_nlpertools.py +0 -0
  48. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/vector_index_demo.py +0 -0
  49. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools/wrapper.py +0 -0
  50. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools.egg-info/SOURCES.txt +0 -0
  51. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools.egg-info/dependency_links.txt +0 -0
  52. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools.egg-info/entry_points.txt +0 -0
  53. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools.egg-info/requires.txt +0 -0
  54. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools.egg-info/top_level.txt +0 -0
  55. {nlpertools-1.0.8 → nlpertools-1.0.9}/src/nlpertools_helper/__init__.py +0 -0
  56. {nlpertools-1.0.8 → nlpertools-1.0.9}/tests/test_kmp.py +0 -0
  57. {nlpertools-1.0.8 → nlpertools-1.0.9}/tests/test_path_exists.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: nlpertools
3
- Version: 1.0.8
3
+ Version: 1.0.9
4
4
  Summary: A small package about small basic IO operation when coding
5
5
  Home-page: https://github.com/lvzii/nlpertools
6
6
  Author: youshuJi
@@ -17,6 +17,8 @@ Requires-Dist: pandas
17
17
  Requires-Dist: psutil
18
18
  Provides-Extra: torch
19
19
  Requires-Dist: torch; extra == "torch"
20
+ Dynamic: provides-extra
21
+ Dynamic: requires-dist
20
22
 
21
23
  <div align="center">
22
24
  <h4 align="center">
@@ -35,7 +37,7 @@ Requires-Dist: torch; extra == "torch"
35
37
 
36
38
  它解决了什么问题:
37
39
 
38
- - 很多函数是记不住的, ~~每次写每次都要搜~~ 每次都要问大模型 ,例如pandas排序
40
+ - 很多函数是记不住的, 每次写都要~~搜~~问大模型 ,例如pandas排序
39
41
  - 刷题的时候,树结构的题目很难调试
40
42
 
41
43
 
@@ -111,11 +113,11 @@ b = nlpertools.io.file.readtxt_list_all_strip('res.txt')
111
113
 
112
114
  ```bash
113
115
  # 生成pypi双因素认证的实时密钥(需要提供key)
114
- python -m nlpertools.get_2fa your_key
116
+ python -m nlpertools.cli --get_2fa --get_2fa_key your_key
115
117
 
116
118
  ## git
117
- python nlpertools.cli --git_push
118
- python nlpertools.cli --git_pull
119
+ python -m nlpertools.cli --git_push
120
+ python -m nlpertools.cli --git_pull
119
121
 
120
122
  # 以下功能被nvitop替代,不推荐使用
121
123
  ## 监控gpu显存
@@ -15,7 +15,7 @@
15
15
 
16
16
  它解决了什么问题:
17
17
 
18
- - 很多函数是记不住的, ~~每次写每次都要搜~~ 每次都要问大模型 ,例如pandas排序
18
+ - 很多函数是记不住的, 每次写都要~~搜~~问大模型 ,例如pandas排序
19
19
  - 刷题的时候,树结构的题目很难调试
20
20
 
21
21
 
@@ -91,11 +91,11 @@ b = nlpertools.io.file.readtxt_list_all_strip('res.txt')
91
91
 
92
92
  ```bash
93
93
  # 生成pypi双因素认证的实时密钥(需要提供key)
94
- python -m nlpertools.get_2fa your_key
94
+ python -m nlpertools.cli --get_2fa --get_2fa_key your_key
95
95
 
96
96
  ## git
97
- python nlpertools.cli --git_push
98
- python nlpertools.cli --git_pull
97
+ python -m nlpertools.cli --git_push
98
+ python -m nlpertools.cli --git_pull
99
99
 
100
100
  # 以下功能被nvitop替代,不推荐使用
101
101
  ## 监控gpu显存
@@ -20,4 +20,4 @@ from .cli import *
20
20
 
21
21
 
22
22
 
23
- __version__ = '1.0.8'
23
+ __version__ = '1.0.9'
@@ -3,8 +3,6 @@ import os
3
3
  import uuid
4
4
  import sys
5
5
 
6
- import pyotp
7
-
8
6
  """
9
7
  如何Debug cli.py
10
8
  """
@@ -49,6 +47,7 @@ def get_mac_address():
49
47
 
50
48
 
51
49
  def get_2af_value(key):
50
+ import pyotp
52
51
  """
53
52
  key应该是7位的
54
53
  """
@@ -57,14 +56,67 @@ def get_2af_value(key):
57
56
  print(totp.now())
58
57
 
59
58
 
59
+ def start_gpu_usage_notify_server():
60
+ from flask import Flask
61
+
62
+ app = Flask(__name__)
63
+
64
+ @app.route("/notify", methods=["GET"])
65
+ def notify():
66
+ # 这里可以根据需要动态生成通知内容
67
+ usage = os.popen("nvidia-smi --query-gpu=memory.used --format=csv").read().split("\n")[1:]
68
+ res = 0
69
+ for edx, each in enumerate(usage):
70
+ if each.startswith("0"):
71
+ res += 1
72
+ print(res)
73
+ return str(res), 200
74
+
75
+ app.run(host="0.0.0.0", port=5000)
76
+
77
+
78
+ def start_gpu_usage_notify_client():
79
+ import requests
80
+ from plyer import notification
81
+ import time
82
+
83
+ SERVER_URL = 'http://127.0.0.1:5000/notify' # 服务器的 API 地址
84
+
85
+ def notify(text):
86
+ # 使用 plyer 发送通知
87
+ notification.notify(
88
+ title='远程通知',
89
+ message=text,
90
+ timeout=10 # 10秒的通知显示时间
91
+ )
92
+
93
+ """定时轮询服务器获取通知"""
94
+ while True:
95
+ try:
96
+ response = requests.get(SERVER_URL)
97
+ if response.status_code == 200:
98
+ num = int(response.text)
99
+ if num > 0:
100
+ notify(f"服务器有{num}张卡")
101
+ print(f"服务器有{num}张卡")
102
+ else:
103
+ print("服务器没有新通知")
104
+ except Exception as e:
105
+ print(f"与服务器连接失败: {e}")
106
+
107
+ time.sleep(1)
108
+
109
+
60
110
  def main():
61
111
  parser = argparse.ArgumentParser(description="CLI tool for git operations and getting MAC address.")
62
112
  parser.add_argument('--gitpush', action='store_true', help='Perform git push operation.')
63
- parser.add_argument('--gitpull', action='store_true', help='Perform git push operation.')
113
+ parser.add_argument('--gitpull', action='store_true', help='Perform git pull operation.')
64
114
  parser.add_argument('--mac_address', action='store_true', help='Get the MAC address.')
65
115
 
66
116
  parser.add_argument('--get_2fa', action='store_true', help='Get the 2fa value.')
67
117
  parser.add_argument('--get_2fa_key', type=str, help='Get the 2fa value.')
118
+ parser.add_argument('--monitor_gpu_cli', action='store_true', help='Get the 2fa value.')
119
+ parser.add_argument('--monitor_gpu_ser', action='store_true', help='Get the 2fa value.')
68
120
 
69
121
  args = parser.parse_args()
70
122
 
@@ -74,13 +126,17 @@ def main():
74
126
  git_pull()
75
127
  elif args.mac_address:
76
128
  get_mac_address()
129
+ elif args.monitor_gpu_cli:
130
+ start_gpu_usage_notify_client()
131
+ elif args.monitor_gpu_ser:
132
+ start_gpu_usage_notify_server()
77
133
  elif args.get_2fa:
78
134
  if args.get_2fa_key:
79
135
  get_2af_value(args.get_2fa_key)
80
136
  else:
81
137
  print("Please provide a key as an argument.")
82
138
  else:
83
- print("No operation specified. Use --gitpush or --get_mac_address.")
139
+ print("No operation specified.")
84
140
 
85
141
 
86
142
  if __name__ == '__main__':
@@ -20,7 +20,7 @@ def confused_matrix(confuse_matrix):
20
20
  f.savefig('tmp.jpg', bbox_inches='tight')
21
21
 
22
22
 
23
- def plot_histogram(data, bin_size):
23
+ def plot_histogram(data, bin_size, max_bin):
24
24
  """
25
25
  画直方图,超过1000的统一按1000算
26
26
  :param data:
@@ -33,15 +33,15 @@ def plot_histogram(data, bin_size):
33
33
  from matplotlib.ticker import MaxNLocator
34
34
  # 将超过1000的值改为1000
35
35
  def process_lengths(data):
36
- return [length if length <= 1000 else 1003 for length in data]
36
+ return [length if length <= max_bin else max_bin + 3 for length in data]
37
37
 
38
38
  # 前闭后开
39
- min_num, max_num = 0, 1000
39
+ # min_num, max_num = 0, 1000
40
40
  # min_num, max_num = min(data), max(data)
41
41
 
42
42
  plt.figure(figsize=(12, 8))
43
43
  processed_data = process_lengths(data)
44
- bins = np.arange(0, 1000 + 2 * bin_size, bin_size)
44
+ bins = np.arange(0, max_bin + 2 * bin_size, bin_size)
45
45
  # 绘制直方图
46
46
  n, new_bins, patches = plt.hist(processed_data, bins=bins, edgecolor='black', color='skyblue', alpha=0.7,
47
47
  linewidth=0)
@@ -60,10 +60,8 @@ def plot_histogram(data, bin_size):
60
60
  plt.xlabel('module line number', fontsize=14)
61
61
  plt.ylabel('frequency', fontsize=14)
62
62
 
63
- # 添加网格
64
63
  plt.grid(True, linestyle='--', alpha=0.6)
65
64
 
66
- # 美化x轴和y轴的刻度
67
65
  plt.xticks(fontsize=12)
68
66
  plt.yticks(fontsize=12)
69
67
 
@@ -80,4 +78,4 @@ if __name__ == '__main__':
80
78
  # 调整区间大小
81
79
  bin_size = 50
82
80
  # 示例模块长度数据
83
- plot_histogram([1, 100, 999, 1000, 1002, 1100, 1150], bin_size)
81
+ plot_histogram([1, 100, 999, 1000, 1002, 1100, 1150], bin_size, max_bin=1000)
@@ -46,7 +46,7 @@ def get_filename(path, suffix=True) -> str:
46
46
  return filename
47
47
 
48
48
 
49
- def j_listdir(dir_name, including_dir=True):
49
+ def listdir(dir_name, including_dir=True):
50
50
  filenames = os.listdir(dir_name)
51
51
  if including_dir:
52
52
  return [os.path.join(dir_name, filename) for filename in filenames]
@@ -54,7 +54,7 @@ def j_listdir(dir_name, including_dir=True):
54
54
  return list(filenames)
55
55
 
56
56
 
57
- def j_listdir_yield(dir_name, including_dir=True):
57
+ def listdir_yield(dir_name, including_dir=True):
58
58
  filenames = os.listdir(dir_name)
59
59
  for filename in filenames:
60
60
  if including_dir:
@@ -241,12 +241,12 @@ def load_from_jsonl(path):
241
241
  return corpus
242
242
 
243
243
 
244
- def pickle_save(data, path):
244
+ def save_pkl(data, path):
245
245
  with open(path, 'wb') as f:
246
246
  pickle.dump(data, f)
247
247
 
248
248
 
249
- def pickle_load(path):
249
+ def load_pkl(path):
250
250
  with open(path, 'rb') as f:
251
251
  data = pickle.load(f)
252
252
  return data
@@ -17,6 +17,28 @@ from .io.file import readtxt_list_all_strip, writetxt_w_list, save_to_csv
17
17
  from .utils.package import *
18
18
 
19
19
 
20
+ def estimate_pass_at_k(num_samples:list, num_correct:list, k):
21
+ """
22
+ copy from https://huggingface.co/spaces/evaluate-metric/code_eval/blob/main/code_eval.py
23
+ num_samples: list
24
+ """
25
+ """Estimates pass@k of each problem and returns them in an array."""
26
+
27
+ def estimator(n: int, c: int, k: int) -> float:
28
+ """Calculates 1 - comb(n - c, k) / comb(n, k)."""
29
+ if n - c < k:
30
+ return 1.0
31
+ return 1.0 - np.prod(1.0 - k / np.arange(n - c + 1, n + 1))
32
+
33
+ if isinstance(num_samples, int):
34
+ num_samples_it = itertools.repeat(num_samples, len(num_correct))
35
+ else:
36
+ assert len(num_samples) == len(num_correct)
37
+ num_samples_it = iter(num_samples)
38
+
39
+ return np.array([estimator(int(n), int(c), k) for n, c in zip(num_samples_it, num_correct)])
40
+
41
+
20
42
  def calc_llm_train_activation_memory(
21
43
  model_name, sequence_length, batch_size, hidden_dim, lay_number, attention_heads_num, gpu_num=1
22
44
  ):
@@ -30,6 +30,21 @@ ENGLISH_PUNCTUATION = list(',.;:\'"!?<>()')
30
30
  OTHER_PUNCTUATION = list('!@#$%^&*')
31
31
 
32
32
 
33
+ def setup_logging(log_file):
34
+ """
35
+ Set up logging configuration.
36
+
37
+ Args:
38
+ log_file (str): Path to the log file.
39
+ """
40
+ logging.basicConfig(
41
+ filename=log_file,
42
+ level=logging.INFO,
43
+ format='%(asctime)s - %(levelname)s - %(message)s',
44
+ datefmt='%Y-%m-%d %H:%M:%S'
45
+ )
46
+
47
+
33
48
  def get_diff_parts(str1, str2):
34
49
  # 创建一个 SequenceMatcher 对象
35
50
  matcher = difflib.SequenceMatcher(None, str1, str2)
@@ -361,10 +376,12 @@ def unsqueeze_list(flatten_list, each_element_len):
361
376
  range(len(flatten_list) // each_element_len)]
362
377
  return two_dim_list
363
378
 
379
+
364
380
  def split_list(input_list, chunk_size):
365
381
  # 使用列表推导式将列表分割成二维数组
366
382
  return [input_list[i:i + chunk_size] for i in range(0, len(input_list), chunk_size)]
367
383
 
384
+
368
385
  def auto_close():
369
386
  """
370
387
  针对企业微信15分钟会显示离开的机制,假装自己还在上班
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: nlpertools
3
- Version: 1.0.8
3
+ Version: 1.0.9
4
4
  Summary: A small package about small basic IO operation when coding
5
5
  Home-page: https://github.com/lvzii/nlpertools
6
6
  Author: youshuJi
@@ -17,6 +17,8 @@ Requires-Dist: pandas
17
17
  Requires-Dist: psutil
18
18
  Provides-Extra: torch
19
19
  Requires-Dist: torch; extra == "torch"
20
+ Dynamic: provides-extra
21
+ Dynamic: requires-dist
20
22
 
21
23
  <div align="center">
22
24
  <h4 align="center">
@@ -35,7 +37,7 @@ Requires-Dist: torch; extra == "torch"
35
37
 
36
38
  它解决了什么问题:
37
39
 
38
- - 很多函数是记不住的, ~~每次写每次都要搜~~ 每次都要问大模型 ,例如pandas排序
40
+ - 很多函数是记不住的, 每次写都要~~搜~~问大模型 ,例如pandas排序
39
41
  - 刷题的时候,树结构的题目很难调试
40
42
 
41
43
 
@@ -111,11 +113,11 @@ b = nlpertools.io.file.readtxt_list_all_strip('res.txt')
111
113
 
112
114
  ```bash
113
115
  # 生成pypi双因素认证的实时密钥(需要提供key)
114
- python -m nlpertools.get_2fa your_key
116
+ python -m nlpertools.cli --get_2fa --get_2fa_key your_key
115
117
 
116
118
  ## git
117
- python nlpertools.cli --git_push
118
- python nlpertools.cli --git_pull
119
+ python -m nlpertools.cli --git_push
120
+ python -m nlpertools.cli --git_pull
119
121
 
120
122
  # 以下功能被nvitop替代,不推荐使用
121
123
  ## 监控gpu显存
File without changes
File without changes
File without changes
File without changes
File without changes