Repository navigation
Fix mtrl eval hyperparameter names #6595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| ) | ||
| from sagemaker.core.telemetry.telemetry_logging import _telemetry_emitter, TelemetryParamType | ||
| from sagemaker.train.common_utils.telemetry_params import BASE_EVALUATOR_TELEMETRY_PARAMS | ||
| from sagemaker.train.recipe_resolver import flatten_resolved_recipe | ||
| from sagemaker.core.telemetry.constants import Feature | ||
|
|
||
| if TYPE_CHECKING: | ||
|
|
@@ -160,6 +161,7 @@ class MultiTurnRLEvaluator(BaseEvaluator): | |
| _agent_arn_resolved: Optional[str] = None | ||
| _agent_kind: Optional[str] = None # "bedrock" | "lambda" | ||
| _hyperparameters: Optional[Any] = None | ||
| _hp_defaults: Optional[Dict[str, str]] = None | ||
|
|
||
| # --- Validators ------------------------------------------------------ | ||
|
|
||
|
|
@@ -315,9 +317,14 @@ def hyperparameters(self): | |
| ``get_info()``, and attribute-style read/write access with | ||
| hub-sourced validation (type + range). | ||
|
|
||
| Supported parameters (sourced from the AgentRFT evaluation recipe): | ||
| ``eval_group_size``, ``sampling_temperature``, ``top_p``, | ||
| ``max_tokens``, ``pass_k_values``, ``success_threshold``. | ||
| Parameter names and ranges come from the hub recipe; call | ||
| ``get_info()`` to list them. | ||
|
|
||
| Example: | ||
|
|
||
| .. code:: python | ||
|
|
||
| evaluator.hyperparameters.sampling_max_tokens = 8192 | ||
|
|
||
| Raises: | ||
| ValueError: If the base model name is not available or the hub | ||
|
|
@@ -365,8 +372,32 @@ def hyperparameters(self): | |
| override_params, param_names=list(override_params.keys()), return_full_spec=True | ||
| ) | ||
| self._hyperparameters = FineTuningOptions(spec) | ||
| self._hp_defaults = self._hyperparameters.to_dict().copy() | ||
| return self._hyperparameters | ||
|
|
||
| def _get_user_changed_hyperparameters(self) -> Dict[str, str]: | ||
| """Return hyperparameters that differ from the hub recipe defaults. | ||
|
|
||
| Returns: | ||
| Dict[str, str]: Changed values, keyed by recipe parameter name. | ||
| """ | ||
| final = self.hyperparameters.to_dict() | ||
| try: | ||
| resolved = self.get_resolved_recipe() | ||
| except ValueError: # no recipe, overrides or direct assignments | ||
| resolved = {} | ||
| values = flatten_resolved_recipe(resolved) | ||
| # flatten_resolved_recipe skips lists, so take them from the inference section. | ||
| values.update( | ||
| {k: v for k, v in resolved.get("inference", {}).items() if isinstance(v, list)} | ||
| ) | ||
| for k, v in values.items(): | ||
| if v is not None: | ||
| final[k] = v if isinstance(v, str) else str(v) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Low: In |
||
|
|
||
| defaults = self._hp_defaults or {} | ||
| return {k: v for k, v in final.items() if v != defaults.get(k)} | ||
|
|
||
| # --- Helpers --------------------------------------------------------- | ||
|
|
||
| def _resolve_agent_arn(self) -> None: | ||
|
|
@@ -428,14 +459,14 @@ def _build_template_context( | |
| """Assemble the rendering context expected by the MTRL templates.""" | ||
| import json as _json | ||
|
|
||
| hparams: Dict[str, Any] = {} | ||
| hparams: Dict[str, str] = {} | ||
| try: | ||
| hparams = self._get_effective_hyperparameters() | ||
| hparams = self._get_user_changed_hyperparameters() | ||
| except Exception as e: # hub fetch can fail in offline envs | ||
| _logger.info(f"Skipping hub-sourced hyperparameters: {e}") | ||
|
|
||
| def _str_or_none(v): | ||
| return str(v) if v is not None else None | ||
| _logger.warning( | ||
| f"Could not load MTRL evaluation hyperparameters ({e}); the " | ||
| f"evaluation job will use the service defaults." | ||
| ) | ||
|
|
||
| action_arn_prefix = ( | ||
| f"arn:aws:sagemaker:{aws_context['region']}:{aws_context['account_id']}:action" | ||
|
|
@@ -492,20 +523,8 @@ def _build_job_config_doc(include_mpc: bool, mlflow_run_name: str) -> str: | |
| "BaseModelArn": base_model_arn, | ||
| "AcceptEula": True, | ||
| } | ||
| hp: Dict[str, str] = {} | ||
| for k in ( | ||
| "eval_group_size", | ||
| "sampling_temperature", | ||
| "top_p", | ||
| "max_tokens", | ||
| "pass_k_values", | ||
| "success_threshold", | ||
| ): | ||
| v = hparams.get(k) | ||
| if v is not None: | ||
| hp[k] = str(v) | ||
| if hp: | ||
| eval_cfg["HyperParameters"] = hp | ||
| if hparams: | ||
| eval_cfg["HyperParameters"] = dict(hparams) | ||
|
|
||
| doc: Dict[str, Any] = { | ||
| "AgentConfig": agent_cfg, | ||
|
|
@@ -549,12 +568,6 @@ def _build_job_config_doc(include_mpc: bool, mlflow_run_name: str) -> str: | |
| "mlflow_resource_arn": self.mlflow_resource_arn, | ||
| "mlflow_experiment_name": getattr(self, "mlflow_experiment_name", None) | ||
| or aws_context.get("pipeline_name"), | ||
| "eval_group_size": _str_or_none(hparams.get("eval_group_size")), | ||
| "sampling_temperature": _str_or_none(hparams.get("sampling_temperature")), | ||
| "top_p": _str_or_none(hparams.get("top_p")), | ||
| "max_tokens": _str_or_none(hparams.get("max_tokens")), | ||
| "pass_k_values": _str_or_none(hparams.get("pass_k_values")), | ||
| "success_threshold": _str_or_none(hparams.get("success_threshold")), | ||
| "stopping_condition": self.stopping_condition, | ||
| "model_package_group_arn": model_package_group_arn, | ||
| "source_model_package_arn": self._source_model_package_arn_cache, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Medium: List-valued hyperparameters (e.g.
pass_k_values) set viarecipeoroverridesare silently dropped._get_effective_hyperparameters()usesflatten_resolved_recipe, which explicitly skips list values (elif not isinstance(v, list)inrecipe_resolver.flatten_resolved_recipe), so the loop here never sees them. The only list values that survive are those captured fromself.hyperparameters.to_dict(), i.e. those set via direct attribute assignment. The PR body states "This coversevaluator.hyperparameters.<name>,recipeandoverrides" and "List values such aspass_k_valuesare forwarded", but therecipe/overridespath for list values does not work. The newtest_list_values_are_forwardedonly exercises direct assignment andtest_overrides_dict_is_forwardedonly uses scalars, so this gap is untested. Consider merging list values from the resolved recipe before dropping them, or documenting the limitation.