|
1 | 1 | import os
|
2 | 2 | import argparse
|
3 | 3 | from azureml.core import Workspace
|
4 |
| -from azureml.core.image import ContainerImage, Image |
5 |
| -from azureml.core.model import Model |
| 4 | +from azureml.core.environment import Environment |
| 5 | +from azureml.core.model import Model, InferenceConfig |
6 | 6 | import shutil
|
7 | 7 | from ml_service.util.env_variables import Env
|
8 | 8 |
|
|
36 | 36 | shutil.copy(os.path.join(".", sources_dir,
|
37 | 37 | "conda_dependencies.yml"), path_to_scoring)
|
38 | 38 | os.chdir(path_to_scoring)
|
39 |
| -image_config = ContainerImage.image_configuration( |
40 |
| - execution_script=score_file, |
41 |
| - runtime="python", |
42 |
| - conda_file="conda_dependencies.yml", |
43 |
| - description="Image with ridge regression model", |
44 |
| - tags={"area": "diabetes_regression"}, |
45 |
| -) |
46 | 39 |
|
47 |
| -image = Image.create( |
48 |
| - name=e.image_name, models=[ |
49 |
| - model], image_config=image_config, workspace=ws |
50 |
| -) |
| 40 | +scoring_env = Environment.from_conda_specification(name="scoringenv", file_path="conda_dependencies.yml") # NOQA: E501 |
| 41 | +inference_config = InferenceConfig( |
| 42 | + entry_script=score_file, environment=scoring_env) |
| 43 | +package = Model.package(ws, [model], inference_config) |
| 44 | +package.wait_for_creation(show_output=True) |
| 45 | +# Display the package location/ACR path |
| 46 | +print(package.location) |
51 | 47 |
|
52 | 48 | os.chdir(cwd)
|
53 | 49 |
|
54 |
| -image.wait_for_creation(show_output=True) |
55 |
| - |
56 |
| -if image.creation_state != "Succeeded": |
57 |
| - raise Exception("Image creation status: {image.creation_state}") |
| 50 | +if package.state != "Succeeded": |
| 51 | + raise Exception("Image creation status: {package.creation_state}") |
58 | 52 |
|
59 |
| -print("{}(v.{} [{}]) stored at {} with build log {}".format( |
60 |
| - image.name, |
61 |
| - image.version, |
62 |
| - image.creation_state, |
63 |
| - image.image_location, |
64 |
| - image.image_build_log_uri, |
65 |
| -) |
66 |
| -) |
| 53 | +print("Package stored at {} with build log {}".format(package.location, package.package_build_log_uri)) # NOQA: E501 |
67 | 54 |
|
68 | 55 | # Save the Image Location for other AzDO jobs after script is complete
|
69 | 56 | if args.output_image_location_file is not None:
|
70 | 57 | print("Writing image location to %s" % args.output_image_location_file)
|
71 | 58 | with open(args.output_image_location_file, "w") as out_file:
|
72 |
| - out_file.write(str(image.image_location)) |
| 59 | + out_file.write(str(package.location)) |
0 commit comments