Skip to content

ランタイムパラメーターの定義

Define environment variables to supply different values to custom model code at runtime by including them as runtime parameters, making your custom model easier to reuse. Define runtime parameters in code or through the UI:

  • Code: Provide a model-metadata.yaml file in the model artifact. Define this file before uploading a model to Workshop, or use the template available in Workshop through a custom model's Files > Create dropdown. The YAML structure is defined on this page.

  • UI: Define runtime parameters in the Runtime parameters section of the custom model in Workshop. For more information, see the Create custom models documentation.

Runtime parameters are injected into containers in two ways:

  1. As standard environment variables without prefixes or JSON parsing for simple types (so you can use os.getenv to access environment variables without the datarobot-drum library).
  2. For backward compatibility also in the legacy prefixed (MLOPS_RUNTIME_PARAM_*) and JSONified format.

Parameters created via the Workshop UI persist and merge when you upload new code versions, ensuring a seamless development flow.

Runtime parameter considerations

The system uses a blocklist of reserved patterns (e.g., DRUM_*, MLOPS_*, KUBERNETES_*), managed in the dynamic configuration. Matching supports the * wildcard (not full regular expression syntax). Reserved names aren't blocked entirely: if a runtime parameter uses a reserved name, the UI displays a warning. How the variable is exposed depends on the context:

  • Custom models: Only in prefixed (MLOPS_RUNTIME_PARAM_*) and JSONified format—not as a raw (unprefixed) environment variable, to prevent system conflicts.
  • Custom apps: Prefixed, but values are not packed into a JSON payload (except for credentials).
  • Custom jobs: No prefix and no JSON payload (except for credential types); the variable is available as a raw environment variable.

For credential-type runtime parameters, the system automatically unpacks JSON fields into separate environment variables rather than a single string. For example, a credential named MAIN_AWS_CREDENTIAL with the following JSON structure:

{"awsAccessKeyId": "<your-key-id>", "awsSecretAccessKey": "<your-access-key>"} 

is unpacked into the following environment variables, combining the parameter name + JSON key, in uppercase:

MAIN_AWS_CREDENTIAL_AWS_ACCESS_KEY_ID="<your-key-id>"
MAIN_AWS_CREDENTIAL_AWS_SECRET_ACCESS_KEY="<your-access-key>" 

For single-field credential types (for example, api_token, bearer, or gcp), the injected environment variable uses the bare runtime parameter name (MY_CRED), not the parameter name plus the credential field name (for example, not MY_CRED_API_TOKEN). Multi-field JSON-encoded runtime parameter variables (for example, MLOPS_RUNTIME_PARAMETERS_OPEN_AI_API) are unchanged; only the flat variable for a single-field secret uses the bare parameter name.

Access runtime parameters in containers

For programmatic access to runtime parameters in containers, use DataRobotAppFrameworkBaseSettings as documented in the SDK API reference.

To change runtime parameter values for an existing deployment, deactivate the deployment, update the values in the deployment's Settings > Resources tab, and then reactivate the deployment. For details, see Configure deployment resource settings.

Runtime parameter definitions

モデルメタデータを介してカスタムモデルにランタイムパラメーターを追加することで、カスタムモデルのコードを再利用しやすくします。 ランタイムパラメーターを定義するには、model-metadata.yamlに以下の runtimeParameterDefinitionsを追加します。

キー 説明
fieldName ランタイムパラメーターの名前を定義します。
type ランタイムパラメーターに含まれるデータ型(stringbooleannumericcredentialdeployment)を定義します。
defaultValue (オプション)ランタイムパラメーターのデフォルト値を設定します。 資格情報タイプのパラメーターでは、defaultValueを使用して、既存の資格情報をその資格情報IDで参照します。 他のタイプでは、デフォルトの文字列値、ブール値、または数値を設定します。 defaultValueを指定せずにランタイムパラメーターを定義した場合、デフォルト値はNoneです。
minValue (オプション)numericランタイムパラメーターには、ランタイムパラメーターで使用可能な最小数値を設定します。
maxValue (オプション)numericランタイムパラメーターには、ランタイムパラメーターで使用可能な最大数値を設定します。
credentialType (オプション)credentialランタイムパラメーターの場合、パラメーターに含める資格情報のタイプを設定します。
allowEmpty (オプション)ランタイムパラメーターに空のフィールドポリシーを設定します。
  • True:(デフォルト)空のランタイムパラメーターを許可します。
  • False:デプロイ前にランタイムパラメーターの値を指定するよう徹底します。
description (オプション)ランタイムパラメーターの目的または内容の説明を入力します。

