speedy-utils 1.1.45__tar.gz → 1.1.46__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/PKG-INFO +1 -1
  2. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/pyproject.toml +2 -1
  3. speedy_utils-1.1.46/src/speedy_utils/scripts/kill_mpython.py +58 -0
  4. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/scripts/mpython.py +51 -11
  5. speedy_utils-1.1.46/test.py +8 -0
  6. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.githooks/pre-push +0 -0
  7. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/copilot-instructions.md +0 -0
  8. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/prompts/improveParallelErrorHandling.prompt.md +0 -0
  9. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/caching-utilities/SKILL.md +0 -0
  10. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/caching-utilities/examples/caching_example.py +0 -0
  11. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/io-utilities/SKILL.md +0 -0
  12. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/io-utilities/examples/io_example.py +0 -0
  13. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/llm-integration/SKILL.md +0 -0
  14. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/llm-integration/examples/llm_example.py +0 -0
  15. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/multi-threading-processing/SKILL.md +0 -0
  16. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/ray-distributed-computing/SKILL.md +0 -0
  17. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/skill-creation/SKILL.md +0 -0
  18. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/vision-utilities/SKILL.md +0 -0
  19. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/skills/vision-utilities/examples/vision_example.py +0 -0
  20. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.github/workflows/publish.yml +0 -0
  21. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.gitignore +0 -0
  22. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/.pre-commit-config.yaml +0 -0
  23. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/AGENTS.md +0 -0
  24. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/README.md +0 -0
  25. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/bumpversion.sh +0 -0
  26. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/debug/debug_generate_response.py +0 -0
  27. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/debug/debug_n_param.py +0 -0
  28. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/debug/debug_n_structure.py +0 -0
  29. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/debug/integration_test.py +0 -0
  30. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/debug/test_decode_api.py +0 -0
  31. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/debug/test_endpoints.py +0 -0
  32. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/debug/test_generate.py +0 -0
  33. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/debug/test_generate_endpoint.py +0 -0
  34. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/docs/GENERATE_QUICKREF.md +0 -0
  35. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/docs/IMPLEMENTATION.md +0 -0
  36. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/docs/QUICKSTART.md +0 -0
  37. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/docs/TOKENIZATION.md +0 -0
  38. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/docs/TOKENIZATION_IMPLEMENTATION.md +0 -0
  39. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/docs/zero_copy_sharing.md +0 -0
  40. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/examples/generate_example.py +0 -0
  41. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/examples/llm_ray_example.py +0 -0
  42. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/examples/pytorch_large_model.py +0 -0
  43. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/examples/shared_kwargs_example.py +0 -0
  44. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/examples/temperature_range_example.py +0 -0
  45. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/examples/test_parallel_gpu.py +0 -0
  46. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/examples/test_share_ray.py +0 -0
  47. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/examples/tokenization_example.py +0 -0
  48. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/examples/vision_utils_example.py +0 -0
  49. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/experiments/exp1/dockerfile +0 -0
  50. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/experiments/exp1/run_in_docker.sh +0 -0
  51. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/experiments/exp1/test.png +0 -0
  52. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/experiments/test_read_image.py +0 -0
  53. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/notebooks/README.ipynb +0 -0
  54. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/notebooks/llm_utils/llm_as_a_judge.ipynb +0 -0
  55. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/notebooks/parallel_gpu_pool.ipynb +0 -0
  56. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/notebooks/ray_tutorial.ipynb +0 -0
  57. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/notebooks/test_multi_thread.ipynb +0 -0
  58. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/ruff.toml +0 -0
  59. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/bug.py +0 -0
  60. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/bug_simple.py +0 -0
  61. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/debug_import_time.py +0 -0
  62. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/deploy.sh +0 -0
  63. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/imports.sh +0 -0
  64. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/test.py +0 -0
  65. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/test_both_backends.py +0 -0
  66. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/test_error_handling.py +0 -0
  67. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/test_import_time_vision.py +0 -0
  68. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/test_locals.py +0 -0
  69. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/test_ray_locals.py +0 -0
  70. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/scripts/test_ray_mp.py +0 -0
  71. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/setup.cfg +0 -0
  72. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/datasets_utils/convert_to_arrow.py +0 -0
  73. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/__init__.py +0 -0
  74. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/chat_format/__init__.py +0 -0
  75. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/chat_format/display.py +0 -0
  76. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/chat_format/transform.py +0 -0
  77. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/chat_format/utils.py +0 -0
  78. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/group_messages.py +0 -0
  79. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/llm_ray.py +0 -0
  80. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/__init__.py +0 -0
  81. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/async_lm/__init__.py +0 -0
  82. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/async_lm/_utils.py +0 -0
  83. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/async_lm/async_llm_task.py +0 -0
  84. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/async_lm/async_lm.py +0 -0
  85. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/async_lm/async_lm_base.py +0 -0
  86. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/async_lm/lm_specific.py +0 -0
  87. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/base_prompt_builder.py +0 -0
  88. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/llm.py +0 -0
  89. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/llm_signature.py +0 -0
  90. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/lm_base.py +0 -0
  91. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/mixins.py +0 -0
  92. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/openai_memoize.py +0 -0
  93. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/signature.py +0 -0
  94. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/lm/utils.py +0 -0
  95. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/scripts/README.md +0 -0
  96. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/scripts/fast_vllm.py +0 -0
  97. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/scripts/vllm_load_balancer.py +0 -0
  98. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/scripts/vllm_serve.py +0 -0
  99. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/vector_cache/__init__.py +0 -0
  100. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/vector_cache/cli.py +0 -0
  101. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/vector_cache/core.py +0 -0
  102. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/vector_cache/types.py +0 -0
  103. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/llm_utils/vector_cache/utils.py +0 -0
  104. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/__imports.py +0 -0
  105. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/__init__.py +0 -0
  106. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/__init__.py +0 -0
  107. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/clock.py +0 -0
  108. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/function_decorator.py +0 -0
  109. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/logger.py +0 -0
  110. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/notebook_utils.py +0 -0
  111. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/patcher.py +0 -0
  112. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/report_manager.py +0 -0
  113. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/utils_cache.py +0 -0
  114. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/utils_error.py +0 -0
  115. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/utils_io.py +0 -0
  116. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/utils_misc.py +0 -0
  117. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/common/utils_print.py +0 -0
  118. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/multi_worker/__init__.py +0 -0
  119. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/multi_worker/dataset_ray.py +0 -0
  120. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/multi_worker/parallel_gpu_pool.py +0 -0
  121. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/multi_worker/process.py +0 -0
  122. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/multi_worker/progress.py +0 -0
  123. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/multi_worker/thread.py +0 -0
  124. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/scripts/__init__.py +0 -0
  125. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/speedy_utils/scripts/openapi_client_codegen.py +0 -0
  126. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/vision_utils/README.md +0 -0
  127. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/vision_utils/__init__.py +0 -0
  128. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/vision_utils/io_utils.py +0 -0
  129. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/src/vision_utils/plot.py +0 -0
  130. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/import_all.py +0 -0
  131. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/import_time_report.py +0 -0
  132. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/integration_test.py +0 -0
  133. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/llm_utils/test_llm_mixins.py +0 -0
  134. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/sample_objects.py +0 -0
  135. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test.py +0 -0
  136. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_logger.py +0 -0
  137. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_logger_format.py +0 -0
  138. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_memoize_typing.py +0 -0
  139. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_mpython.py +0 -0
  140. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_multithread_error_trace.py +0 -0
  141. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_process.py +0 -0
  142. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_process_update.py +0 -0
  143. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_pytorch_sharing.py +0 -0
  144. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_shared_kwargs.py +0 -0
  145. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_thread.py +0 -0
  146. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/tests/test_tokenization.py +0 -0
  147. {speedy_utils-1.1.45 → speedy_utils-1.1.46}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: speedy-utils
