Blazgo commited on
Commit
9c0631a
·
verified ·
1 Parent(s): 1faa11b

Create setup-petals-swarm.py

Browse files
Files changed (1) hide show
  1. setup-petals-swarm.py +59 -0
setup-petals-swarm.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import sys
3
+ import time
4
+
5
+ # Function to install necessary dependencies
6
+ def install_dependencies():
7
+ try:
8
+ print("Installing Petals...")
9
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "git+https://github.com/bigscience-workshop/petals"])
10
+ print("Petals installation successful.")
11
+ except subprocess.CalledProcessError:
12
+ print("Error during Petals installation.")
13
+ sys.exit(1)
14
+
15
+ # Function to start the Petals server
16
+ def start_petal_server(model_name, port=31337):
17
+ try:
18
+ command = [
19
+ sys.executable,
20
+ "-m",
21
+ "petals.cli.run_server",
22
+ model_name,
23
+ "--port",
24
+ str(port)
25
+ ]
26
+ server_process = subprocess.Popen(command)
27
+ print(f"Petals server started for model {model_name} on port {port}.")
28
+ return server_process
29
+ except Exception as e:
30
+ print(f"Error starting Petals server: {e}")
31
+ sys.exit(1)
32
+
33
+ # Function to keep the server alive
34
+ def keep_server_alive(server_process):
35
+ try:
36
+ while True:
37
+ time.sleep(60) # Check every minute
38
+ if server_process.poll() is not None:
39
+ print("Petals server has stopped unexpectedly.")
40
+ break
41
+ except KeyboardInterrupt:
42
+ print("Keep-alive interrupted. Terminating server...")
43
+ server_process.terminate()
44
+ server_process.wait()
45
+ print("Petals server terminated.")
46
+
47
+ if __name__ == "__main__":
48
+ # Define the model name and port
49
+ model_name = "meta-llama/Meta-Llama-3.1-405B-Instruct"
50
+ port = 31337
51
+
52
+ # Install dependencies (optional, but should be included for Docker consistency)
53
+ install_dependencies()
54
+
55
+ # Start the Petals server
56
+ server_process = start_petal_server(model_name, port)
57
+
58
+ # Keep the server alive
59
+ keep_server_alive(server_process)