Skip to content

Sample from a set discrete values in variation system - #1767

Draft
xyao-nv wants to merge 5 commits into
mainfrom
xyao/feature/discrete-value-sampler
Draft

xyao-nv wants to merge 5 commits into
mainfrom
xyao/feature/discrete-value-sampler

Conversation

@xyao-nv

@xyao-nv xyao-nv commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Let ChoiceSampler draw from its own values, at random with optional weights or as one fixed entry per env, and let numeric variations take it in place of UniformSampler.

Why this change?

Numeric variations, such as object mass, light intensity and camera extrinsics, accept only UniformSamplerCfg. To evaluate an apple at two known masses, 0.17 kg and 0.24 kg, a user runs twice with low equal to high. There is also no way to give each parallel environment its own fixed value, so that one run covers every value without randomness.

ChoiceSampler already picks from a set, but only for name lists such as HDR images and assets, only uniformly, and only from the choices that a variation passes to each draw.

Hydra overrides also cannot change the type of a config node, so overrides could not switch a variation away from its uniform sampler.

What changes?

Motivated by measuring apple weights task,

  • ChoiceSampler draws from a set of any values: ChoiceSamplerCfg gains three fields:

    • values: the entries to draw from, for example [[0.17], [0.24]]. With values set, a draw needs no choices.
    • probabilities: weights for random draws.
    • random_choice=False: env i gets entry i % len(entries) on every reset, with no random draws. A build-time variation draws without env ids, so it gets the first entry.

    When values is empty, each draw passes its own choices, as before. HDRImageVariation and RigidAssetSelectionVariation keep working unchanged, and a seed gives the same draws as before, which a test pins.

  • Numeric variations take either sampler: object mass, camera extrinsics and intrinsics, and light intensity, color, color temperature and direction now type sampler_cfg as SamplerBaseCfg. Their defaults are unchanged. They draw through the new sample_float_rows() in sampler_base.py, which turns a sampler's output into a float32 tensor of the shape the variation needs. It accepts both the tensor from UniformSampler and the list of number lists from ChoiceSampler. This draw-time shape check replaces the setup-time shape_per_sample checks.

  • Sampler selection in overrides: UniformSamplerCfg and ChoiceSamplerCfg carry a distribution name, "uniform" or "choice". Before Hydra composes the config, build_variations_cfg_with_overrides reads <host>.<variation>.sampler_cfg.distribution overrides and puts a default cfg of the selected type into the schema. The remaining overrides then set its fields.

    • Selecting the current distribution keeps the current values.
    • An unknown distribution, or one the variation does not accept, fails and lists the available names.
    • A field of another sampler, such as values without distribution=choice, fails with a hint to set distribution.
  • Docs: the variations concept page describes drawing from a fixed set and its two modes, and its --list_variations example shows the new distribution field. The author-environment skill has the override syntax.

Limitations:

  • SamplerBaseCfg also admits sampler cfgs that do not return numbers, such as BernoulliSamplerCfg. Such a sampler fails at its first draw. Overrides can select only uniform and choice.
  • In an experiment config, a variation that sets uniform low and high for every Run cannot switch to choice in one Run. The merged overrides fail with an unknown-field error. Set the sampler fields in each Run instead.

Usage example

Before, a single fixed mass, one run per mass:

pick_up_object.mass.enabled=true \
"pick_up_object.mass.sampler_cfg.low=[0.17]" \
"pick_up_object.mass.sampler_cfg.high=[0.24]"

After, selecting mass per episode:

pick_up_object.mass.enabled=true \
pick_up_object.mass.sampler_cfg.distribution=choice \
"pick_up_object.mass.sampler_cfg.values=[[0.17],[0.24]]" \
pick_up_object.mass.sampler_cfg.random_choice=false

With random_choice=false, even envs get 0.17 kg and odd envs get 0.24 kg on every reset. Without it, each reset draws a mass at random; "pick_up_object.mass.sampler_cfg.probabilities=[0.8,0.2]" weights the draws. The same keys work in an experiment config's variations field.

Validation

  • Simulation tests for the object mass, light, HDR image and build-time variations locally, and all passed. They include a new 3-env test that applies a choice mass sampler through Hydra overrides and checks the masses and the recorded values over two resets.

@xyao-nv xyao-nv changed the title Xyao/feature/discrete value sampler Sample from discrete value sets in variation system Nov 30, 2026
@xyao-nv xyao-nv changed the title Sample from discrete value sets in variation system Sample from a set discrete values in variation system Nov 30, 2026
DiscreteSampler draws value vectors from a fixed list and returns the
same float32 tensors as UniformSampler, so it drives any variation that
takes a ContinuousSampler. It draws entries at random, optionally
weighted, or gives env i the entry values[i % n] without drawing.

ChoiceSampler and DiscreteSampler share one random index draw, which
keeps ChoiceSampler's draws unchanged for a given seed. The numeric
variations now accept any ContinuousSamplerCfg instead of only
UniformSamplerCfg.

Signed-off-by: Xinjie Yao <[email protected]>
Hydra overrides cannot change the type of a config node, so a numeric
variation could not switch from its uniform sampler from the command
line or an experiment config. Continuous sampler cfgs now carry a
distribution name, and a <variation>.sampler_cfg.distribution override
makes the override schema hold that sampler cfg before the remaining
overrides set its fields, for example:

  apple.mass.sampler_cfg.distribution=discrete
  apple.mass.sampler_cfg.values=[[0.17],[0.24]]

Signed-off-by: Xinjie Yao <[email protected]>
Keep the variations page to what a fixed set of values is for and its two modes; move the override syntax into the author-environment skill.

Signed-off-by: Xinjie Yao <[email protected]>
ChoiceSampler now draws from its own values as well as from per-call
choices, at random with optional probabilities or as one fixed entry
per env. DiscreteSampler is removed, and ContinuousSampler is back to
its form on main apart from the distribution name.

Numeric variations type sampler_cfg as SamplerBaseCfg and draw through
sample_float_rows(), which returns a float32 tensor of the shape the
variation needs from a UniformSampler or a ChoiceSampler. The override
that selects the sampler is now
<variation>.sampler_cfg.distribution=choice.

Signed-off-by: Xinjie Yao <[email protected]>
…uild

With random_choice=false, a draw without env ids now starts at the rebuild
index, so rebuild k of a build-time variation takes values[k % n], as in-order
asset selection does. VariationBase passes the rebuild index to its sampler.

Numeric variations declare numeric_sample_shape, and configure_at_build_time
checks every value the sampler can draw against it, so a wrong-shaped value,
a choice sampler without values or a non-numeric sampler fails before the env
is built.

HDRImageVariation gets its own HDRImageSamplerCfg with only random_choice, so
its listing no longer shows a values field that conflicts with hdr_names.

Signed-off-by: Xinjie Yao <[email protected]>
@xyao-nv
xyao-nv force-pushed the xyao/feature/discrete-value-sampler branch from 66dee11 to 73c863a Compare November 30, 2026 22:57

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant