Add support for row-dependent sampling from list and weighted-dict columns

Open
#1,201 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
data

Research direction

Start by reading the column configuration and generator paths named in the issue: config/column_configs.py, config/column_types.py, and engine/column_generators/generators/. Then trace row drop handling in engine/dataset_builders/async_scheduler.py and row offsets in engine/context.py; the issue leaves key design questions open. Done means a built-in column can sample each row's list or weighted dict pool, with defined handling for invalid pools, empty pools, and seeded draws, plus tests for those behaviors.

Written by the indexing model from the issue text.

Description

enhancement needs-discussion
Priority Level

High (Major improvement)

Is your feature request related to a problem? Please describe.

Data Designer samples from distributions that are fixed in the config (SamplerColumnConfig). Some pipelines instead need each record to sample from its own pool: a list or weighted dict held in another column of the same record, coming from the seed dataset or an earlier column.

record_id candidate_pool example draw
1 ["A", "B", "C"] "B"
2 ["D", "E"] "E"
3 {"F": 0.8, "G": 0.2} "F"

I ran into this while moving pipelines to Data Designer from SDG Hub, an open-source Python framework for synthetic data generation. Two existing synthetic data generation workflows that I and my team use depend on per-record sampling:

  • Red-team prompt generation: each seed record is an adversarial harm category with its own pools for eight attributes (demographic, region, language style and so on). Most pools are uniform lists; some are weighted dicts. Each output row draws one value per attribute from its own record's pools.
  • MCP tool-use distillation: each seed record is an MCP server with its tool list. Each output row draws 2 of that server's tools, without replacement, to seed a question.

Neither fits Data Designer's config today:

  • Sampler columns can't read other columns. They are generated from scratch, and #614 made this explicit for subcategory samplers by rejecting non-sampler parents at config validation.
  • Expression columns can pick one element uniformly with Jinja's random filter, but offer no weights, no sampling without replacement and no seeding, and an empty pool drops the row.
  • Custom columns and column-generator plugins can do it, but each pipeline then needs Python code or an extra package, and a custom column can't ship in a config file run with data-designer create.
Describe the solution you'd like

Proposing to add a built-in column type, pool-sampler, that draws values from a pool held in another column of the same record. A pool is a list (drawn uniformly) or a dict of value to weight (drawn by weight), and can come from the seed dataset or from an earlier column.

columns:
  - name: region
    column_type: pool-sampler
    source_column: geography_pool   # list -> uniform, dict -> weighted
    num_samples: 1
    return_scalar: true

  - name: sampled_tools
    column_type: pool-sampler
    source_column: tool_list
    num_samples: 2                  # without replacement by default
dd.PoolSamplerColumnConfig(name="region", source_column="geography_pool", num_samples=1, return_scalar=True)
Field Default Notes
source_column required column holding each record's pool
num_samples 1 at least 1
replace false without replacement, draws min(num_samples, pool size)
return_scalar false returns the value instead of a one-element list; only with num_samples: 1
seed unset optional int

Per row:

  • A list, array or set pool is drawn uniformly (a set is sorted first). A dict pool is drawn by weight.
  • Weights must be finite and non-negative. Keys with weight 0 are dropped. Keys with weight None count as absent, because parquet and JSONL seeds pad dict keys missing from a record with None.
  • An empty pool, a null cell, or a dict with no positive weight gives None with return_scalar, and [] otherwise. The row is kept.
  • A pool stored as text is parsed as JSON, then as a Python literal (nothing is executed). A column that mixes lists and dicts reaches generators only as text: JSON strings from a JSONL seed, Python reprs from a DataFrame seed.
  • A row whose pool is invalid is dropped: a negative, infinite or non-numeric weight, or a value that is not a list, array, set, dict or parseable text. The log gives drop counts by reason, the way expression columns report rows that fail to render.
  • With seed set, each row gets its own generator, keyed on the seed, the column name and the row's absolute index. Draws then don't depend on row-group scheduling or buffer_size, and preview and create agree. Without seed, draws use fresh entropy.

