Skip to content

Commit

Permalink
chore: workaround upstream torch bug (#3321)
Browse files Browse the repository at this point in the history
setuptools 59.6.0 exposed a bug in pytorch, where pytorch is improperly
importing a particular submodule of distutils.  In old setuptools,
distutils.version was automatically imported, but in new setuptools, it
is not.  For details, see:

    pytorch/pytorch#69894

Since forcing users to upgrade pytorch is not feasible, we intervene by
enforcing that distutils.version is imported before we try to import the
problematic torch.utils.tensorboard submodule.  This workaround will not
help users who import torch.utils.tensorboard directly, but it will
protect users who only import torch.utils.tensorboard because of us.
  • Loading branch information
rb-determined-ai authored Dec 15, 2021
1 parent 0c12fe3 commit 355dcb8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion harness/determined/tensorboard/metric_writers/pytorch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from typing import Any, Union

import numpy as np
from torch.utils.tensorboard import SummaryWriter

from determined import tensorboard

# As of torch v1.9.0, torch.utils.tensorboard has a bug that is exposed by setuptools 59.6.0. The
# bug is that it attempts to import distutils then access distutils.version without actually
# importing distutils.version. We can workaround this by prepopulating the distutils.version
# submodule in the distutils module.
import distutils.version # isort:skip # noqa: F401
from torch.utils.tensorboard import SummaryWriter # isort:skip


class TorchWriter(tensorboard.MetricWriter):
"""
Expand Down

0 comments on commit 355dcb8

Please sign in to comment.