Skip to content

アプリケーション内で をクリックすると、お使いのDataRobotバージョンに関する全プラットフォームドキュメントにアクセスできます。

Define custom model runtime parameters

Add runtime parameters to a custom model through the model metadata, making your custom model code easier to reuse. ランタイムパラメーターを定義するには、model-metadata.yamlに以下の runtimeParameterDefinitionsを追加します。

キー 説明
fieldName ランタイムパラメーターの名前を定義します。
type ランタイムパラメーターに含まれるデータ型(stringbooleannumericcredential)を定義します。
defaultValue (オプション)ランタイムパラメーターのデフォルト文字列値(credentialタイプはデフォルト値をサポートしません)
minValue (オプション)numericランタイムパラメーターには、ランタイムパラメーターで使用可能な最小数値を設定します。
maxValue (オプション)numericランタイムパラメーターには、ランタイムパラメーターで使用可能な最大数値を設定します。
credentialType (Optional) For credential runtime parameters, set the type of credentials the parameter should contain.
allowEmpty (オプション)ランタイムパラメーターに空のフィールドポリシーを設定します。
  • True:(デフォルト)空のランタイムパラメーターを許可します。
  • False:デプロイ前にランタイムパラメーターの値を指定するよう徹底します。
description (オプション)ランタイムパラメーターの目的または内容の説明

備考

defaultValueを指定せずにランタイムパラメーターを定義した場合、デフォルト値はNoneです。

Example: model-metadata.yaml
name: runtime-parameter-example
type: inference
targetType: regression

runtimeParameterDefinitions:
- fieldName: my_first_runtime_parameter
  type: string
  description: My first runtime parameter.

- fieldName: runtime_parameter_with_default_value
  type: string
  defaultValue: Default
  description: A string-type runtime parameter with a default value.

- fieldName: runtime_parameter_boolean
  type: boolean
  defaultValue: true
  description: A boolean-type runtime parameter with a default value of true.

- fieldname: runtime_parameter_numeric
  type: numeric
  defaultValue: 0
  minValue: -100
  maxValue: 100
  description: A boolean-type runtime parameter with a default value of 0, a minimum value of -100, and a maximum value of 100.

- fieldName: runtime_parameter_for_credentials
  type: credential
  credentialType: basic
  allowEmpty: false
  description: A runtime parameter containing a dictionary of credentials; credentials must be provided before registering the custom model.

Provide credentials through runtime parameters

credentialランタイムパラメータータイプは、DataRobot REST APIで使用可能な任意のcredentialType値をサポートします。 以下の例に示すように、含まれる資格情報はcredentialTypeに依存します。

備考

サポートされている資格情報タイプの詳細については、 資格情報のAPIリファレンスドキュメントを参照してください。

Credential Type Example
basic
basic:
  credentialType: basic
  description: string
  name: string
  password: string
  user: string
        
azure
azure:
  credentialType: azure
  description: string
  name: string
  azureConnectionString: string
        
gcp
gcp:
  credentialType: gcp
  description: string
  name: string
  gcpKey: string
        
s3
s3:
  credentialType: s3
  description: string
  name: string
  awsAccessKeyId: string
  awsSecretAccessKey: string
  awsSessionToken: string
        
api_token
api_token:
  credentialType: api_token
  apiToken: string
  name: string
        

ローカル開発中にオーバーライド値を指定する

DRUMを使用したローカル開発では、ランタイムパラメーターの値を含む.yamlファイルを指定できます。 ここで定義された値は、model-metadata.yamlでのdefaultValueセットをオーバーライドします。

例: .runtime-parameters.yaml
my_first_runtime_parameter: Hello, world.
runtime_parameter_with_default_value: Override the default value.
runtime_parameter_for_credentials:
  credentialType: basic
  name: credentials
  password: password1
  user: user1 

DRUMを使用する場合、新しい--runtime-params-fileオプションはランタイムパラメーター値を含むファイルを指定します。

例:: --runtime-params-file
drum score --runtime-params-file .runtime-parameters.yaml --code-dir model_templates/python3_sklearn --target-type regression --input tests/testdata/juniors_3_year_stats_regression.csv 

カスタムコードでのランタイムパラメーターのインポートと使用

ランタイムパラメーターをインポートしてアクセスするには、custom.pyでコードにRuntimeParametersモジュールをインポートします。

例: custom.py
from datarobot_drum import RuntimeParameters


def mask(value, visible=3):
    return value[:visible] + ("*" * len(value[visible:]))


def transform(data, model):
    print("Loading the following Runtime Parameters:")
    parameter1 = RuntimeParameters.get("my_first_runtime_parameter")
    parameter2 = RuntimeParameters.get("runtime_parameter_with_default_value")
    print(f"\tParameter 1: {parameter1}")
    print(f"\tParameter 2: {parameter2}")

    credentials = RuntimeParameters.get("runtime_parameter_for_credentials")
    if credentials is not None:
        credential_type = credentials.pop("credentialType")
        print(
            f"\tCredentials (type={credential_type}): "
            + str({k: mask(v) for k, v in credentials.items()})
        )
    else:
        print("No credential data set")
    return data 

更新しました April 8, 2024