For list and dict pools this matches SDG Hub's SamplerBlock in cell mode: the same weight checks, zero weights dropped, and the same empty-pool output. The differences are the None-weight rule, parsing of text pools, and the handling of invalid pools: SamplerBlock raises on bad weights (failing the flow), returns an empty draw for a scalar and samples a string's characters, while this column drops the row. SamplerBlock also consumes one seeded generator in row order, which a row-group engine can't reproduce, so seeded draws match it in distribution, not draw for draw.

Fit in the engine:

  • Config: PoolSamplerColumnConfig(SingleColumnConfig) with required_columns = [source_column], registered in config/column_types.py and exported from config/__init__.py.
  • Engine: a ColumnGeneratorFullColumn in a new engine/column_generators/generators/pool_sampler.py, registered in engine/column_generators/registry.py and engine/column_generators/utils/generator_classification.py.
  • DAG and skip: as an ordinary single column, it runs after its source column in the dependency DAG and can carry skip.when. sampler columns can't do either: they are generated together from scratch, and skip is rejected on them (config/base.py, _validate_skip_scope).
  • Row drops: the scheduler accepts fewer rows back only from expression columns today (_task_supports_row_drops). The new type would join that contract, including failing the run when a row group has no valid row.

I have this working as a column-generator plugin, with tests. A plugin can't drop single rows though: only expression columns may return fewer rows, so an invalid pool in a plugin column drops its whole row group. Once this issue is triaged, I'll use the plugin as the starting point for a plan in plans/<issue>/ and a PR. I am proposing a built-in column because the operation is domain-independent, but open to contributing it to DataDesignerPlugins if that fits the project's direction better.

Open questions:

  1. A separate column type, or a new sampler_type under sampler? The latter needs row access inside the sampler engine.
  2. For an empty or null pool: None for scalar output and [] for list output (as SamplerBlock does), or always None?
  3. For an invalid pool: drop the row (as expression columns do), or fail the run (as SamplerBlock does)?
  4. Seeded draws in multi-shard Slurm runs: key them on a global row index if shards expose one, or limit seeded columns to single-shard runs?
