Skip to content

Fix ProgressBoard AttributeError and unconditional label assignment in torch/tensorflow/mxnet backends#2706

Open
Chessing234 wants to merge 3 commits into
d2l-ai:masterfrom
Chessing234:fix/progressboard-xlabel-none-check
Open

Fix ProgressBoard AttributeError and unconditional label assignment in torch/tensorflow/mxnet backends#2706
Chessing234 wants to merge 3 commits into
d2l-ai:masterfrom
Chessing234:fix/progressboard-xlabel-none-check

Conversation

@Chessing234
Copy link
Copy Markdown

Bug

In ProgressBoard.draw() across the PyTorch, TensorFlow, and MXNet backends, the label-setting code is:

if not self.xlabel: self.xlabel = self.x
axes.set_xlabel(self.xlabel)
axes.set_ylabel(self.ylabel)

Two problems:

  1. self.x is not an attribute of ProgressBoard — it is never stored on the instance. When xlabel is None (the default) or an empty string, this line raises AttributeError: 'ProgressBoard' object has no attribute 'x'.

  2. The truthiness check if not self.xlabel treats an explicitly-supplied empty string "" as equivalent to None, unintentionally overwriting it.

Root cause

The fallback self.xlabel = self.x is a dead code remnant; x is a local parameter of draw() not a stored attribute. When xlabel is None the intent is simply to omit the axis label, not to substitute the numeric x-coordinate.

The same bug was fixed in d2l/jax.py by PR #2704/#2705 but those PRs only touched the JAX backend.

Fix

Guard both set_xlabel and set_ylabel with explicit is not None checks (matching the JAX fix) in all three remaining backends: torch.py, tensorflow.py, and mxnet.py.

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