Skip to content
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

fix: compare bento manifest and dependency client #4993

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/_bentoml_sdk/models/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,9 @@ class HuggingFaceModel(Model[str]):

@cached_property
def commit_hash(self) -> str:
from huggingface_hub import get_hf_file_metadata
from huggingface_hub import hf_hub_url
from huggingface_hub import model_info

url = hf_hub_url(
self.model_id, CONFIG_FILE, revision=self.revision, endpoint=self.endpoint
)
metadata = get_hf_file_metadata(url)
return metadata.commit_hash or self.revision
return model_info(self.model_id, revision=self.revision).sha or self.revision

def resolve(self, base_path: t.Union[PathType, FS, None] = None) -> str:
from huggingface_hub import snapshot_download
Expand Down
3 changes: 1 addition & 2 deletions src/_bentoml_sdk/service/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from simple_di import Provide
from simple_di import inject

from bentoml._internal.cloud.client import RestApiClient
from bentoml._internal.configuration.containers import BentoMLContainer
from bentoml.exceptions import BentoMLException

Expand Down Expand Up @@ -49,14 +48,14 @@ def get(
runner_mapping: dict[str, str] = Provide[
BentoMLContainer.remote_runner_mapping
],
client: RestApiClient = Provide[BentoMLContainer.rest_api_client],
) -> T | RemoteProxy[t.Any]:
from _bentoml_impl.client.proxy import RemoteProxy

media_type = "application/json"
if self.deployment and self.url:
raise BentoMLException("Cannot specify both deployment and url")
if self.deployment:
client = BentoMLContainer.rest_api_client.get()
deployment = client.v2.get_deployment(self.deployment, self.cluster)
try:
self.url = deployment.urls[0]
Expand Down
19 changes: 17 additions & 2 deletions src/bentoml/_internal/cloud/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,9 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
if (
target is None
or target.bento is None
or target.bento.manifest != bento_info.get_manifest()
or not _is_bento_manifest_equal(
target.bento.manifest, bento_info.get_manifest()
)
):
console.print("✨ [green bold]Bento change detected[/]")
spinner.update("🔄 Pushing Bento to BentoCloud")
Expand Down Expand Up @@ -864,7 +866,9 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
if (
target is None
or target.bento is None
or target.bento.manifest != bento_info.get_manifest()
or not _is_bento_manifest_equal(
target.bento.manifest, bento_info.get_manifest()
)
):
# stop log tail and reset the deployment
break
Expand Down Expand Up @@ -1373,3 +1377,14 @@ def _build_requirements_txt(bento_dir: str, config: BentoBuildConfig) -> bytes:
bentoml_requirement = f"-e ./{EDITABLE_BENTOML_DIR}"
content += f"{bentoml_requirement}\n".encode("utf8")
return content


def _is_bento_manifest_equal(
source: BentoManifestSchema, target: BentoManifestSchema
) -> bool:
source_data = bentoml_cattr.structure(source, BentoManifestSchema)
target_data = bentoml_cattr.structure(target, BentoManifestSchema)

config_merger.merge(source_data, target_data)
new_source = bentoml_cattr.unstructure(source_data, BentoManifestSchema)
return new_source == source
3 changes: 2 additions & 1 deletion src/bentoml_cli/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ def decorate(f: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
return decorate


@click.command(name="develop")
# FIXME: remove hidden flag when ready for GA
@click.command(name="develop", hidden=True)
@click.argument(
"bento_dir",
type=click.Path(exists=True, file_okay=False, dir_okay=True, readable=True),
Expand Down