3
- Version: 1.1.45
3
+ Version: 1.1.46
4
4
  Summary: Fast and easy-to-use package for data science
5
5
  Project-URL: Homepage, https://github.com/anhvth/speedy
6
6
  Project-URL: Repository, https://github.com/anhvth/speedy
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "speedy-utils"
3
- version = "1.1.45"
3
+ version = "1.1.46"
4
4
  description = "Fast and easy-to-use package for data science"
5
5
  authors = [{ name = "AnhVTH", email = "anhvth.226@gmail.com" }]
6
6
  readme = "README.md"
@@ -65,6 +65,7 @@ svllm = "llm_utils.scripts.vllm_serve:main"
65
65
  svllm-lb = "llm_utils.scripts.vllm_load_balancer:run_load_balancer"
66
66
  openapi_client_codegen = "speedy_utils.scripts.openapi_client_codegen:main"
67
67
  fast-vllm = "llm_utils.scripts.fast_vllm:main"
68
+ kill-mpython = "speedy_utils.scripts.kill_mpython:main"
68
69
 
69
70
  [build-system]
70
71
  requires = ["hatchling"]
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env python3
2
+ """Script to kill all tmux sessions matching 'mpython*' pattern."""
3
+
4
+ import subprocess
5
+ import sys
6
+
7
+
8
+ def main():
9
+ """Kill all tmux sessions with names starting with 'mpython'."""
10
+ try:
11
+ # Get list of tmux sessions matching the pattern
12
+ result = subprocess.run(
13
+ ["tmux", "ls"],
14
+ capture_output=True,
15
+ text=True
16
+ )
17
+ if result.returncode != 0:
18
+ if "no server running" in result.stderr.lower():
19
+ print("No tmux server running.")
20
+ return
21
+ print(f"Error listing tmux sessions: {result.stderr}")
22
+ sys.exit(result.returncode)
23
+
24
+ sessions = []
25
+ for line in result.stdout.strip().split('\n'):
26
+ if line.strip():
27
+ session_name = line.split(':')[0]
28
+ if session_name.startswith('mpython'):
29
+ sessions.append(session_name)
30
+
31
+ if not sessions:
32
+ print("No tmux sessions found matching 'mpython*'")
33
+ return
34
+
35
+ print(f"Found {len(sessions)} tmux session(s) to kill: {', '.join(sessions)}")
36
+
37
+ # Kill each session
38
+ for session in sessions:
39
+ kill_result = subprocess.run(
40
+ ["tmux", "kill-session", "-t", session],
41
+ capture_output=True,
42
+ text=True
43
+ )
44
+ if kill_result.returncode == 0:
45
+ print(f"Successfully killed tmux session '{session}'")
46
+ else:
47
+ print(f"Error killing tmux session '{session}': {kill_result.stderr}")
48
+
49
+ except FileNotFoundError:
50
+ print("Error: tmux command not found. Please ensure tmux is installed.")
51
+ sys.exit(1)
52
+ except Exception as e:
53
+ print(f"Unexpected error: {e}")
54
+ sys.exit(1)
55
+
56
+
57
+ if __name__ == "__main__":
58
+ main()
@@ -7,6 +7,19 @@ import re
7
7
  import shlex # To properly escape command line arguments
