tetra-rp 0.17.1__py3-none-any.whl

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.

Potentially problematic release.


This version of tetra-rp might be problematic. Click here for more details.

Files changed (66) hide show
  1. tetra_rp/__init__.py +43 -0
  2. tetra_rp/cli/__init__.py +0 -0
  3. tetra_rp/cli/commands/__init__.py +1 -0
  4. tetra_rp/cli/commands/build.py +534 -0
  5. tetra_rp/cli/commands/deploy.py +370 -0
  6. tetra_rp/cli/commands/init.py +119 -0
  7. tetra_rp/cli/commands/resource.py +191 -0
  8. tetra_rp/cli/commands/run.py +100 -0
  9. tetra_rp/cli/main.py +85 -0
  10. tetra_rp/cli/utils/__init__.py +1 -0
  11. tetra_rp/cli/utils/conda.py +127 -0
  12. tetra_rp/cli/utils/deployment.py +172 -0
  13. tetra_rp/cli/utils/ignore.py +139 -0
  14. tetra_rp/cli/utils/skeleton.py +184 -0
  15. tetra_rp/cli/utils/skeleton_template/.env.example +3 -0
  16. tetra_rp/cli/utils/skeleton_template/.flashignore +40 -0
  17. tetra_rp/cli/utils/skeleton_template/.gitignore +44 -0
  18. tetra_rp/cli/utils/skeleton_template/README.md +256 -0
  19. tetra_rp/cli/utils/skeleton_template/main.py +43 -0
  20. tetra_rp/cli/utils/skeleton_template/requirements.txt +1 -0
  21. tetra_rp/cli/utils/skeleton_template/workers/__init__.py +0 -0
  22. tetra_rp/cli/utils/skeleton_template/workers/cpu/__init__.py +20 -0
  23. tetra_rp/cli/utils/skeleton_template/workers/cpu/endpoint.py +38 -0
  24. tetra_rp/cli/utils/skeleton_template/workers/gpu/__init__.py +20 -0
  25. tetra_rp/cli/utils/skeleton_template/workers/gpu/endpoint.py +62 -0
  26. tetra_rp/client.py +128 -0
  27. tetra_rp/config.py +29 -0
  28. tetra_rp/core/__init__.py +0 -0
  29. tetra_rp/core/api/__init__.py +6 -0
  30. tetra_rp/core/api/runpod.py +319 -0
  31. tetra_rp/core/exceptions.py +50 -0
  32. tetra_rp/core/resources/__init__.py +37 -0
  33. tetra_rp/core/resources/base.py +47 -0
  34. tetra_rp/core/resources/cloud.py +4 -0
  35. tetra_rp/core/resources/constants.py +4 -0
  36. tetra_rp/core/resources/cpu.py +146 -0
  37. tetra_rp/core/resources/environment.py +41 -0
  38. tetra_rp/core/resources/gpu.py +68 -0
  39. tetra_rp/core/resources/live_serverless.py +62 -0
  40. tetra_rp/core/resources/network_volume.py +148 -0
  41. tetra_rp/core/resources/resource_manager.py +145 -0
  42. tetra_rp/core/resources/serverless.py +463 -0
  43. tetra_rp/core/resources/serverless_cpu.py +162 -0
  44. tetra_rp/core/resources/template.py +94 -0
  45. tetra_rp/core/resources/utils.py +50 -0
  46. tetra_rp/core/utils/__init__.py +0 -0
  47. tetra_rp/core/utils/backoff.py +43 -0
  48. tetra_rp/core/utils/constants.py +10 -0
  49. tetra_rp/core/utils/file_lock.py +260 -0
  50. tetra_rp/core/utils/json.py +33 -0
  51. tetra_rp/core/utils/lru_cache.py +75 -0
  52. tetra_rp/core/utils/singleton.py +21 -0
  53. tetra_rp/core/validation.py +44 -0
  54. tetra_rp/execute_class.py +319 -0
  55. tetra_rp/logger.py +34 -0
  56. tetra_rp/protos/__init__.py +0 -0
  57. tetra_rp/protos/remote_execution.py +148 -0
  58. tetra_rp/stubs/__init__.py +5 -0
  59. tetra_rp/stubs/live_serverless.py +155 -0
  60. tetra_rp/stubs/registry.py +117 -0
  61. tetra_rp/stubs/serverless.py +30 -0
  62. tetra_rp-0.17.1.dist-info/METADATA +976 -0
  63. tetra_rp-0.17.1.dist-info/RECORD +66 -0
  64. tetra_rp-0.17.1.dist-info/WHEEL +5 -0
  65. tetra_rp-0.17.1.dist-info/entry_points.txt +2 -0
  66. tetra_rp-0.17.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,117 @@
