generated from aniketmaurya/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* deploy lightning * fixes * add docs * fixes
- Loading branch information
1 parent
dbd9f52
commit 5ef62d5
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from fastserve.deploy.lightning import lightning_job as lightning_job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
try: | ||
from lightning_sdk import Machine, Studio | ||
except ModuleNotFoundError: | ||
Machine = None | ||
Studio = None | ||
|
||
|
||
def lightning_job( | ||
user: str, | ||
teamspace: str = "default", | ||
command="python main.py", | ||
machine=Machine.CPU, | ||
): | ||
# Start the studio | ||
s = Studio(name="fastserve", teamspace=teamspace, user=user, create_ok=True) | ||
print("starting Studio...") | ||
s.start() | ||
|
||
# Install plugin if not installed (in this case, it is already installed) | ||
s.install_plugin("jobs") | ||
|
||
jobs_plugin = s.installed_plugins["jobs"] | ||
|
||
jobs_plugin.run(command, name="serve", machine=machine) | ||
|
||
print("Stopping Studio") | ||
s.stop() | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description="Deploy FastServe") | ||
parser.add_argument("--filename", type=str, required=True, help="Python filename") | ||
parser.add_argument("--user", type=str, required=True, help="Lightning AI username") | ||
parser.add_argument( | ||
"--teamspace", type=str, required=True, help="Lightning AI teamspace" | ||
) | ||
parser.add_argument( | ||
"--machine", | ||
type=Machine, | ||
required=False, | ||
default="CPU", | ||
help="Lightning AI job plugin machine type", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
command = f"python {args.filename}" | ||
lightning_job( | ||
command=command, user=args.user, teamspace=args.teamspace, machine=args.machine | ||
) |