Skip to content

Commit

Permalink
scp checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nhutleFlydinotech committed May 9, 2024
1 parent 8bb892d commit a855a95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PEM_PATH=
SERVER_ADDRESS=
DESTINATION_FILE=
19 changes: 19 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
from fastapi import File, UploadFile, Form
from typing import Annotated
import shutil
import subprocess
import os
from dotenv import load_dotenv

load_dotenv()


class Api:
Expand Down Expand Up @@ -313,6 +318,7 @@ def upload_lora_and_merge_lora_to_checkpoint(self, lora_file: UploadFile, merge_

print("Started to merge lora")
merged_res = self.merge_lora(merge_request)
self.copy_checkpoint(merged_res)

message = f'Upload and merge lora <{lora_file.filename}> to checkpoint <{merge_request.model}> successfully.'

Expand All @@ -323,6 +329,19 @@ def upload_lora_and_merge_lora_to_checkpoint(self, lora_file: UploadFile, merge_
raise e
# end try

def copy_checkpoint(source_file):
pem_file = os.environ['PEM_PATH']
server_address = os.environ['SERVER_ADDRESS']
destination_file = os.environ['DESTINATION_FILE']

command = ["sudo", "scp", "-i", pem_file, source_file, server_address + ":" + destination_file]

try:
subprocess.run(command, check=True)
print("File " + source_file + " copied successfully!")
except subprocess.CalledProcessError as e:
print("Error copying file:", e.output)
raise e

def on_app_started(_, app: FastAPI):
Api(app, queue_lock, '/supermerger/v1')

0 comments on commit a855a95

Please sign in to comment.