Skip to content

Commit 0eac229

Browse files
authored
feat: Update Model Repo interfaces (#227)
1 parent 9e40001 commit 0eac229

5 files changed

Lines changed: 36 additions & 56 deletions

File tree

README.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ _Note: All pods automatically come with runpodctl installed with a pod-scoped AP
2323
- [To receive a file](#to-receive-a-file)
2424
- [Using Google Drive](#using-google-drive)
2525
- [Pod Commands](#pod-commands)
26-
- [Model Repository Commands](#model-repository-commands)
2726
- [Acknowledgements](#acknowledgements)
2827

2928
## Get Started
@@ -135,32 +134,6 @@ runpodctl stop pod {podId}
135134

136135
For a comprehensive list of commands, visit [RunPod CLI documentation](docs/runpodctl.md).
137136

138-
## Model Repository Commands
139-
140-
Model repository commands let you upload, list, and remove AI models that can later be deployed with pods.
141-
142-
```bash
143-
# Upload a model directory to your account's repository
144-
runpodctl create model \
145-
--provider huggingface \
146-
--name lodestones/Chroma \
147-
--credential-reference secret://runpod/model-storage \
148-
--version 1.0.0 \
149-
--model-path ./chroma-model
150-
151-
# List models in your repository
152-
runpodctl get models
153-
154-
# Remove a model by owner and name
155-
runpodctl remove model \
156-
--owner your-org \
157-
--name lodestones/Chroma
158-
```
159-
160-
Supplying `--model-path` archives the directory into a `.tar.gz` file, starts a multipart upload, transfers the artifact using the pre-signed URLs, and finalizes the upload automatically.
161-
162-
You can still pass `--create-upload` on its own to inspect the multipart session details without uploading any files.
163-
164137
## Acknowledgements
165138

166139
- [cobra](https://github.com/spf13/cobra)

api/model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ type CreateModelRepoUploadInput struct {
201201
Name string `json:"name,omitempty"`
202202
FileName string `json:"fileName"`
203203
FileSizeBytes string `json:"fileSizeBytes"`
204+
ModelVersionHash string `json:"modelVersionHash,omitempty"`
204205
PartSizeBytes string `json:"partSizeBytes,omitempty"`
205206
ContentType string `json:"contentType,omitempty"`
206207
Metadata map[string]interface{} `json:"metadata,omitempty"`
@@ -647,6 +648,7 @@ func CreateModelRepoUpload(input *CreateModelRepoUploadInput) (*ModelRepoMutatio
647648
addString("contentType", input.ContentType)
648649
addString("credentialType", input.CredentialType)
649650
addString("credentialReference", input.CredentialReference)
651+
addString("modelVersionHash", input.ModelVersionHash)
650652

651653
if len(input.Metadata) > 0 {
652654
payload["metadata"] = input.Metadata

cmd/model/addModelToRepo.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ type modelFile struct {
7979
// TODO: replace the manual completion call with github.com/aws/aws-sdk-go-v2/service/s3's
8080
// CompleteMultipartUpload to rely on the SDK for payload formatting and signing logic.
8181

82-
// AddModelToRepoCmd uploads a model to the RunPod model repository.
83-
// Hidden while the model repository feature is in development and not ready for general use.
8482
var AddModelToRepoCmd = &cobra.Command{
8583
Use: "model",
8684
Args: cobra.ExactArgs(0),
87-
Short: "upload a model",
88-
Long: "upload a model to the RunPod model repository",
85+
Short: "internal command",
86+
Long: "",
8987
Hidden: true,
9088
Run: func(cmd *cobra.Command, args []string) {
9189
setModelGraphQLTimeout(cmd)
@@ -189,18 +187,18 @@ var AddModelToRepoCmd = &cobra.Command{
189187
}
190188

191189
func init() {
192-
AddModelToRepoCmd.Flags().StringVar(&addModelName, "name", "", "model name within your namespace")
193-
AddModelToRepoCmd.Flags().StringVar(&addModelCredentialReference, "credential-reference", "", "reference that allows RunPod to access the model artifact")
194-
AddModelToRepoCmd.Flags().StringVar(&addModelCredentialType, "credential-type", "", "type of credential used to access the model artifact (API_KEY, OAUTH_TOKEN, OTHER, USERNAME_PASSWORD)")
195-
AddModelToRepoCmd.Flags().StringVar(&addModelVersionStatus, "version-status", "", "status to assign to the uploaded model version")
196-
AddModelToRepoCmd.Flags().StringVar(&addModelStatus, "model-status", "", "status to assign to the model record")
197-
AddModelToRepoCmd.Flags().BoolVar(&addModelCreateUpload, "create-upload", false, "initialize a multipart upload session for the model artifact")
198-
AddModelToRepoCmd.Flags().StringVar(&addModelFileName, "file-name", "", "file name to use for the model artifact upload")
199-
AddModelToRepoCmd.Flags().StringVar(&addModelFileSize, "file-size", "", "size of the model artifact in bytes")
200-
AddModelToRepoCmd.Flags().StringVar(&addModelPartSize, "part-size", "", "preferred multipart upload part size in bytes")
201-
AddModelToRepoCmd.Flags().StringVar(&addModelContentType, "content-type", "", "content type for the model artifact upload")
202-
AddModelToRepoCmd.Flags().StringVar(&addModelDirectoryPath, "model-path", "", "path to a directory containing the model files to upload")
203-
AddModelToRepoCmd.Flags().StringToStringVar(&addModelMetadata, "metadata", nil, "key=value metadata to associate with the model and upload")
190+
AddModelToRepoCmd.Flags().StringVar(&addModelName, "name", "", "")
191+
AddModelToRepoCmd.Flags().StringVar(&addModelCredentialReference, "credential-reference", "", "")
192+
AddModelToRepoCmd.Flags().StringVar(&addModelCredentialType, "credential-type", "", "")
193+
AddModelToRepoCmd.Flags().StringVar(&addModelVersionStatus, "version-status", "", "")
194+
AddModelToRepoCmd.Flags().StringVar(&addModelStatus, "model-status", "", "")
195+
AddModelToRepoCmd.Flags().BoolVar(&addModelCreateUpload, "create-upload", false, "")
196+
AddModelToRepoCmd.Flags().StringVar(&addModelFileName, "file-name", "", "")
197+
AddModelToRepoCmd.Flags().StringVar(&addModelFileSize, "file-size", "", "")
198+
AddModelToRepoCmd.Flags().StringVar(&addModelPartSize, "part-size", "", "")
199+
AddModelToRepoCmd.Flags().StringVar(&addModelContentType, "content-type", "", "")
200+
AddModelToRepoCmd.Flags().StringVar(&addModelDirectoryPath, "model-path", "", "")
201+
AddModelToRepoCmd.Flags().StringToStringVar(&addModelMetadata, "metadata", nil, "")
204202

205203
AddModelToRepoCmd.MarkFlagRequired("name") //nolint
206204
}
@@ -260,10 +258,15 @@ func collectModelFiles(dir string) ([]modelFile, error) {
260258
}
261259

262260
func uploadModelFiles(files []modelFile, baseInput *api.CreateModelRepoUploadInput) error {
261+
var modelVersionHash string
262+
263263
for _, file := range files {
264264
input := *baseInput
265265
input.FileName = file.RelativePath
266266
input.FileSizeBytes = strconv.FormatInt(file.Size, 10)
267+
if modelVersionHash != "" {
268+
input.ModelVersionHash = modelVersionHash
269+
}
267270

268271
result, err := api.CreateModelRepoUpload(&input)
269272
if err != nil {
@@ -272,6 +275,12 @@ func uploadModelFiles(files []modelFile, baseInput *api.CreateModelRepoUploadInp
272275
if result.Upload == nil {
273276
return fmt.Errorf("upload response missing upload session details for %s", file.RelativePath)
274277
}
278+
if modelVersionHash == "" {
279+
if result.Version == nil || result.Version.Hash == "" {
280+
return fmt.Errorf("upload response missing model version hash for %s", file.RelativePath)
281+
}
282+
modelVersionHash = result.Version.Hash
283+
}
275284

276285
if err = completeModelUpload(result.Upload, file.AbsolutePath); err != nil {
277286
return fmt.Errorf("upload %s: %w", file.RelativePath, err)

cmd/model/getModels.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ var (
2020
getAll bool
2121
)
2222

23-
// GetModelsCmd lists models that are available in the RunPod model repository.
24-
// Hidden while the model repository feature is in development and not ready for general use.
2523
var GetModelsCmd = &cobra.Command{
2624
Use: "models",
2725
Args: cobra.ExactArgs(0),
28-
Short: "list models",
29-
Long: "list models available in the RunPod model repository",
26+
Short: "internal command",
27+
Long: "",
3028
Hidden: true,
3129
Run: func(cmd *cobra.Command, args []string) {
3230
input := &api.GetModelsInput{
@@ -56,9 +54,9 @@ var GetModelsCmd = &cobra.Command{
5654
}
5755

5856
func init() {
59-
GetModelsCmd.Flags().StringVar(&getProvider, "provider", "", "filter models by provider (e.g. huggingface)")
60-
GetModelsCmd.Flags().StringVar(&getName, "name", "", "filter models by name")
61-
GetModelsCmd.Flags().BoolVar(&getAll, "all", false, "list all models available in the RunPod repository")
57+
GetModelsCmd.Flags().StringVar(&getProvider, "provider", "", "")
58+
GetModelsCmd.Flags().StringVar(&getName, "name", "", "")
59+
GetModelsCmd.Flags().BoolVar(&getAll, "all", false, "")
6260
}
6361

6462
func displayModels(models []*api.Model) {

cmd/model/removeModel.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ var (
1414
removeName string
1515
)
1616

17-
// RemoveModelCmd removes a model from the RunPod model repository.
18-
// Hidden while the model repository feature is in development and not ready for general use.
1917
var RemoveModelCmd = &cobra.Command{
2018
Use: "model",
2119
Args: cobra.ExactArgs(0),
22-
Short: "remove a model",
23-
Long: "remove a model from the RunPod model repository",
20+
Short: "internal command",
21+
Long: "",
2422
Hidden: true,
2523
Run: func(cmd *cobra.Command, args []string) {
2624
if removeOwner == "" || removeName == "" {
@@ -63,8 +61,8 @@ var RemoveModelCmd = &cobra.Command{
6361
}
6462

6563
func init() {
66-
RemoveModelCmd.Flags().StringVar(&removeOwner, "owner", "", "account or namespace that owns the model")
67-
RemoveModelCmd.Flags().StringVar(&removeName, "name", "", "model name within the owner namespace")
64+
RemoveModelCmd.Flags().StringVar(&removeOwner, "owner", "", "")
65+
RemoveModelCmd.Flags().StringVar(&removeName, "name", "", "")
6866

6967
RemoveModelCmd.MarkFlagRequired("owner") //nolint
7068
RemoveModelCmd.MarkFlagRequired("name") //nolint

0 commit comments

Comments
 (0)