Describe alternatives you've considered
  1. A new sampler_type that reads from a column. Sampler columns are collapsed into one multi-column generator that builds its frame from scratch, so no sampler type sees row values. Conditions that name a non-sampler column fail with "not found in schema", and #614 rejects non-sampler subcategory parents at config validation. This route needs row access and per-row parameters inside the sampler engine, and the column still couldn't carry skip.when (open question 1).

  2. Jinja's random filter in an expression column. It picks one element uniformly from a list, but:

    • it has no weights: with data-designer 1.1.0, a dict pool from a DataFrame seed reaches the template as (key, weight) pairs, so the filter renders a pair such as "['Western Europe', 0.7]";
    • the result is rendered text, cast at most to int, float or bool, so k values can't come back as a list;
    • it uses Python's global random module, so draws can't be seeded;
    • an empty or null pool drops the row.

    More filters (a weighted pick, a k-sample) would add weights. But the output would still be text, draws still couldn't be keyed to the row, and an empty pool would still drop the row.

  3. Pre-sampling in pandas before the run. This works when the pools are in the seed: sample into new seed columns, then run the config. But the sampling then lives outside the config, so the pipeline is no longer one config that data-designer create can run. The rows also have to be replicated in pandas first, and pools produced by an earlier column can't be handled.

  4. A custom column. It works in Python, but a config that uses one can't ship as a file: generator_function serializes as the function's name, and loading needs a callable decorated with @custom_column_generator (unless I missed something).

  5. A column-generator plugin. This is what I use today (see above). Its limits:

    • everyone who runs the config has to install the package;
    • multi-shard Slurm runs reject plugin column types (slurm/planning/resolution.py, _SHARDABLE_COLUMN_TYPES; #1113);
    • it can't drop single rows, so an invalid pool drops its whole row group.
  6. A package in DataDesignerPlugins. It would be listed in the default nvidia catalog, so users could find and install it easily. It would still face the install step and the Slurm limit that every plugin has but open to this as alternative / staging spot for this functionality.

Agent Investigation

Findings are at main @ 861a0828 (2026-12-03; v1.1.0 is the latest release). Source paths are under packages/data-designer-*/src/data_designer/.

Sampler columns have no row access

  • SamplerColumnConfig.required_columns returns [] (config/column_configs.py:92-94).
  • SamplerColumnGenerator is a FromScratchColumnGenerator that uses only len(data) (engine/column_generators/generators/samplers.py:29-38). The sampler engine starts from DataFrame(index=range(num_samples)) (engine/sampling_gen/generator.py:118).
  • Condition columns become sampler-DAG nodes (engine/sampling_gen/schema.py:65-70), and a node that isn't a sampler raises Column '<name>' not found in schema (:139). On 1.1.0, a category sampler conditioned on a seed column fails with exactly that error.
  • Samplers draw from numpy's global RandomState (engine/sampling_gen/utils.py:39-40, generator.py:66), and RunConfig has no seed.
  • skip is rejected on sampler and seed-dataset columns (config/base.py:116-124).

Failures and row drops

  • Only expression columns may return fewer rows than they received (engine/dataset_builders/async_scheduler.py:2196-2202).
  • A non-retryable failure in any other batch generator drops its whole row group (async_scheduler.py:2099-2104). With my plugin on 1.0.1, I ran 6 rows with buffer_size=2 and one negative weight in row 3: rows 2 and 3 were dropped and 4 rows came back.

Per-row identity for seeding

  • current_row_group_start_offset is set for every task (engine/context.py:24-26, async_scheduler.py:1948). For planned row groups it equals row_group * buffer_size (engine/dataset_builders/row_group_plan.py:204-209).
  • Batch generators receive DataFrames that keep slot indices (engine/dataset_builders/utils/row_group_buffer.py:71-85).
  • SeedDatasetColumnGenerator already reads the offset (engine/column_generators/generators/seed_dataset.py:46-49).

Custom columns and plugins

  • generator_function serializes as the function's __name__ (config/column_configs.py:735-737), and loading requires a callable decorated with @custom_column_generator (:700-706).
  • Multi-shard Slurm runs accept only the built-in types in _SHARDABLE_COLUMN_TYPES (slurm/planning/resolution.py:50-62, :358-364; #1113).

What seeds deliver (probe with 1.1.0, pandas 3.1.2 and pyarrow 24.0.0; 1.0.1 gave identical results; no LLM calls)

Seed source List pool arrives as Dict pool arrives as
DataFrameSeedSource numpy.ndarray list of (key, weight) tuples
parquet or JSONL LocalFileSeedSource numpy.ndarray dict with every key seen in any row; keys absent from the row are None
a column mixing lists and dicts parquet: can't be written; JSONL: JSON strings; DataFrame: Python repr strings same

{{ pool | random }} with a DataFrame seed:

  • list pool: one element per row;
  • weighted dict pool: the pair rendered as a string, e.g. ['Western Europe', 0.7];
  • empty list and null pool: both rows dropped (EmptyRenderedExpression=1, TemplateRenderError=1).

With the plugin on 1.0.1, a pool built by an earlier expression column also works: each row drew from its own pool.

Places a new built-in type touches

  • config/column_types.py:32-44, :82-98 and :143-155
  • config/__init__.py:16-30 and :142-160
  • engine/column_generators/registry.py:45-57
  • engine/column_generators/utils/generator_classification.py:17-27
  • engine/dataset_builders/async_scheduler.py:2196-2202, for the row-drop contract
  • slurm/planning/resolution.py:50-62 and slurm/services/wiring.py:1003-1015, if seeded runs can be made shard-safe
  • Tests (repo paths): packages/data-designer-engine/tests/engine/column_generators/test_registry.py and packages/data-designer-engine/tests/engine/column_generators/utils/test_generator_classification.py
  • Docs (repo paths): fern/versions/latest/pages/concepts/columns.mdx and architecture/config.md
Additional context

Some references from / for sdg_hub's version of this feature:

Checklist
  • I've reviewed existing issues and the documentation
  • This is a design proposal, not a "please build this" request
Dominant language
Python
Stars
2.4k
Forks
258
Avg merge
4d 20m
Merged PRs (30d)
32

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA-NeMo/DataDesigner

All issues in NVIDIA-NeMo/DataDesigner

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.