Nesting/cascading dynamic widgets not working as expected

Hi,

Hopefully the description of what I’m trying to do makes sense, basically I want this behavior:

If the cpu partition is selected, hide all GPU settings.

If the interactive partition is selected, force the slurm_gpu_type to a40 and force the slurm_gpus to 1, leaving the slurm_gpu_constraint widget hidden.

If the gpu partition is selected, show the slurm_gpus and slurm_gpu_type widgets.

If gpu partition is selected AND the slurm_gpu_type is set to a100, then display the slurm_gpu_constraint widget to allow selecting an A100 sub-type.

The config below almost works, but the slurm_gpu_constraint widget is never displayed regardless of my selections. Am I doing something wrong or is nesting/cascading levels like this not something that will work with dynamic widgets?

slurm_partition:
    label: "Partition (--partition=THIS_VALUE):"
    widget: "select"
    help:
    options:
      - [
          "cpu", "cpu",
          data-hide-slurm-gpus: true,
          data-hide-slurm-gpu-type: true,
          data-hide-slurm-gpu-constraint: true
        ]
      - [
          "gpu", "gpu",
          data-max-slurm-gpus: 4
        ]
      - [
          "interactive", "interactive",
          data-max-slurm-gpus: 1,
          data-hide-slurm-gpu-type: true,
          data-set-slurm-gpu-type: "a40",
          data-hide-slurm-gpu-constraint: true,
          data-set-slurm-gpu-constraint: ""
        ]
    value: 'cpu'

  slurm_gpus:
    label: "Number of gpus (--gres=gpu:THIS_VALUE)"
    help: "This value sets the number of gpus that will be available to the job.
           Select the gpu partition if this value is non-zero for best results ..."
    widget: "number_field"
    value: "0"
    min: "0"
    max: "8"

  slurm_gpu_type:
    label: "Optional GPU type. Using a specific type could result in longer queue times."
    widget: "select"
    options:
      - [ "Any Available GPU", "", data-hide-slurm-gpu-constraint: true ]
      - [ "A100", "a100" ]
      - [ "A40", "a40", data-hide-slurm-gpu-constraint: true ]
      - [ "A6000", "a6000", data-hide-slurm-gpu-constraint: true ]
    value: ""

  slurm_gpu_constraint:
    label: "Optional GPU constraint, to select between different versions of the same GPU type."
    widget: "select"
    options:
      - [ "Any available A100", "" ]
      - [ "A100 80GB", "a100_80" ]
      - [ "A100 40GB", "a100_40" ]
    value: ""

Well, I found part of my problem, I had forgotten to add slurm_gpu_constraint to the form: element. But having fixed that, it’s still not working. As soon as I select the gpu partition the slurm_gpu_constraint widget is displayed and then not hidden by the slurm_gpu_type selections. So I’m still stuck on how to get this to work with the nested/cascading selections.

Hey, sorry for the trouble. The code you posted has one thing jumping out, which is that some attributes seem to be at the wrong level. Your slurm_partition has everything below it indented, so slurm_gpus and slurm_gpy_type and slurm_gpu_contsraint don’t look to be set at the attributes level for the form.

Sure enough, if i fix some of that indentation locally, I can see the behavior you’re after where I can select gpu, then I can select certain gpu types that will hide that optional constraint.

Here’s roughly what I have:

attributes:    
  slurm_partition:
    label: "Partition"
    widget: "select"
    help:
    options:
      - [
          "cpu", "cpu",
          data-hide-slurm-gpus: true,
          data-hide-slurm-gpu-type: true,
          data-hide-slurm-gpu-constraint: true
        ]
      - [
          "gpu", "gpu",
          data-max-slurm-gpus: 4
        ]
      - [
          "interactive", "interactive",
          data-max-slurm-gpus: 1,
          data-hide-slurm-gpu-type: true,
          data-set-slurm-gpu-type: "a40",
          data-hide-slurm-gpu-constraint: true,
          data-set-slurm-gpu-constraint: ""
        ]
    value: 'cpu'
  slurm_gpus:
    label: "Number of gpus"
    widget: "number_field"
    value: "0"
    min: "0"
    max: "8"
  slurm_gpu_type:
    label: "Optional GPU type"
    widget: "select"
    options:
      - [ "Any Available GPU", "", data-hide-slurm-gpu-constraint: true ]
      - [ "A100", "a100" ]
      - [ "A40", "a40", data-hide-slurm-gpu-constraint: true ]
      - [ "A6000", "a6000", data-hide-slurm-gpu-constraint: true ]
    value: ""
  slurm_gpu_constraint:
    label: "Optional GPU constraint"
    widget: "select"
    options:
      - [ "Any available A100", "" ]
      - [ "A100 80GB", "a100_80" ]
      - [ "A100 40GB", "a100_40" ]
    value: ""

Thanks @travert, not suprised that I mangled the indentation, but while struggling with this I “fixed” my problem by just merging my gpu_type and gpu_constraint into a single widget and then teasing the two values apart in submit.yml.erb. I have many other places I want to use cascading widgets like this though, so I’ll follow up here when I do with the result.

I’ll add my workaround, in case it’s helpful to someone facing the same kind of problem:

In form.yml.erb I have:

  slurm_gpu_type:
    label: "Optional GPU type. Using a specific type could result in longer queue times."
    widget: "select"
    options:
      - [ "Any Available GPU", "", data-max-slurm-gpus: 4 ]
      - [ "A100 (Any Size)", "a100", data-max-slurm-gpus: 4 ]
      - [ "A100 (80G)", "a100,a100_80", data-max-slurm-gpus: 4 ]
      - [ "A100 (40G)", "a100,a100_40", data-max-slurm-gpus: 4 ]
      - [ "A40", "a40", data-max-slurm-gpus: 1 ]
      - [ "A6000", "a6000", data-max-slurm-gpus: 4 ]
    value: ""

Which encapsulates type and constraint and eliminates the problem of selecting too many GPUs of a given type by setting the max that can be requested for each type.

Then in submit.yml.erb it’s handed with:

  <%- unless slurm_gpus.to_i == 0 -%>
    <%- unless slurm_partition == 'cpu' -%>
      <% gpu_type, gpu_constraint = slurm_gpu_type.include?(',') ? slurm_gpu_type.split(',', 2) : [slurm_gpu_type, nil] %>
    - "--gpus=<%= gpu_type.present? ? "#{gpu_type}:" : "" %><%= slurm_gpus.to_s %>"
      <%- if gpu_constraint -%>
    - "--constraint=<%= gpu_constraint %>"
      <%- end -%>
    <%- end -%>
  <%- end -%>

So far this is working well.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.