1
+ import logging
2
+ from functools import singledispatch
3
+
4
+ from ..core.resources import (
5
+ CpuLiveServerless,
6
+ CpuServerlessEndpoint,
7
+ LiveServerless,
8
+ ServerlessEndpoint,
9
+ )
10
+ from .live_serverless import LiveServerlessStub
11
+ from .serverless import ServerlessEndpointStub
12
+
13
+ log = logging.getLogger(__name__)
14
+
15
+
16
+ @singledispatch
17
+ def stub_resource(resource, **extra):
18
+ async def fallback(*args, **kwargs):
19
+ return {"error": f"Cannot stub {resource.__class__.__name__}."}
20
+
21
+ return fallback
22
+
23
+
24
+ def _create_live_serverless_stub(resource, **extra):
25
+ """Create a live serverless stub for both LiveServerless and CpuLiveServerless."""
26
+ stub = LiveServerlessStub(resource)
27
+
28
+ # Function execution
29
+ async def stubbed_resource(
30
+ func,
31
+ dependencies,
32
+ system_dependencies,
33
+ accelerate_downloads,
34
+ *args,
35
+ **kwargs,
36
+ ) -> dict:
37
+ if args == (None,):
38
+ args = []
39
+
40
+ request = stub.prepare_request(
41
+ func,
42
+ dependencies,
43
+ system_dependencies,
44
+ accelerate_downloads,
45
+ *args,
46
+ **kwargs,
47
+ )
48
+ response = await stub.ExecuteFunction(request)
49
+ return stub.handle_response(response)
50
+
51
+ # Class method execution
52
+ async def execute_class_method(request):
53
+ response = await stub.ExecuteFunction(request)
54
+ return stub.handle_response(response)
55
+
56
+ # Attach the method to the function
57
+ stubbed_resource.execute_class_method = execute_class_method
58
+
59
+ return stubbed_resource
60
+
61
+
62
+ @stub_resource.register(LiveServerless)
63
+ def _(resource, **extra):
64
+ return _create_live_serverless_stub(resource, **extra)
65
+
66
+
67
+ @stub_resource.register(CpuLiveServerless)
68
+ def _(resource, **extra):
69
+ return _create_live_serverless_stub(resource, **extra)
70
+
71
+
72
+ @stub_resource.register(ServerlessEndpoint)
73
+ def _(resource, **extra):
74
+ async def stubbed_resource(
75
+ func,
76
+ dependencies,
77
+ system_dependencies,
78
+ accelerate_downloads,
79
+ *args,
80
+ **kwargs,
81
+ ) -> dict:
82
+ if dependencies or system_dependencies:
83
+ log.warning(
84
+ "Dependencies are not supported for ServerlessEndpoint. "
85
+ "They will be ignored."
86
+ )
87
+
88
+ stub = ServerlessEndpointStub(resource)
89
+ payload = stub.prepare_payload(func, *args, **kwargs)
90
+ response = await stub.execute(payload, sync=extra.get("sync", False))
91
+ return stub.handle_response(response)
92
+
93
+ return stubbed_resource
94
+
95
+
96
+ @stub_resource.register(CpuServerlessEndpoint)
97
+ def _(resource, **extra):
98
+ async def stubbed_resource(
99
+ func,
100
+ dependencies,
101
+ system_dependencies,
102
+ accelerate_downloads,
103
+ *args,
104
+ **kwargs,
105
+ ) -> dict:
106
+ if dependencies or system_dependencies:
107
+ log.warning(
108
+ "Dependencies are not supported for CpuServerlessEndpoint. "
109
+ "They will be ignored."
110
+ )
111
+
112
+ stub = ServerlessEndpointStub(resource)
113
+ payload = stub.prepare_payload(func, *args, **kwargs)
114
+ response = await stub.execute(payload, sync=extra.get("sync", False))
115
+ return stub.handle_response(response)
116
+
117
+ return stubbed_resource
@@ -0,0 +1,30 @@
1
+ from ..core.resources import ServerlessEndpoint, JobOutput
2
+
3
+
4
+ class ServerlessEndpointStub:
5
+ """Adapter class to make Runpod endpoints requests."""
6
+
7
+ def __init__(self, server: ServerlessEndpoint):
8
+ self.server = server
9
+
10
+ def prepare_payload(self, func, *args, **kwargs) -> dict:
11
+ return func(*args, **kwargs)
12
+
13
+ async def execute(self, payload: dict, sync: bool = False) -> JobOutput:
14
+ """
15
+ Executes a serverless endpoint request with the payload.
16
+ Returns a JobOutput object.
17
+ """
18
+ if sync:
19
+ return await self.server.run_sync(payload)
20
+ else:
21
+ return await self.server.run(payload)
22
+
23
+ def handle_response(self, response: JobOutput):
24
+ if response.output:
25
+ return response.output
26
+
27
+ if response.error:
28
+ raise Exception(f"Remote execution failed: {response.error}")
29
+
30
+ raise ValueError("Invalid response from server")