Use the test_functions testing system to complete the pre-submission self-check for RL training: from the testing tools bundled with the Demo package, to custom function tests, and finally to pre-submission smoke verification.
Demo package testing tools overview
The Demo package (Prepare data and code) comes with a complete set of function testing facilities:
Tool | Purpose |
|---|---|
| Test script: provides an independent, complete "registration → remote testing → log retrieval" closed loop for each of the four function types: Rollout / Reward / decorator Reward / Group Reward |
| Sample test inputs for the four function types (rollout_input / reward_input / reward_decorator_input / group_reward_input); see the detailed field descriptions below |
| A collection of local testing and query commands (equivalent CLI entry points) |
| Script for starting the function service locally (usable for Reward functions; the classpath of the Rollout version points to a nonexistent module and fails to start — start it with the environment variable method instead) |
Test the Demo functions
Run test_functions.py
In the project root directory (the DASHSCOPE_API_KEY environment variable must be set; see environment preparation), run:
__main__); to test the other functions, uncomment the corresponding lines or call them yourself:
Test input field reference
Top-level fields of the four test inputs:
Field | Applicable functions | Description |
|---|---|---|
| All | Function type: rollout / reward / group_reward (for decorator Reward, enter reward) |
| Rollout | List of conversation messages; during training it comes from the messages field of each row in the dataset |
| All | Reference answer, readable by scoring logic (for the value flow during training, see the RewardInput field description in the developer guide) |
| Rollout | Pass-through content of the dataset rollout_extra field; custom business data |
| Rollout | Sampling parameters: temperature, max_tokens, max_turns, timeout |
| Rollout | Inference endpoints: model_name, base_url, api_key (automatically injected by the framework during training; you must fill in a usable endpoint when testing. For example values, see Development guide — Test input format) |
| Reward class | Agent outputs to be scored: messages, rollout_extra, rollout_metrics, reward_score |
| Group Reward | An array of multiple outputs for the same sample (plural), distinguished from the single agent_output |
| Optional | Framework metadata (job_id, sample_id, etc.); can be omitted or filled with placeholder values during testing |
| Rollout optional | List of available tools; pass null if there are no tools |
| Optional | Any custom additional fields, passed through as-is by the framework |
Expected return values
Actual returns from the four demo test inputs (consistent between the local service and cloud test_functions on both ends):
Test input | Function under test | Expected return |
|---|---|---|
rollout_input.json | DemoRolloutProcessor | status=success, reward_score=0.95 (Rollout embeds the scoring logic; the test input uses a placeholder inference endpoint and does not actually call inference) |
reward_input.json | DemoRewardProcessor | status=success, reward_score=0.0, reward_metrics contains test1/test2 |
reward_decorator_input.json | SafetyProcessor (decorator) | status=success, reward_score=0.85 (weighted aggregation result of sub-dimensions) |
group_reward_input.json | DemoGroupRewardProcessor | status=success, the rewards array length matches agent_outputs, with a single value of 0.5 |
Test custom functions
Once all four types of demo function tests pass, the environment and pipeline have been verified. Replace the classpath with your custom function and the test input with your own constructed cases, then follow the same test path. Place the custom function source code in the project functions/ directory (the classpath is the module path relative to the project root, e.g., functions/reward/my_reward.py corresponds to functions.reward.my_reward.MyRewardProcessor); during registration, the SDK packages the project code and requirements.txt for upload, so all dependencies must be listed in requirements.txt.
Construct test cases
Construct 3 test inputs for your custom scoring logic whose expected scores can be manually computed — the expected scores are determined by your custom scoring logic:
Test case | Construction method | Expected score |
|---|---|---|
Full-score sample | Put a response in messages that is guaranteed to hit the scoring conditions (contains the correct answer, meets the format), and fill ground_truth with the corresponding ground truth | The full score of the scoring logic (for example, 1.0) |
Zero-score sample | Put a response in messages that is guaranteed to miss (wrong answer, format mismatch) | 0.0 |
Boundary sample | The forms most likely to be misjudged: empty messages, extremely long responses, partially matching answers, different casing | Based on the defined boundary behaviors (if a boundary behavior is undefined, first add its definition in the scoring logic) |
my_reward_test_full.json, my_reward_test_zero.json, my_reward_test_edge.json). Reward class input template (see Test input field details for the field structure):
Local service verification
Before remote testing, first run your custom function locally as a service and verify the three cases (see Test input field details for the Rollout input structure). The service takes a few seconds to start; if you get connection refused, wait briefly and retry:
status for all three inputs is success, and each reward_score in reward matches the expected score; any mismatch indicates a defect in the scoring logic, which must be fixed before proceeding to remote testing. A score of 0 is a valid result — TaskStatus returns SUCCESS; only transient errors (timeout, network jitter) return FAILED (see Development guide — TaskStatus determination for scoring scenarios for details).
To test the rollout function locally, replace model_resource in the test input with an available inference endpoint and API Key: you must use an API Key that supports inference calls (created on the API-KEY page of the Model Studio console, with the sk- prefix). If the credentials used for the training submission do not support inference calls, a 401 (Incorrect API key) will be returned here. During training, there is no need to configure an inference endpoint yourself — the endpoint and key are automatically injected at runtime by the training framework (see RolloutInput key fields).
At the reward logic design level, two self-checks are recommended before submission: self-check before writing the Reward function (10 questions); and prepare a gold set of 50-200 manually annotated entries (gold-standard answer set) for the reward consistency self-check. Also keep the field names in reward_metrics stable — renaming them will break the continuity of the metric curves in the console.
Remote testing of custom functions
Register the functions to the cloud and execute them in a real FC container — differences between the local and container environments (dependency installation, packaging paths, runtime behavior) can only be exposed by this step (the DASHSCOPE_API_KEY environment variable must be set, see environment preparation). The first registration includes building the function dependency layer, which takes about 1-3 minutes with no output during that period — this is normal.
register_functions call and each submission registers new function entities that accumulate in your account (the local project root directory will generate start.sh and temporary packaging files, which can be ignored or deleted). Function instances created by tests can be viewed and managed on the FC page of the console.
Pass criteria: the return results of the three test cases match the local verification results item by item. If they do not match, first check requirements.txt (the container installs dependencies based on it), then locate the issue through the instance logs (see log query) — if a function instance fails during the startup phase, logs may not have been generated yet (an empty list is returned); in that case, rely on the error message in the test_functions return result.
test_functions details
SDK signature
Parameter | Description |
|---|---|
| Function instance ID (ro-ins- / rw-ins- / grw-ins- prefix), from the register_functions return value, or from the CLI registration command output |
| FunctionType enum: ROLLOUT / REWARD / GROUP_REWARD; note that the SDK parameter name is functype (the CLI parameter name is --type) |
| Test input, of dict type (loaded from a JSON file via json.load, or constructed by yourself according to the field details) |
| Optional; when True, the return result includes instance logs |
register_functions returns a 6-tuple (lists of entity and instance IDs for the three types rollout/reward/group_reward; unregistered types are empty lists); for the semantics of lazy_load values and a complete unpacking example, see development guide — register functions.
CLI comparison
dashscope prefix (applicable to dashscope 2.0.x). If you have installed dashscope 2.1.0 or later, use the dashscope1 prefix for all CLI commands in this document (e.g., dashscope1 rl get "ft-xxx"); the parameters remain unchanged.Actions | Command |
|---|---|
Test functions |
|
Upload data |
|
Query task |
|
Log query
When a test fails, pull the function instance logs (query_all_function_instance_logs): the logs take about 30 seconds to become ready (the test function in test_functions.py has this step built in); if a function instance fails during the startup phase, logs may not have been generated yet (an empty list is returned); in that case, rely on the error message in the test_functions return result. For how to call it and a complete example, see development guide — remote testing.
Submission smoke test
After all function tests pass, make one real submission to confirm the server accepts all the configurations, then cancel it immediately. Apart from the two changes below, the parameters are exactly the same as a formal submission: set batch_size to 8 and replace the data with a slimmed-down file of about 10 rows (for the data format, see data format). For the complete parameter syntax, see configuration — one-step completion (run). Billing basis: taking 24 pay-as-you-go instances as an example, the cost is about 984 CNY/hour (the minimum billing granularity for pay-as-you-go is 1 minute, i.e., about 16 CNY/minute); keeping the time from submission to cancellation within 1 minute costs about 16 CNY minimum, and every additional minute of delay in canceling adds about 16 CNY.
runreturns normally (status_codeis 200) andjob_idis non-empty — the full pipeline of function registration, data upload, and parameter validation is accepted by the server- In the
hyper_parametersechoed byget, fields not explicitly filled in are automatically populated by the server (such asenable_thinking,max_off_policy_strategy, etc.) — verify that the populated values do not conflict with your expectations - Verify two resource configurations:
mtu_capacity= nnodes_rollout × n_gpus_rollout + nnodes_training × n_gpus_training (Distributed parallelism and resources); function Runtime memory_size ≥ 4096 and disk_size ≥ 512 (Runtime resource configuration) - Smoke test data volume works with batch_size: a small amount of data (such as 10 rows) is enough; the data volume is then below the formal
batch_size, sobatch_sizemust be lowered to no more than the number of data rows (the server requires a value range of 8~2048, see the Batch and sampling parameter table); setting it to 8 for smoke tests is sufficient
Cost and duration of the first training
This section provides the acceptance criteria for the first training after submission (not a pre-submission step): actually execute a training run with the minimum data volume + 1 epoch to confirm that the first step produces trajectories and metrics, and that Reward has gradients (not constantly 0 or 1).
Expected duration (based on actual measurements with demo streamlined data of 128 entries, batch_size=64, and 24 postpaid instances):
- Approximately 1 minute from submission to entering RUNNING (when resource queuing is normal)
- Producing trajectories and metrics for the first step typically takes more than 30 minutes (the first step must complete all Rollout sampling; it is normal to see no output within 25 minutes in actual tests, so do not prematurely determine failure)
- Approximately 1 hour 45 minutes for a complete run to SUCCEEDED
- Stopping at the point where "first step metrics appear and are normal" typically costs several hundred CNY; a complete run costs approximately 1,000+ CNY
- Cancelling a task before training begins incurs no charge (measured usage is 0); after training starts, billing is based on actual usage, and the
usagefield in task details displays the cumulative usage - Full training cost estimation:
Instances × estimated duration × hourly unit price—the estimated duration can be roughly calculated as "data volume / batch_size × time per step × n_epochs", or by proportionally scaling up the measured duration of a streamlined first run
critic/rewards/mean and actor/entropy), see Observability configuration — key metrics quick reference. For concrete practices (lean datasets, n_epochs=1), see Reinforcement learning training overview — getting started tips.
After completing the self-check process, if only some items are changed, there is no need to repeat all self-check items:
- Changing data (new dataset or data expansion) → simply run a smoke test before resubmitting
- Modifying function code → restart from local service verification
- Only adjusting hyperparameters or resource configuration → restart from the submission smoke test (approximately 16 CNY to verify that the new configuration is accepted by the server)
Common error quick reference
This section covers high-frequency errors from testing to submission. For error attribution after a task has entered training (first step crash, sampling timeout, garbled output, etc.), see Observability configuration — troubleshooting decision tree.
Stage | Error message | Cause analysis | Resolution |
|---|---|---|---|
Local service | 401 Incorrect API key (Rollout live test) | The API key in use does not support inference calls | Switch to an sk- prefixed inference key created in the Model Studio console (see local service verification) |
Remote testing |
| Windows packaging compatibility issue (the CLI and SDK share the same packaging pipeline, and the issue reproduces on both sides; the | Running in a WSL or Linux environment completely avoids this issue (if WSL is not installed, it can be installed via |
Remote testing | ModuleNotFoundError (in instance logs) | requirements.txt is missing dependencies, or the package structure cannot be resolved inside the container | Complete requirements.txt and go back to the local service to reproduce |
Submit | ValidationError: extra inputs are not permitted (e.g. weight) | This parameter does not belong to the current component type (weight is a field of RewardFunctionComponent, not on AgenticRLFunctionComponent) | Verify the component type and field ownership; step-by-step submission does not include weight |
Submit | [3005] Job submission failed: TypeError(unexpected keyword argument) | Called a non-existent method parameter (for example, run(lazy_load=...) or submit_job(training_file_ids=...)) | For the dataset, pass in all three parameters in full with datasets=[Dataset(type=DatasetsType.VALIDATION, data_source_type=DataSourceType.FILE_ID, file_id=...)]; for other parameters, follow the examples on this page and in Submit training tasks |
Submit | [400] InvalidParameter:batch_size need to be in range [8, 2048] | batch_size is outside the range allowed by the server (during a smoke test the data volume is small, so batch_size must be adjusted to 8) | Adjust batch_size to 8~2048; for smoke test scenarios, pair it with a small data volume |
Submit | [1002] I/O error: Failed to load from dict | YAML dialect error (unsupported top-level key or field type) | Use the job.yaml template structure from the YAML configuration |
Submit | TypeError: object FineTune can't be used in 'await' expression | Misusing await on synchronous methods (submit_job / get / cancel / list / logs) | Remove await; note that run/register_functions/upload_datasets/test_functions are async, while job management methods are synchronous |
Next steps
- After all self-checks pass, submit the formal training → Reinforcement learning training configuration — submission and configuration
- Function development details and design philosophy → Reinforcement learning development guide
- Metric observation and error attribution after training starts → Observability configuration and metrics reference for reinforcement learning
- Review the end-to-end process → Reinforcement learning training overview