|
| 1 | +import oci |
| 2 | +import os |
| 3 | +import logging |
| 4 | + |
| 5 | +def get_auth(): |
| 6 | + PROFILE_NAME = 'DEFAULT' |
| 7 | + SECURITY_TOKEN_FILE_KEY = 'security_token_file' |
| 8 | + KEY_FILE_KEY = 'key_file' |
| 9 | + config = oci.config.from_file(profile_name=PROFILE_NAME) |
| 10 | + token_file = config[SECURITY_TOKEN_FILE_KEY] |
| 11 | + token = None |
| 12 | + with open(token_file, 'r') as f: |
| 13 | + token = f.read() |
| 14 | + private_key = oci.signer.load_private_key_from_file(config[KEY_FILE_KEY]) |
| 15 | + signer = oci.auth.signers.SecurityTokenSigner(token, private_key) |
| 16 | + return signer |
| 17 | + |
| 18 | +def get_datascience_client(): |
| 19 | + logger.info("Getting Resource Principal authenticated in datascience client") |
| 20 | + return oci.data_science.DataScienceClient({}, signer=get_auth(), service_endpoint=service_endpoint) |
| 21 | + |
| 22 | +# Set up logging |
| 23 | +_logger_name = 'MD' |
| 24 | +logger = logging.getLogger(_logger_name) |
| 25 | +logger.setLevel(logging.DEBUG) |
| 26 | +ch = logging.StreamHandler() |
| 27 | +ch.setLevel(logging.DEBUG) |
| 28 | +formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s', '%Y-%m-%d %H:%M:%S') |
| 29 | +ch.setFormatter(formatter) |
| 30 | +logger.addHandler(ch) |
| 31 | + |
| 32 | + |
| 33 | +service_endpoint = "https://datascience.us-ashburn-1.oci.oraclecloud.com" |
| 34 | + |
| 35 | +compartment_id = os.getenv('COMPARTMENT_ID', None) |
| 36 | +project_id = os.getenv('PROJECT_ID', None) |
| 37 | + |
| 38 | +logger.info("Setting up data-science client") |
| 39 | +data_science_client = get_datascience_client() |
| 40 | +logger.info("Data-science client set up successfully") |
| 41 | + |
| 42 | +data_science_client.create_model_deployment(create_model_deployment_details = { |
| 43 | + "displayName": "Diffusion Model deployment", |
| 44 | + "projectId": project_id, |
| 45 | + "compartmentId": compartment_id, |
| 46 | + "modelDeploymentConfigurationDetails": { |
| 47 | + "deploymentType": "SINGLE_MODEL", |
| 48 | + "modelConfigurationDetails": { |
| 49 | + "modelId": <MODEL_ID>, |
| 50 | + "instanceConfiguration": { |
| 51 | + "instanceShapeName": "VM.GPU.A10.2", |
| 52 | + "modelDeploymentInstanceShapeConfigDetails": None, |
| 53 | + "subnetId": "<SUBNET_ID>", |
| 54 | + "privateEndpointId": None |
| 55 | + }, |
| 56 | + "scalingPolicy": { |
| 57 | + "policyType": "FIXED_SIZE", |
| 58 | + "instanceCount": 1 |
| 59 | + }, |
| 60 | + "bandwidthMbps": 10, |
| 61 | + "maximumBandwidthMbps": 10 |
| 62 | + }, |
| 63 | + "streamConfigurationDetails": { |
| 64 | + "inputStreamIds": None, |
| 65 | + "outputStreamIds": None |
| 66 | + }, |
| 67 | + "environmentConfigurationDetails": { |
| 68 | + "environmentConfigurationType": "OCIR_CONTAINER", |
| 69 | + "image": <CONTAINER_ID>, |
| 70 | + "imageDigest": <DIGEST>, |
| 71 | + "cmd": None, |
| 72 | + "entrypoint": None, |
| 73 | + "serverPort": 3000, |
| 74 | + "healthCheckPort": 3000, |
| 75 | + "environmentConfigurationDetails": { |
| 76 | + "environmentConfigurationType": "OCIR_CONTAINER", |
| 77 | + "image": "<IMAGE_ID>", |
| 78 | + "imageDigest": "<DIGEST>", |
| 79 | + "cmd": None, |
| 80 | + "entrypoint": None, |
| 81 | + "serverPort": 3000, |
| 82 | + "healthCheckPort": 3000, |
| 83 | + "environmentVariables": { |
| 84 | + "MODEL_DEPLOY_HEALTH_ENDPOINT": "/readyz", |
| 85 | + "SHM_SIZE": "10g", |
| 86 | + "HF_TOKEN": "<HF_TOKEN_FOR_MODEL_DOWNLOAD>" # No need if using cataloged model |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + }, |
| 91 | + "categoryLogDetails": { |
| 92 | + "access": { |
| 93 | + "logId": <LOG_GROUP_ID>, |
| 94 | + "logGroupId": <LOG_ID> |
| 95 | + }, |
| 96 | + "predict": { |
| 97 | + "logId": <LOG_GROUP_ID>, |
| 98 | + "logGroupId": <LOG_ID> |
| 99 | + } |
| 100 | + }, |
| 101 | + "freeformTags": {}, |
| 102 | + "definedTags": {} |
| 103 | +}) |
0 commit comments