A colleague registered a component named prep_data in your Azure Machine Learning workspace and registers a new version of it every few weeks. You are building a pipeline in a notebook where ml_client is already connected to the same workspace.
Requirements:
- You do not have the component's YAML file or script on your machine.
- The pipeline must use the newest registered version of
prep_datawithout editing your code each time a new version is registered. - You must not register any new component versions in the workspace.
Which code should you use to obtain the component for your pipeline?
Components that are already registered in a workspace, including ones shared by teammates, can be loaded with ml_client.components.get(). Passing only the name loads the latest registered version when the call executes. Pinning a version prevents selection of newer versions, and loading local YAML requires an unavailable file. The create_or_update method registers a supplied definition rather than retrieving the latest registered component.
- Not correct:
prep = ml_client.components.get(name="prep_data", version="1"). This loads the registered component from the workspace, but it is pinned to version 1, so new versions would require a code change. - Correct:
prep = ml_client.components.get(name="prep_data"). Getting a registered component by name only loads its latest version from the workspace, so no local files are needed and nothing new is registered. - Not correct:
prep = load_component(source="./prep.yml"). load_component reads a local YAML definition, which you do not have. - Not correct:
prep = ml_client.components.create_or_update(prep_data). create_or_update registers a supplied component definition rather than retrieving the latest registered version ofprep_data.