Skip to content

Commit

Permalink
Fix RAI image builds
Browse files Browse the repository at this point in the history
  • Loading branch information
imatiach-msft committed Nov 27, 2024
1 parent 57da35d commit 5f8c0c0
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ extra_config: environment.yaml
test:
pytest:
enabled: true
pip_requirements: tests/requirements.txt
conda_environment: tests/test_conda_env.yaml
tests_dir: tests
categories: ["Responsible AI"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
azure-ai-ml~=1.0.0
azure.identity==1.10.0
azureml-core~=1.53.0
azure-ai-ml==1.22.4
azure.identity==1.19.0
azureml-core>=1.58.0
azureml-mlflow
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from azure.ai.ml.entities import Environment, BuildContext
from azure.ai.ml import automl
from azure.ai.ml.constants import AssetTypes
from azure.identity import AzureCliCredential
from azure.identity import DefaultAzureCredential


BUILD_CONTEXT = Path("../context")
Expand Down Expand Up @@ -53,8 +53,10 @@ def test_responsibleai():
resource_group = os.environ.get("resource_group")
workspace_name = os.environ.get("workspace")

credential = DefaultAzureCredential()

ml_client = MLClient(
AzureCliCredential(), subscription_id, resource_group, workspace_name
credential, subscription_id, resource_group, workspace_name
)

env_name = "responsibleai"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
channels:
- conda-forge
- defaults
- anaconda
dependencies:
- python=3.12.0
- pip
- pip:
- -r requirements.txt
## Test requirements
- pytest
- tqdm
- azure-core
name: rai_test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ spec: spec.yaml
extra_config: environment.yaml
test:
pytest:
enabled: true
pip_requirements: tests/requirements.txt
enabled: true
conda_environment: tests/test_conda_env.yaml
tests_dir: tests
categories: ["Responsible AI"]
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from azure.ai.ml import command
from azure.ai.ml.operations._run_history_constants import JobStatus
from azure.ai.ml.entities import Environment, BuildContext
from azure.identity import AzureCliCredential
from azure.identity import DefaultAzureCredential

BUILD_CONTEXT = Path("../context")
JOB_SOURCE_CODE = "src"
Expand All @@ -25,8 +25,10 @@ def test_responsibleai_text():
resource_group = os.environ.get("resource_group")
workspace_name = os.environ.get("workspace")

credential = DefaultAzureCredential()

ml_client = MLClient(
AzureCliCredential(), subscription_id, resource_group, workspace_name
credential, subscription_id, resource_group, workspace_name
)

env_name = "responsibleai-text"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
channels:
- conda-forge
- defaults
- anaconda
dependencies:
- python=3.12.0
- pip
- pip:
- -r requirements.txt
## Test requirements
- pytest
- tqdm
- azure-core
name: rai_test
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ extra_config: environment.yaml
test:
pytest:
enabled: true
pip_requirements: tests/requirements.txt
conda_environment: tests/test_conda_env.yaml
tests_dir: tests
categories: ["Responsible AI"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,30 @@
from azure.ai.ml import MLClient
from azure.ai.ml import command
from azure.ai.ml.entities import Environment, BuildContext
from azure.identity import AzureCliCredential
from azure.identity import DefaultAzureCredential
from azure.core.credentials import AccessToken, TokenCredential
from datetime import datetime, timedelta

BUILD_CONTEXT = Path("../context")
JOB_SOURCE_CODE = "src"
TIMEOUT_MINUTES = os.environ.get("timeout_minutes", 60)
STD_LOG = Path("artifacts/user_logs/std_log.txt")


class CustomTokenCredential(TokenCredential):
"""Custom token credential class for runner."""

def __init__(self, token):
"""Initialize custom token credential class."""
self.token = token

def get_token(self, *scopes):
"""Get token."""
two_hours_from_now = datetime.now() + timedelta(hours=2)
utc_timestamp = int(two_hours_from_now.timestamp())
return AccessToken(self.token, utc_timestamp)


def test_responsibleai_vision():
"""Tests a sample job using responsibleai vision image as the environment."""
this_dir = Path(__file__).parent
Expand All @@ -24,8 +40,13 @@ def test_responsibleai_vision():
resource_group = os.environ.get("resource_group")
workspace_name = os.environ.get("workspace")

my_env = os.environ.copy()
if my_env['token']:
print("token is set in environment")
credential = CustomTokenCredential(my_env['token'])

ml_client = MLClient(
AzureCliCredential(), subscription_id, resource_group, workspace_name
credential, subscription_id, resource_group, workspace_name
)

env_name = "responsibleai-vision"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
channels:
- conda-forge
- defaults
- anaconda
dependencies:
- python=3.12.0
- pip
- pip:
- -r requirements.txt
## Test requirements
- pytest
- tqdm
- azure-core
name: rai_test

0 comments on commit 5f8c0c0

Please sign in to comment.