-
Notifications
You must be signed in to change notification settings - Fork 762
[Jobs] Add huggingface-cli jobs
commands
#3211
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
Open
lhoestq
wants to merge
32
commits into
main
Choose a base branch
from
jobs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
4836c04
jobs
lhoestq 682a789
style
lhoestq af05c27
docs
lhoestq 3895c8e
mypy
lhoestq 3661cb7
style
lhoestq 13f17c8
minor
lhoestq 5e99d64
remove hfjobs mentions
lhoestq 7efe998
add huggingface-cli jobs uv commands
lhoestq ab8511e
add some uv options
lhoestq 3c00292
add test
lhoestq 3136ef4
fix for 3.8
lhoestq 9fc3c78
Update src/huggingface_hub/commands/jobs/uv.py
davanstrien fd926b5
move to HfApi
lhoestq 1bf5f66
minor
lhoestq aefb493
more comments
lhoestq 31a3d97
uv run local_script.py
lhoestq f7c8be9
lucain's comments
lhoestq 541aa6a
more lucain's comments
lhoestq 251e719
Apply suggestions from code review
lhoestq 97a856b
style
lhoestq 1102968
minor
lhoestq 99b538a
Remove JobUrl and add url in JobInfo directly
Wauplin 53fb0aa
Apply suggestions from code review
lhoestq 4e3523d
add namespace arg
lhoestq 5db3b42
fix wrong job url
lhoestq 76588ef
add missing methods at top level
lhoestq 63dd90f
add docs
lhoestq bfd326a
uv script url as env, not secret
lhoestq c9ab2f1
rename docs
lhoestq cf59dca
update test
lhoestq da1d40d
again
lhoestq 334d831
improve docs
lhoestq 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 hidden or 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 hidden or 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 hidden or 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,126 @@ | ||
# coding=utf-8 | ||
# Copyright 2019-present, the HuggingFace Inc. team. | ||
lhoestq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
from enum import Enum | ||
from typing import Any, Dict, List, Optional | ||
|
||
from huggingface_hub import constants | ||
from huggingface_hub._space_api import SpaceHardware | ||
from huggingface_hub.utils._datetime import parse_datetime | ||
from huggingface_hub.utils._http import fix_hf_endpoint_in_url | ||
|
||
|
||
class JobStage(str, Enum): | ||
""" | ||
Enumeration of possible stage of a Job on the Hub. | ||
|
||
Value can be compared to a string: | ||
```py | ||
assert JobStage.COMPLETED == "COMPLETED" | ||
``` | ||
|
||
Taken from https://github.com/huggingface/moon-landing/blob/main/server/job_types/JobInfo.ts#L61 (private url). | ||
""" | ||
|
||
# Copied from moon-landing > server > lib > Job.ts | ||
COMPLETED = "COMPLETED" | ||
CANCELED = "CANCELED" | ||
ERROR = "ERROR" | ||
DELETED = "DELETED" | ||
RUNNING = "RUNNING" | ||
|
||
|
||
class JobUrl(str): | ||
"""Subclass of `str` describing a job URL on the Hub. | ||
|
||
`JobUrl` is returned by `HfApi.create_job`. It inherits from `str` for backward | ||
compatibility. At initialization, the URL is parsed to populate properties: | ||
- endpoint (`str`) | ||
- namespace (`Optional[str]`) | ||
- job_id (`str`) | ||
- url (`str`) | ||
|
||
Args: | ||
url (`Any`): | ||
String value of the job url. | ||
endpoint (`str`, *optional*): | ||
Endpoint of the Hub. Defaults to <https://huggingface.co>. | ||
|
||
Example: | ||
```py | ||
>>> HfApi.run_job("ubuntu", ["echo", "hello"]) | ||
JobUrl('https://huggingface.co/jobs/lhoestq/6877b757344d8f02f6001012', endpoint='https://huggingface.co', job_id='6877b757344d8f02f6001012') | ||
``` | ||
|
||
Raises: | ||
[`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) | ||
If URL cannot be parsed. | ||
""" | ||
|
||
def __new__(cls, url: Any, endpoint: Optional[str] = None): | ||
url = fix_hf_endpoint_in_url(url, endpoint=endpoint) | ||
return super(JobUrl, cls).__new__(cls, url) | ||
|
||
def __init__(self, url: Any, endpoint: Optional[str] = None) -> None: | ||
super().__init__() | ||
# Parse URL | ||
self.endpoint = endpoint or constants.ENDPOINT | ||
namespace, job_id = url.split("/")[-2:] | ||
|
||
# Populate fields | ||
self.namespace = namespace | ||
self.job_id = job_id | ||
self.url = str(self) # just in case it's needed | ||
|
||
def __repr__(self) -> str: | ||
return f"JobUrl('{self}', endpoint='{self.endpoint}', job_id='{self.job_id}')" | ||
|
||
|
||
@dataclass | ||
class JobStatus: | ||
stage: JobStage | ||
message: Optional[str] | ||
|
||
def __init__(self, **kwargs) -> None: | ||
self.stage = kwargs["stage"] | ||
self.message = kwargs.get("message") | ||
|
||
|
||
@dataclass | ||
class JobInfo: | ||
id: str | ||
created_at: Optional[datetime] | ||
docker_image: Optional[str] | ||
space_id: Optional[str] | ||
command: Optional[List[str]] | ||
arguments: Optional[List[str]] | ||
environment: Optional[Dict[str, Any]] | ||
secrets: Optional[Dict[str, Any]] | ||
flavor: Optional[SpaceHardware] | ||
status: Optional[JobStatus] | ||
|
||
def __init__(self, **kwargs) -> None: | ||
self.id = kwargs["id"] | ||
created_at = kwargs.get("createdAt") or kwargs.get("created_at") | ||
self.created_at = parse_datetime(created_at) if created_at else None | ||
self.docker_image = kwargs.get("dockerImage") or kwargs.get("docker_image") | ||
self.space_id = kwargs.get("spaceId") or kwargs.get("space_id") | ||
self.command = kwargs.get("command") | ||
self.arguments = kwargs.get("arguments") | ||
self.environment = kwargs.get("environment") | ||
self.secrets = kwargs.get("secrets") | ||
self.flavor = kwargs.get("flavor") | ||
self.status = JobStatus(**(kwargs["status"] if isinstance(kwargs.get("status"), dict) else {})) |
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.
Uh oh!
There was an error while loading. Please reload this page.