Skip to content

Missing labels in loss kwargs causing issue for electra model / Issues from PR#130 #140

Description

@aditya0by0

When I try use an electra checkpoint for prediction, the recently merged code in the PR #130 causes an issue.

  File "chebai/result/prediction.py", line 171, in <module>
    CLI(MainPredictor, as_positional=False)
  File "/home/staff/a/akhedekar/miniconda3/envs/gnn/lib/python3.10/site-packages/jsonargparse/_cli.py", line 23, in CLI
    return auto_cli(*args, _stacklevel=3, **kwargs)
  File "/home/staff/a/akhedekar/miniconda3/envs/gnn/lib/python3.10/site-packages/jsonargparse/_cli.py", line 102, in auto_cli
    return _run_component(components, init)
  File "/home/staff/a/akhedekar/miniconda3/envs/gnn/lib/python3.10/site-packages/jsonargparse/_cli.py", line 210, in _run_component
    return component(**cfg)
  File "chebai/result/prediction.py", line 152, in predict_from_file
    predictor.predict_from_file(
  File "chebai/result/prediction.py", line 89, in predict_from_file
    preds: torch.Tensor = self.predict_smiles(smiles=smiles_strings)
  File "/home/staff/a/akhedekar/miniconda3/envs/gnn/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
  File "chebai/result/prediction.py", line 128, in predict_smiles
    self._model.predict_step(batch, batch_idx, dm_hparams=self._dm_hparams)
  File "/home/staff/a/akhedekar/python-chebai/chebai/models/base.py", line 247, in predict_step
    pr, _ = self._get_prediction_and_labels(data, labels, model_output)
  File "/home/staff/a/akhedekar/python-chebai/chebai/models/electra.py", line 330, in _get_prediction_and_labels
    d = d * (~missing_labels).int().to(
RuntimeError: The size of tensor a (1528) must match the size of tensor b (2) at non-singleton dimension 1

Additional Information

shape of missing labels is [2, 2]

with following values. [[False, False], [False, False]]

the missing labels are added using collator with new logic (#130). Relevant part of code below:

            missing_labels = [
                d.get("missing_labels", [False for _ in y[0]]) for d in data
            ]

Activity

  1. aditya0by0 commented on Dec 18, 2025

    @aditya0by0
    MemberAuthor

    Also, the pass_loss_kwargs for electra was set to True instead of accepting value from the user or method parameter. Is there any particular reason for it with new changes introduced ?
    https://github.com/ChEB-AI/python-chebai/pull/130/files#diff-9b4cba0f4cb875af21676f1998e61cd7b25a1e65d7b971a00ce88d17df880706R244

  2. aditya0by0 commented on Dec 18, 2025

    @aditya0by0
    MemberAuthor

    Also in electra config, the model type is set to regression, shouldn't it be the original classification version by default.

    https://github.com/ChEB-AI/python-chebai/pull/130/files#diff-286e6c43d041243386413f98ba9f93eca188d678d39b19a40450c57df5ab9979R3

  3. aditya0by0 commented on Dec 18, 2025

    @aditya0by0
    MemberAuthor

    Also, I wonder whether the issue #53 was also addressed in that PR. As I see files and tests related to tox changed.

  4. aditya0by0 commented on Jan 9, 2026

    @aditya0by0
    MemberAuthor
  5. aditya0by0 commented on Jan 11, 2026

    @aditya0by0
    MemberAuthor

    I wonder why the following line as deleted ?
    https://github.com/ChEB-AI/python-chebai/pull/130/files#diff-5a15c77150d45ed1d4be890d0dc4808bfc54d5df4a9a998ddedf9ab583d7c3c3L276

    The reason for this question is that I am concerned that deletion and the below error might be related.
    https://wandb.ai/chebai/chebai/runs/m74gxlm8/logs?nw=nwuseraditya0by0

    SLURM auto-requeueing enabled. Setting signal handlers.
    Sanity Checking: |          | 0/? [00:00<?, ?it/s]
    Loading validation data... (datamodule.current_epoch=N/A)
    Loading splits from data/chebi_v241/ChEBI50/processed/splits.csv...
    Sanity Checking DataLoader 0:   0%|          | 0/2 [00:00<?, ?it/s]Computing loss-weights based on v241 dataset (beta=1000.0)
    Epoch 0: 100%|██████████| 5017/5017 [02:25<00:00, 34.43it/s, v_num=0153, train_loss_step=nan.0, val_loss_step=nan.0, val_loss_epoch=nan.0, val_macro-f1=0.000, val_micro-f1=0.000, train_loss_epoch=nan.0, train_macro-f1=2.62e-5, train_micro-f1=0.000748]
    Loading train data... (datamodule.current_epoch=N/A)
    Starting epoch 0
                                                                              
    Traceback (most recent call last):
      File "/home/staff/a/akhedekar/miniconda3/envs/gnn/lib/python3.10/runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/home/staff/a/akhedekar/miniconda3/envs/gnn/lib/python3.10/runpy.py", line 86, in _run_code
     ...
     ...
     ...
      File "/home/staff/a/akhedekar/miniconda3/envs/gnn/lib/python3.10/site-packages/lightning/pytorch/callbacks/model_checkpoint.py", line 383, in _save_topk_checkpoint
        raise MisconfigurationException(m)
    lightning.fabric.utilities.exceptions.MisconfigurationException: `ModelCheckpoint(monitor='val_roc-auc')` could not find the monitored key in the returned metrics: ['train_loss', 'train_loss_step', 'val_loss', 'val_loss_epoch', 'val_macro-f1', 'val_micro-f1', 'train_loss_epoch', 'train_macro-f1', 'train_micro-f1', 'epoch', 'step']. HINT: Did you call `log('val_roc-auc', value)` in the `LightningModule`?
  6. changed the title [-]Missing labels in loss kwargs causing issue for electra model[/-] [+]Missing labels in loss kwargs causing issue for electra model / Issue from PR#130[/+] on Jan 11, 2026
  7. changed the title [-]Missing labels in loss kwargs causing issue for electra model / Issue from PR#130[/-] [+]Missing labels in loss kwargs causing issue for electra model / Issues from PR#130[/+] on Jan 11, 2026
  8. added theissue type on Jan 11, 2026
  9. sfluegel05 commented on Jan 19, 2026

    @sfluegel05
    Collaborator

    Oh dear, it seems like we missed some important things in PR #130.

    Also, the pass_loss_kwargs for electra was set to True instead of accepting value from the user or method parameter. Is there any particular reason for it with new changes introduced ?
    https://github.com/ChEB-AI/python-chebai/pull/130/files#diff-9b4cba0f4cb875af21676f1998e61cd7b25a1e65d7b971a00ce88d17df880706R244

    That does not make sense. True is already the default and I don't see a reason for overriding the user input. We should remove that line.

    Also in electra config, the model type is set to regression, shouldn't it be the original classification version by default.

    https://github.com/ChEB-AI/python-chebai/pull/130/files#diff-286e6c43d041243386413f98ba9f93eca188d678d39b19a40450c57df5ab9979R3

    You are right, it should be classification.

    Also, I wonder whether the issue #53 was also addressed in that PR. As I see files and tests related to tox changed.

    Probably, that is a question for @schnamo

    Default beta value for BCE is set to 1000

    Is this was the intended change ?

    https://github.com/ChEB-AI/python-chebai/pull/130/files#diff-00639a90075191fb4a6de89627b1181de9a0d44451fbf239c0a96e9df6750280R2-R3

    I would say not intended since beta is supposed to be a value between 0 and 1, we should ask @schnamo about this (and also about the other BCE configs).

    I wonder why the following line as deleted ? https://github.com/ChEB-AI/python-chebai/pull/130/files#diff-5a15c77150d45ed1d4be890d0dc4808bfc54d5df4a9a998ddedf9ab583d7c3c3L276

    I don't know why it got removed, we should re-add it (although I'm not sure if that solves the problem you mention).

  10. sfluegel05 commented on Jan 19, 2026

    @sfluegel05
    Collaborator

    For the loss configs, see also #139

  11. schnamo commented on Jan 20, 2026

    @schnamo
    Collaborator
    • pass_loss_kwargs always set to True removed
    • electra config set to classification
    • loss configs tidied up
    • BCE loss beta parameter set to 0.99 in accordance with Chebifier
    • Re-added accidentally removed line
  12. sfluegel05 commented on Jan 20, 2026

    @sfluegel05
    Collaborator

    Thanks. @schnamo Can you confirm that the toxicity-related issues are out of date (#53) and your version of the toxicity datasets is functional?

  13. schnamo commented on Jan 26, 2026

    @schnamo
    Collaborator

    Seems to work fine now!

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

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions