-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gRPC API surface plus response/requests datatype naming conventions #5
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
!streamlit run main.py --server.port $CDSW_APP_PORT --server.address 127.0.0.1 | ||
import subprocess | ||
import os | ||
|
||
CDSW_APP_PORT = os.environ.get("CDSW_APP_PORT") | ||
out = subprocess.run([f"bash ./bin/start-app-script.sh {CDSW_APP_PORT}"], shell=True, check=True) | ||
print(out) | ||
|
||
print("App start script is complete.") |
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,22 @@ | ||
#!/bin/bash | ||
|
||
|
||
# gRPC server will spawn on 50051 | ||
PORT=50051 | ||
|
||
{ # Try to start up the server | ||
echo "Starting up the gRPC server..." | ||
nohup python bin/start-grpc-server.py & | ||
} || { | ||
echo "gRPC server initialization script failed. Is there already a local server running in the pod?" | ||
} | ||
|
||
|
||
echo "Waiting 5 seconds..." | ||
sleep 5 | ||
|
||
|
||
# Start up the streamlit application | ||
echo "Starting up streamlit application..." | ||
streamlit run main.py --server.port $1 --server.address 127.0.0.1 | ||
|
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,33 @@ | ||
# start-grpc-server.py | ||
from concurrent import futures | ||
import logging | ||
import grpc | ||
from ft.proto import fine_tuning_studio_pb2_grpc | ||
from ft.service import FineTuningStudioApp | ||
from multiprocessing import Process | ||
import socket | ||
|
||
def start_server(blocking: bool = False): | ||
port = "50051" | ||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) | ||
fine_tuning_studio_pb2_grpc.add_FineTuningStudioServicer_to_server(FineTuningStudioApp(), server=server) | ||
server.add_insecure_port("[::]:" + port) | ||
server.start() | ||
print("Server started, listening on " + port) | ||
|
||
if blocking: | ||
server.wait_for_termination() | ||
|
||
def is_port_in_use(port: int) -> bool: | ||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: | ||
result = sock.connect_ex(('localhost', port)) | ||
return result == 0 | ||
|
||
|
||
port = 50051 | ||
if not is_port_in_use(port): | ||
print("Starting up the gRPC server.") | ||
# Start the gRPC server if it's not already running | ||
start_server(blocking=True) | ||
else: | ||
print("Server is already running.") |
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,12 @@ | ||
|
||
import streamlit as st | ||
import grpc | ||
|
||
from ft.api import * | ||
from ft.proto.fine_tuning_studio_pb2_grpc import FineTuningStudioStub | ||
|
||
|
||
with grpc.insecure_channel('localhost:50051') as channel: | ||
stub = FineTuningStudioStub(channel=channel) | ||
datasets: ListDatasetsResponse = stub.ListDatasets(ListDatasetsRequest()) | ||
print(datasets) |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What multiprocessing are we planning to implement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an old artifact from trying different ways of spawning the gRPC server. Originally I was trying to spawn the gRPC server as a sub-process to the Streamlit server, but this was causing some headache because streamlit reruns entry point scripts upon every interaction.
We can probably safely remove this in the future.