DataRobotで予約されたランタイムパラメーター

DataRobotでは、カスタムモデルの設定用に、以下のランタイムパラメーターが予約されています。

ランタイムパラメーター タイプ 説明
CUSTOM_MODEL_WORKERS 数値 各レプリカは、設定された数の同時プロセスを処理できます。 このオプションは、主に生成AIのユースケースで、プロセスセーフなカスタムモデルを対象としています(プロセスセーフモデルの詳細については、以下の注を参照してください)。 レプリカごとに許可する適切な同時プロセス数を決定するには、カスタムモデルでリクエスト数とレスポンス時間の中央値を監視します。 カスタムモデルでのレスポンス時間の中央値は、LLMでのレスポンス時間の中央値に近い必要があります。 カスタムモデルのレスポンス時間がLLMのレスポンス時間を超えた場合、同時プロセスの数を増やすのをやめ、代わりにレプリカの数を増やしてください。
デフォルト値1
最大値40

カスタムモデルプロセスの安全性

CUSTOM_MODEL_WORKERSを有効にして設定する場合は、モデルがプロセスセーフであることを確認してください。これにより、複数の独立したプロセスが、競合を引き起こすことなく、共有リソースと安全にやり取りできるようになります。 この設定は、リソース効率を向上させるためにカスタムモデルで一般的に使用するためのものではありません。 この方法でCPUリソースを利用するメリットがあるのは、I/Oバウンドタスクを持つプロセスセーフなカスタムモデル(プロキシモデルなど)だけです。

カスタムモデルのメタデータを定義する

Before you define runtimeParameterDefinitions in model-metadata.yaml, define the custom model metadata required for the target type. For binary and multiclass models, that includes an inferenceModel block (targetName and class labels; for multiclass, classLabels).

Example: model-metadata.yaml for a binary model
name: binary-example
targetType: binary
type: inference
inferenceModel:
  targetName: target
  positiveClassLabel: "1"
  negativeClassLabel: "0" 
Example: model-metadata.yaml for a regression model
name: regression-example
targetType: regression
type: inference 
Example: model-metadata.yaml for a text generation model
name: textgeneration-example
targetType: textgeneration
type: inference 
Example: model-metadata.yaml for an anomaly detection model
name: anomaly-example
targetType: anomaly
type: inference 
Example: model-metadata.yaml for an unstructured model
name: unstructured-example
targetType: unstructured
type: inference 
Example: model-metadata.yaml for a multiclass model
name: multiclass-example
targetType: multiclass
type: inference
inferenceModel:
  targetName: class
  classLabels:
    - class_a
    - class_b
    - class_c 

次に、モデル情報の下にruntimeParameterDefinitionsを指定できます。

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

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.

- fieldName: runtime_parameter_for_connected_deployment
  type: deployment
  description: A runtime parameter defined to accept the deployment ID of another deployment to connect to the deployed custom model. 

ランタイムパラメーターによる資格情報の提供

credentialランタイムパラメータータイプは、DataRobot REST APIで使用可能な任意のcredentialType値をサポートします。 At runtime, credential payloads are also reflected as environment variables in the container; see the runtime parameter considerations for naming rules (single-field types such as api_token, bearer, and gcp use the bare parameter name; multi-field types such as basic and s3 use suffixed names per field).

資格情報は、以下の2つの方法で指定できます。

  • 既存の資格情報を参照する:DataRobotの資格情報の管理セクションで定義された資格情報を参照するには、資格情報IDをdefaultValueとして使用します。

  • 資格情報の値を直接指定する:(通常、DRUMを用いたローカル開発時に使用される)ランタイムパラメーターを定義する際には、完全な資格情報構造を含めます。

資格情報のタイプ

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

既存の資格情報を参照する

既存の資格情報を参照するには、defaultValueを資格情報IDに設定します。

Example: Reference an existing credential
- fieldName: my_api_token
  type: credential
  credentialType: api_token
  allowEmpty: false
  defaultValue: <credential-id>
  description: A runtime parameter referencing an existing API token credential. 

資格情報の要件

既存の資格情報を参照する場合、その資格情報は、カスタムモデルを登録する前に資格情報管理セクションに存在し、ランタイムパラメーター定義で指定されたcredentialTypeと一致し、defaultValueとして使用される資格情報IDと一致する必要があります。

資格情報の値を直接指定する

必要な資格情報は、以下の例に示すように、credentialTypeによって異なります。

資格情報タイプ
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セットをオーバーライドします。

Example: .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オプションはランタイムパラメーター値を含むファイルを指定します。

Example: --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モジュールをインポートします。

Example: 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