8
8
  import shutil
9
9
  import subprocess
10
+ import sys
11
+
12
+ try:
13
+ from rich.console import Console, Group
14
+ from rich.panel import Panel
15
+ from rich.text import Text
16
+ from rich.syntax import Syntax
17
+ except ImportError:
18
+ Console = None
19
+ Group = None
20
+ Panel = None
21
+ Text = None
22
+ Syntax = None
10
23
 
11
24
 
12
25
  taskset_path = shutil.which('taskset')
@@ -60,18 +73,34 @@ def assert_script(python_path):
60
73
  with open(python_path) as f:
61
74
  code_str = f.read()
62
75
  if 'MP_ID' not in code_str or 'MP_TOTAL' not in code_str:
63
- example_code = (
64
- 'import os; MP_TOTAL = int(os.environ.get("MP_TOTAL"));MP_ID = int(os.environ.get("MP_ID"))\n'
76
+ helper_code = (
77
+ 'import os\n'
78
+ 'MP_ID = int(os.getenv("MP_ID", "0"))\n'
79
+ 'MP_TOTAL = int(os.getenv("MP_TOTAL", "1"))\n'
65
80
  'inputs = list(inputs[MP_ID::MP_TOTAL])'
66
81
  )
67
- # ANSI escape codes for coloring
68
- YELLOW = '\033[93m'
69
- RESET = '\033[0m'
70
- raise_msg = (
71
- f'MP_ID and MP_TOTAL not found in {python_path}, please add them.\n\n'
72
- f'Example:\n{YELLOW}{example_code}{RESET}'
73
- )
74
- raise Exception(raise_msg)
82
+ if Console and Panel and Text and Syntax and Group:
83
+ console = Console(stderr=True, force_terminal=True)
84
+ syntax = Syntax(helper_code, "python", theme="monokai", line_numbers=False)
85
+ console.print()
86
+ console.print(
87
+ Panel(
88
+ f'Your script {python_path} is missing MP_ID and/or MP_TOTAL variables.\n\n'
89
+ f'Add the following code to enable multi-process sharding:',
90
+ title='[bold yellow]Warning: Missing Multi-Process Variables[/bold yellow]',
91
+ border_style='yellow',
92
+ expand=False,
93
+ )
94
+ )
95
+ console.print()
96
+ console.print("```python")
97
+ console.print(syntax)
98
+ console.print("```")
99
+ console.print("-"*80)
100
+ else:
101
+ # Fallback to plain text
102
+ print(f'Warning: MP_ID and MP_TOTAL not found in {python_path}, please add them.', file=sys.stderr)
103
+ print(f'Example:\n{helper_code}', file=sys.stderr)
75
104
 
76
105
 
77
106
  def run_in_tmux(commands_to_run, tmux_name, num_windows):
@@ -96,7 +125,18 @@ def run_in_tmux(commands_to_run, tmux_name, num_windows):
96
125
  def main():
97
126
  # Assert that MP_ID and MP_TOTAL are not already set
98
127
 
99
- parser = argparse.ArgumentParser(description='Process fold arguments')
128
+ helper_code = (
129
+ 'import os\n'
130
+ 'MP_ID = int(os.getenv("MP_ID", "0"))\n'
131
+ 'MP_TOTAL = int(os.getenv("MP_TOTAL", "1"))\n'
132
+ 'inputs = list(inputs[MP_ID::MP_TOTAL])'
133
+ )
134
+
135
+ parser = argparse.ArgumentParser(
136
+ description='Process fold arguments',
137
+ epilog=f'Helper code for multi-process sharding:\n{helper_code}',
138
+ formatter_class=argparse.RawDescriptionHelpFormatter
139
+ )
100
140
  parser.add_argument(
101
141
  '--total_fold', '-t', default=16, type=int, help='total number of folds'
102
142
  )
@@ -0,0 +1,8 @@
1
+ import os
2
+ MP_ID = int(os.getenv("MP_ID", "0"))
3
+ MP_TOTAL = int(os.getenv("MP_TOTAL", "1"))
4
+
5
+ inputs = range(1000)
6
+ def f(x):
7
+ print(x)
8
+ inputs = list(inputs[MP_ID::MP_TOTAL])
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes