-
Notifications
You must be signed in to change notification settings - Fork 282
Added native huggingface native commands and e2e and workflow tests #3341
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
Changes from all commits
7f9a899
edf35c3
96bdd84
ec6a028
4451840
bc12fba
ff52c72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| name: HuggingFace Tests | ||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - "master" | ||
| # Triggers the workflow on PRs to master branch only. | ||
| pull_request_target: | ||
| types: [labeled] | ||
| branches: | ||
| - "master" | ||
|
|
||
| # Ensures that only the latest commit is running for each PR at a time. | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| jobs: | ||
| HuggingFace-Tests: | ||
| name: HuggingFace tests (${{ matrix.os.name }}) | ||
| if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'safe to test') | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: | ||
| - name: ubuntu | ||
| version: 24.04 | ||
| - name: windows | ||
| version: 2022 | ||
| - name: macos | ||
| version: 14 | ||
| runs-on: ${{ matrix.os.name }}-${{ matrix.os.version }} | ||
| steps: | ||
| - name: Skip macOS - JGC-413 | ||
| if: matrix.os.name == 'macos' | ||
| run: | | ||
| echo "::warning::JGC-413 - Skip until artifactory bootstrap in osx is fixed" | ||
| exit 0 | ||
|
|
||
| - name: Checkout code | ||
| if: matrix.os.name != 'macos' | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha || github.ref }} | ||
|
|
||
| - name: Setup FastCI | ||
| if: matrix.os.name != 'macos' | ||
| uses: jfrog-fastci/fastci@v0 | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| fastci_otel_token: ${{ secrets.FASTCI_TOKEN }} | ||
|
|
||
| - name: Setup Go with cache | ||
| if: matrix.os.name != 'macos' | ||
| uses: jfrog/.github/actions/install-go-with-cache@main | ||
|
|
||
| - name: Setup Python | ||
| if: matrix.os.name != 'macos' | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Install HuggingFace CLI | ||
| if: matrix.os.name != 'macos' | ||
| run: | | ||
| pip install huggingface_hub | ||
| shell: bash | ||
|
|
||
| - name: Debug macOS Environment and Set Timeout | ||
| if: runner.os == 'macOS' | ||
| run: | | ||
| echo "=== macOS Debug Information ===" | ||
| echo "Architecture: $(uname -m)" | ||
| echo "macOS Version: $(sw_vers -productVersion)" | ||
| echo "macOS Build: $(sw_vers -buildVersion)" | ||
| echo "Available memory: $(system_profiler SPHardwareDataType | grep Memory || echo 'Memory info not available')" | ||
| echo "Available disk space: $(df -h)" | ||
| echo "Go version: $(go version)" | ||
| echo "Setting RT_CONNECTION_TIMEOUT_SECONDS to 2400 for macOS" | ||
| echo "RT_CONNECTION_TIMEOUT_SECONDS=2400" >> $GITHUB_ENV | ||
|
|
||
| - name: Install local Artifactory | ||
| if: matrix.os.name != 'macos' | ||
| uses: jfrog/.github/actions/install-local-artifactory@main | ||
| with: | ||
| RTLIC: ${{ secrets.RTLIC }} | ||
| RT_CONNECTION_TIMEOUT_SECONDS: ${{ env.RT_CONNECTION_TIMEOUT_SECONDS || '1200' }} | ||
|
|
||
| - name: Get ID Token and Exchange Token | ||
| if: matrix.os.name != 'macos' | ||
| shell: bash | ||
| run: | | ||
| ID_TOKEN=$(curl -sLS -H "User-Agent: actions/oidc-client" -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ | ||
| "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=jfrog-github" | jq .value | tr -d '"') | ||
| echo "JFROG_CLI_OIDC_EXCHANGE_TOKEN_ID=${ID_TOKEN}" >> $GITHUB_ENV | ||
|
|
||
| - name: Run HuggingFace tests | ||
| if: matrix.os.name != 'macos' | ||
| run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.huggingface --jfrog.url=http://127.0.0.1:8082 --jfrog.adminToken=${{ env.JFROG_TESTS_LOCAL_ACCESS_TOKEN }} | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import ( | |
| "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/golang" | ||
| "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/gradle" | ||
| helmcmd "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/helm" | ||
| huggingfaceCommands "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/huggingface" | ||
| "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/mvn" | ||
| "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/npm" | ||
| containerutils "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/ocicontainer" | ||
|
|
@@ -58,6 +59,7 @@ import ( | |
| "github.com/jfrog/jfrog-cli/docs/buildtools/gopublish" | ||
| gradledoc "github.com/jfrog/jfrog-cli/docs/buildtools/gradle" | ||
| "github.com/jfrog/jfrog-cli/docs/buildtools/gradleconfig" | ||
| "github.com/jfrog/jfrog-cli/docs/buildtools/huggingface" | ||
| mvndoc "github.com/jfrog/jfrog-cli/docs/buildtools/mvn" | ||
| "github.com/jfrog/jfrog-cli/docs/buildtools/mvnconfig" | ||
| "github.com/jfrog/jfrog-cli/docs/buildtools/npmcommand" | ||
|
|
@@ -475,6 +477,17 @@ func GetCommands() []cli.Command { | |
| Category: buildToolsCategory, | ||
| Action: twineCmd, | ||
| }, | ||
| { | ||
| Name: "hugging-face", | ||
| Aliases: []string{"hf"}, | ||
| Flags: cliutils.GetCommandFlags(cliutils.HuggingFace), | ||
| HelpName: corecommon.CreateUsage("hugging-face", huggingface.GetDescription(), huggingface.Usage), | ||
| Description: huggingface.GetDescription(), | ||
| UsageText: huggingface.GetArguments(), | ||
| Hidden: true, | ||
| Action: huggingFaceCmd, | ||
| Category: buildToolsCategory, | ||
| }, | ||
| }) | ||
| return decorateWithFlagCapture(cmds) | ||
| } | ||
|
|
@@ -1115,6 +1128,80 @@ func loginCmd(c *cli.Context) error { | |
| return nil | ||
| } | ||
|
|
||
| func huggingFaceCmd(c *cli.Context) error { | ||
| if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil { | ||
| return err | ||
| } | ||
| if c.NArg() < 1 { | ||
| return cliutils.WrongNumberOfArgumentsHandler(c) | ||
| } | ||
| args := cliutils.ExtractCommand(c) | ||
| cmdName, hfArgs := getCommandName(args) | ||
| switch cmdName { | ||
| case "u", "upload": | ||
| return huggingFaceUploadCmd(c, hfArgs) | ||
| case "d", "download": | ||
| return huggingFaceDownloadCmd(c, hfArgs) | ||
| default: | ||
| return errorutils.CheckErrorf("unknown HuggingFace command: '%s'. Valid commands are: upload (u), download (d)", cmdName) | ||
| } | ||
| } | ||
|
|
||
| func huggingFaceUploadCmd(c *cli.Context, hfArgs []string) error { | ||
| // Upload requires folderPath and repoID | ||
| if len(hfArgs) < 2 { | ||
| return cliutils.PrintHelpAndReturnError("Folder path and repository ID are required.", c) | ||
| } | ||
| folderPath := hfArgs[0] | ||
| if folderPath == "" { | ||
| return cliutils.PrintHelpAndReturnError("Folder path cannot be empty.", c) | ||
| } | ||
| repoID := hfArgs[1] | ||
| if repoID == "" { | ||
| return cliutils.PrintHelpAndReturnError("Repository ID cannot be empty.", c) | ||
| } | ||
| revision := "" | ||
| if c.String("revision") != "" { | ||
| revision = c.String("revision") | ||
| } | ||
| repoType := c.String("repo-type") | ||
| if repoType == "" { | ||
| repoType = "model" | ||
| } | ||
| huggingFaceUploadCmd := huggingfaceCommands.NewHuggingFaceUpload().SetFolderPath(folderPath).SetRepoId(repoID).SetRepoType(repoType).SetRevision(revision) | ||
naveenku-jfrog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return commands.Exec(huggingFaceUploadCmd) | ||
| } | ||
|
|
||
| func huggingFaceDownloadCmd(c *cli.Context, hfArgs []string) error { | ||
| // Download requires repoID | ||
| if len(hfArgs) < 1 { | ||
| return cliutils.PrintHelpAndReturnError("Model/Dataset name is required.", c) | ||
| } | ||
| const eTagTimeout = 86400 | ||
| repoID := hfArgs[0] | ||
| if repoID == "" { | ||
| return cliutils.PrintHelpAndReturnError("Model/Dataset name cannot be empty.", c) | ||
| } | ||
| revision := "" | ||
| if c.String("revision") != "" { | ||
| revision = c.String("revision") | ||
| } | ||
| etagTimeout := eTagTimeout | ||
| if c.String("etag-timeout") != "" { | ||
| var err error | ||
| etagTimeout, err = strconv.Atoi(c.String("etag-timeout")) | ||
| if err != nil { | ||
| return errorutils.CheckErrorf("invalid etag-timeout value: %s", c.String("etag-timeout")) | ||
| } | ||
| } | ||
| repoType := c.String("repo-type") | ||
| if repoType == "" { | ||
| repoType = "model" | ||
| } | ||
|
Comment on lines
+1197
to
+1200
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default values for repoType are set in the command functions, but the flag definition says "[Default: model]" which suggests it should be set at the flag level.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NA. |
||
| huggingFaceDownloadCmd := huggingfaceCommands.NewHuggingFaceDownload().SetRepoId(repoID).SetRepoType(repoType).SetRevision(revision).SetEtagTimeout(etagTimeout) | ||
| return commands.Exec(huggingFaceDownloadCmd) | ||
| } | ||
|
|
||
| func dockerScanCmd(c *cli.Context, imageTag string) error { | ||
| if show, err := cliutils.ShowGenericCmdHelpIfNeeded(c, c.Args(), securityCLI.DockerScanCmdHiddenName); show || err != nil { | ||
| return err | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package huggingface | ||
|
|
||
| var Usage = []string{"hf d <model-name>", | ||
| "hf u <folder-path> <repo-id>"} | ||
|
|
||
| func GetDescription() string { | ||
| return `Download or upload models/datasets from/to HuggingFace Hub.` | ||
| } | ||
|
|
||
| func GetArguments() string { | ||
| return ` d <model-name> | ||
| Download a model/dataset from HuggingFace Hub. | ||
| model-name | ||
| The HuggingFace model repository ID (e.g., 'bert-base-uncased' or 'username/model-name'). | ||
|
|
||
| u <folder-path> <repo-id> | ||
| Upload a model or dataset folder to HuggingFace Hub. | ||
| folder-path | ||
| Path to the folder to upload. | ||
| repo-id | ||
| The HuggingFace repository ID (e.g., 'username/model-name' or 'username/dataset-name'). | ||
|
|
||
| Command options: | ||
| --revision | ||
| [Optional] The revision (commit hash, branch name, or tag) to download/upload. Defaults to main branch if not specified. | ||
|
|
||
| --repo-type | ||
| [Optional] The repository type. Can be 'model' or 'dataset'. Default: 'model'. | ||
|
|
||
| --etag-timeout | ||
| [Optional] [Download only] Timeout in seconds for ETag validation. Default: 86400 seconds (24 hours).` | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.