def conda_dependencies(self):
        """
        Get module conda dependencies

        :return: CondaDependencies instance
        """
        cd = CondaDependencies()
        for c in self._get_value('CondaDependencies/CondaChannels'):
            cd.add_channel(c)
        for c in self._get_value('CondaDependencies/CondaPackages'):
            cd.add_conda_package(c)
        for p in self._get_value('CondaDependencies/PipPackages'):
            cd.add_pip_package(p)
        for p in self._get_value('CondaDependencies/PipOptions'):
            cd.set_pip_option(p)
        return cd
from azureml.core.conda_dependencies import CondaDependencies
from azureml.core.webservice import AciWebservice
from azureml.core.model import Model
from azureml.core import Workspace

import os

ws = Workspace.from_config()
model_name = "net.onnx"

model = Model(workspace=ws, name=model_name)

myenv = CondaDependencies(conda_dependencies_file_path=os.path.join(
    os.path.dirname(os.path.realpath(__file__)), '../../',
    'conda_dependencies.yml'))
myenv.add_channel("pytorch")

with open("myenv.yml", "w") as f:
    f.write(myenv.serialize_to_string())

myenv = Environment.from_conda_specification(name="myenv",
                                             file_path="myenv.yml")

inference_config = InferenceConfig(
    entry_script="code_final/deployment/score.py", environment=myenv)

aciconfig = AciWebservice.deploy_configuration(cpu_cores=1,
                                               memory_gb=1,
                                               tags={'demo': 'onnx'},
                                               description='ONNX for text')
Exemplo n.º 3
0
def generate_yaml(
    directory: str,
    ref_filename: str,
    needed_libraries: list,
    conda_filename: str,
):
    """
    Creates a deployment-specific yaml file as a subset of
    the image classification environment.yml

    Also adds extra libraries, if not present in environment.yml

    Args:
        directory (string): Directory name of reference yaml file
        ref_filename (string): Name of reference yaml file
        needed_libraries (list of strings): List of libraries needed
        in the Docker container
        conda_filename (string): Name of yaml file to be deployed
        in the Docker container

    Returns: Nothing

    """

    with open(os.path.join(directory, ref_filename), "r") as f:
        yaml_content = yaml.load(f, Loader=yaml.FullLoader)

    # Extract libraries to be installed using conda
    extracted_libraries = [
        depend for depend in yaml_content["dependencies"]
        if any(lib in depend for lib in needed_libraries)
    ]

    # Extract libraries to be installed using pip
    if any(isinstance(x, dict) for x in yaml_content["dependencies"]):
        # if the reference yaml file contains a "pip" section,
        # find where it is in the list of dependencies
        ind = [
            yaml_content["dependencies"].index(depend)
            for depend in yaml_content["dependencies"]
            if isinstance(depend, dict)
        ][0]
        extracted_libraries += [
            depend for depend in yaml_content["dependencies"][ind]["pip"]
            if any(lib in depend for lib in needed_libraries)
        ]

    # Check whether additional libraries are needed
    not_found = [
        lib for lib in needed_libraries
        if not any(lib in ext for ext in extracted_libraries)
    ]

    # Create the deployment-specific yaml file
    conda_env = CondaDependencies()
    for ch in yaml_content["channels"]:
        conda_env.add_channel(ch)
    for library in extracted_libraries + not_found:
        conda_env.add_conda_package(library)

    # Display the environment
    print(conda_env.serialize_to_string())

    # Save the file to disk
    conda_env.save_to_file(base_directory=os.getcwd(),
                           conda_file_path=conda_filename)
Exemplo n.º 4
0
 def conda_deps():
     deps = CondaDependencies(f'{project_folder}/environment.yml')
     deps.add_channel("conda-forge")
     deps.add_conda_package('curl')
     return deps
Exemplo n.º 5
0
workspace_name = "aa-ml-aml-workspace"  # The name of the workspace to look for or to create
workspace_region = 'eastus'  # Location of the workspace
computetarget_vm = 'Standard_NC6'  # Size of the VM to use
experiment_name = 'azureml-gpubenchmark'
score_script = 'score_and_track.py'
conda_file_name = 'fastai.yml'

ws = Workspace(workspace_name=workspace_name,
               subscription_id=subscription_id,
               resource_group=resource_group)

myenv = CondaDependencies()
myenv.add_conda_package("fastai")
myenv.add_conda_package("pytorch")
myenv.add_conda_package("torchvision")
myenv.add_channel("pytorch")
myenv.add_channel("fastai")

with open(conda_file_name, "w") as f:
    f.write(myenv.serialize_to_string())

from azureml.core.image import ContainerImage
# Image configuration
image_config = ContainerImage.image_configuration(
    execution_script=score_script,
    runtime="python",
    conda_file=conda_file_name,
    enable_gpu=True,
    description="Image classficiation service cats vs dogs",
    tags={
        "data": "cats-vs-dogs",