Skip to content

Commit

Permalink
Project import generated by Copybara. (#12)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: c940ae2b6eabf1ea03ae27ac404d5004a4e894cc

Co-authored-by: Snowflake Authors <[email protected]>
  • Loading branch information
snowflake-provisioner and Snowflake Authors authored May 12, 2023
1 parent 0cd258b commit 4044414
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 14 deletions.
8 changes: 4 additions & 4 deletions ci/conda_recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package:
name: snowflake-ml-python
version: 0.2.4 # this has to be in sync with snowflake/ml/BUILD.bazel and snowflake/ml/version.py
version: 0.3.0 # this has to be in sync with snowflake/ml/BUILD.bazel and snowflake/ml/version.py

source:
path: ../../
Expand Down Expand Up @@ -40,11 +40,11 @@ requirements:
about:
home: https://github.com/snowflakedb/snowflake-ml-python
license: Apache-2.0
license_family : Apache
license_family: Apache
license_file: ../../LICENSE.txt
summary: Snowflake ML Library
description: |
Snowflake ML client Library is used for interacting with Snowflake to build machine learning solutions.
Functionalities include feature engineering, modeling, model management, deployment, etc
Snowflake ML client Library is used for interacting with Snowflake to build machine learning solutions.
Functionalities include feature engineering, modeling, model management, deployment, etc
dev_url: https://github.com/snowflakedb/snowflake-ml-python
doc_url: https://github.com/snowflakedb/snowflake-ml-python/blob/main/README.md
4 changes: 2 additions & 2 deletions snowflake/ml/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ snowml_wheel(
# versions in the requirements file, we are pinning the versions here.
"scikit-learn==1.2.1",
"xgboost==1.7.3",
"joblib>=1.0.0,<=1.1.1", # All the release versions between 1.0.0 and 1.1.1 are available in SF Conda channel.
"joblib>=1.0.0,<=1.1.1", # All the release versions between 1.0.0 and 1.1.1 are available in SF Conda channel.
],
version = "0.2.4", # this has to be in sync with version.py and ci/conda_recipe/meta.yaml
version = "0.3.0", # this has to be in sync with version.py and ci/conda_recipe/meta.yaml
deps = [
"//snowflake/ml/metrics:metrics_pkg",
"//snowflake/ml/preprocessing:preprocessing_pkg",
Expand Down
1 change: 1 addition & 0 deletions snowflake/ml/_internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ py_library(
py_test(
name = "file_utils_test",
srcs = ["file_utils_test.py"],
timeout = "short",
deps = [
":file_utils",
],
Expand Down
9 changes: 5 additions & 4 deletions snowflake/ml/_internal/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ def zip_file_or_directory_to_stream(
with io.BytesIO() as input_stream:
with zipfile.ZipFile(input_stream, mode="w", compression=zipfile.ZIP_DEFLATED) as zf:

cur_path = os.path.dirname(path)
while os.path.realpath(cur_path) != os.path.realpath(start_path):
zf.writestr(f"{os.path.relpath(cur_path, start_path)}/", "")
cur_path = os.path.dirname(cur_path)
if os.path.realpath(path) != os.path.realpath(start_path):
cur_path = os.path.dirname(path)
while os.path.realpath(cur_path) != os.path.realpath(start_path):
zf.writestr(f"{os.path.relpath(cur_path, start_path)}/", "")
cur_path = os.path.dirname(cur_path)

if os.path.isdir(path):
for dirname, _, files in os.walk(path):
Expand Down
4 changes: 4 additions & 0 deletions snowflake/ml/_internal/file_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ def test_zip_file_or_directory_to_stream(self) -> None:
importlib.import_module("snowflake.snowpark.fake_module.p")

sys.path.remove(os.path.abspath(zip_module_filename))

with file_utils.zip_file_or_directory_to_stream(fake_mod_dirpath, fake_mod_dirpath) as input_stream:
with open(zip_module_filename, "wb") as f:
f.write(input_stream.getbuffer())
1 change: 1 addition & 0 deletions snowflake/ml/registry/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ py_library(
"//snowflake/ml/_internal/utils:formatting",
"//snowflake/ml/_internal/utils:query_result_checker",
"//snowflake/ml/_internal/utils:uri",
"//snowflake/ml/_internal:file_utils",
"//snowflake/ml/model:_model",
"//snowflake/ml/model:_deployer",
"//snowflake/ml/utils:telemetry",
Expand Down
10 changes: 7 additions & 3 deletions snowflake/ml/registry/model_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from absl import logging

from snowflake import connector, snowpark
from snowflake.ml._internal import file_utils
from snowflake.ml._internal.utils import formatting, query_result_checker, uri
from snowflake.ml.model import (
_deployer,
Expand All @@ -21,7 +22,6 @@
)
from snowflake.ml.registry import _schema
from snowflake.ml.utils import telemetry
from snowflake.snowpark._internal import utils

if TYPE_CHECKING:
import pandas as pd
Expand Down Expand Up @@ -998,6 +998,9 @@ def log_model(
output, which could be inferred by calling `infer_signature` method with sample input data.
sample_input_data: Sample of the input data for the model.
Raises:
TypeError: Raised when both signatures and sample_input_data is not presented. Will be captured locally.
Returns:
String of the auto-generate unique model identifier. None if failed.
"""
Expand Down Expand Up @@ -1031,6 +1034,8 @@ def log_model(
pip_requirements=pip_requirements,
sample_input=sample_input_data,
)
else:
raise TypeError("Either signature or sample input data should exist for native model packaging.")
id = self.log_model_path(
path=tmpdir,
type="snowflake_native",
Expand Down Expand Up @@ -1174,7 +1179,6 @@ def log_model_path(
Returns:
String of the auto-generate unique model identifier.
"""

# Copy model from local disk to remote stage.
fully_qualified_model_stage_name = self._prepare_model_stage(model_name=name, model_version=version)

Expand All @@ -1183,7 +1187,7 @@ def log_model_path(
if os.path.isfile(path):
self._session.file.put(path, f"{fully_qualified_model_stage_name}/data")
elif os.path.isdir(path):
with utils.zip_file_or_directory_to_stream(path, path, add_init_py=True) as input_stream:
with file_utils.zip_file_or_directory_to_stream(path, path) as input_stream:
self._session._conn.upload_stream(
input_stream=input_stream,
stage_location=fully_qualified_model_stage_name,
Expand Down
2 changes: 1 addition & 1 deletion snowflake/ml/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Update this for the versions
# Don't change the forth version number from None
VERSION = (0, 2, 4, None) # this has to be in sync with BUILD.bazel and ci/conda_recipe/meta.yaml
VERSION = (0, 3, 0, None) # this has to be in sync with BUILD.bazel and ci/conda_recipe/meta.yaml


def get_version() -> str:
Expand Down

0 comments on commit 4044414

Please sign in to comment.