V1Param
polyaxon._flow.params.params.V1Param()Params provide values to declared inputs/outputs or to the operation context.
Params can be passed in several ways
- literal values that the user sets manually.
- a reference from a previous run, in which case Polyaxon will validate during the compilation time if the user who initiated the run has access to that organization/project/run.
- a reference from an upstream operation in the context of a DAG.
Params matching the inputs/outputs
declared by the component
are validated against those declarations. Other params follow the strictParams
policy described below.
- Args:
- value: any
- ref: str, optional
- context_only: bool, optional
- connection: str, optional
- to_init: bool, optional
- to_env: str, optional
YAML usage
Polyaxon supports two syntaxes for defining params: short-form and full-form.
Short-form syntax
N.B: Requires Polyaxon CLI version
>= 2.13
For simple literal values, you can use the concise short-form syntax:
params:
loss: MeanSquaredError
preprocess: true
accuracy: 0.1
batch_size: 32
layers: [64, 128, 256]
config:
optimizer: adam
lr: 0.001Full-form syntax
The full-form syntax is required when using advanced features like ref, toInit, toEnv, connection, or contextOnly:
params:
loss:
value: MeanSquaredError
preprocess:
value: true
accuracy:
value: 0.1
outputs_path:
ref: ops.upstream-job1
value: outputs.images_pathYou can mix both syntaxes in the same params section:
params:
# Short-form for simple values
batch_size: 32
learning_rate: 0.001
# Full-form when using refs or other options
upstream_output:
ref: ops.training
value: outputs.model_path
data_path:
value: /data/train
toInit: truePython usage
from polyaxon.schemas import V1Param
params = {
"loss": V1Param(value="MeanSquaredError"),
"preprocess": V1Param(value=True),
"accuracy": V1Param(value=0.1),
"outputs-path": V1Param(ref="ops.upstream_job1", value="outputs.images_path")
}Undeclared params
Note: The permissive default and
strictParamsare available in Polyaxon 2.18+. Use CLI and server versions that support this policy, and an SDK version that supports the field when submitting it through an SDK. Older validators may reject undeclared params orstrictParams. Polyaxonfileversionis optional in 2.18+.
By default, a param without a matching input/output declaration becomes a context value. This applies whether the component has no IO, empty IO lists, or declared IO alongside extra params. Required values, defaults, types, and constraints on declared IO still apply.
version: 1.1
kind: operation
params:
count: 3
message: hello
component:
inputs:
- name: count
type: int
run:
kind: job
container:
image: busybox:1.36
command: [sh, '-c']
args: ['echo "count={{ count }} message={{ message }}"']This operation prints count=3 message=hello. The compiled operation keeps
count in inputs and message in contexts; it does not create an input
declaration for message. After resolution, both values are recorded in
Run.inputs:{"count": 3, "message": "hello"}.
Explicit and inferred context values are recorded the same way, including resolved references. Declared output params keep their output recording behavior. Context inference does not export environment variables or create outputs or artifacts.
Strict mode
Set strictParams: true on a component or operation to reject undeclared params
unless they explicitly set contextOnly: true. This catches misspelled param
names that the permissive default would accept as context values.
To make the example above strict, keep its component and use these operation
- fields:
strictParams: true
params:
count: 3
message:
value: hello
contextOnly: trueAfter presets and overrides are applied, strict mode is enabled if either the
component or the operation enables it. An operation with strictParams: false
cannot relax a strict component. Omitting the field preserves the existing
policy during patching; it does not override it with false.
CLI and Python overrides
In Polyaxon 2.18+, polyaxon run and polyaxon check accept --strict-params
and --no-strict-params to set the operation policy:
polyaxon check -f polyaxonfile.yaml --strict-params
polyaxon run -f polyaxonfile.yaml --no-strict-params -P message=helloLeaving both flags out preserves the specification's policy. A strict component
remains strict with --no-strict-params. The flags apply after every -f file
and override a strictParams set by preset files.
Python callers can pass strict_params=True, False, or None to
check_polyaxonfile with the same behavior. CLI -P values start as strings;
declared IO controls their type conversion.
Fields
value
The value to pass, if no ref is passed then it corresponds to a literal value,
and will be validated eagerly.
Otherwise it will be a future validation during the compilation time.
params:
loss:
value: MeanSquaredError
learning_rate:
value: 0.001The value could be coming from the context, for example:
params:
current_project:
value: {{globals.project_name}}
current_run:
value: {{globals.uuid}}
fully_resolved_artifacts_path:
value: {{globals.run_artifacts_path}}
fully_resolved_artifacts_outputs_path:
value: {{globals.run_outputs_path}}Resolving values from the IO (inputs/outputs) of the reference:
specific_input:
value: {{inputs.input_name}}
specific_outputs:
value: {{outputs.output_name}}
all_inputs_dict:
value: {{inputs}}
all_outputs_dict:
value: {{outputs}}
specific_input:
value: {{inputs.input_name}}
specific_outputs:
value: {{outputs.output_name}}Resolving paths from the artifacts and lineages of the reference:
run_artifacts_subpath_without_context:
value: {{artifacts}}
run_artifacts_outputs_subpath_without_context:
value: {{artifacts.outputs}}
run_path_of_lineage:
value: {{artifacts.lineage_name}}
run_tensorboard_path_from_lineage:
value: {{artifacts.tensorboard}}
run_tensorboard_path_from_lineage:
value: {{artifacts.tensorboard}}Resolving artifacts manually from the reference based on the ArtifactsType
files_and_dirs:
value:
- files: ["subpath/file1", "another/subpath/file2.ext"]
- dirs: ["subpath/dir1", "another/subpath/dir2"]Note: the difference between using
artifacts.lineage_nameand ArtifactsType, is that the former will only expose the path based on any lineage logged during the runtime, the later is a manual way of selecting specific files and dirs.
ref
Ref corresponds to a reference of an object.
A reference could be a previous run in the database or an operation in DAG that has not been executed yet.
params:
loss:
value: outputs.loss
ref: ops.upstream-job-1params:
loss:
value: outputs.loss
ref: runs.fcc462d764104eb698d3cca509f34154contextOnly
Explicitly allow an undeclared param as a context value, including in strict
mode. A matching input/output declaration always takes precedence: the value
is validated and bound to that IO, even with contextOnly: true.
In Polyaxon 2.18+, an omitted or null flag follows the effective strictParams
policy. An explicit false requires a matching input/output declaration in
either mode. For example, this param requires a declared count IO:
params:
count:
value: 3
contextOnly: falseTo pass an undeclared context value in strict mode:
params:
convolutions:
contextOnly: true
value:
conv1:
kernels: [32, 32]
size: [2, 2]
strides: [1, 1]
conv2:
kernels: [64, 64]
size: [2, 2]
strides: [1, 1]Without a matching IO declaration, convolutions is available in the context.
For example, use {{ convolutions.conv1 }} in the specification.
connection
A connection to use with the parameter. if the initial Input/Output definition has a predefined connection and this connection is provided, it will override the that value and will be added to the context.
toInit
if True the param will be converted to an init container.
For example, to initialize some artifacts without using the
init section, you can use toInit to turn an artifacts value
or git value to an init container:
files_and_dirs:
toInit: true
value:
- files: ["subpath/file1", "another/subpath/file2.ext"]
- dirs: ["subpath/dir1", "another/subpath/dir2"]toEnv
N.B: Requires Polyaxon CLI and Polyaxon Agent/CE version
>= 1.12
If passed, it will be converted automatically to an environment variable.
param1:
toEnv: ENV_VAR_NAME_TO_USE
value: "some value"