Rank Zero Property Mixin
🚀 Feature
This is an alternative to the change proposed in #1408 in case the global variable approach doesn't work.
I propose to add a mixin class for the rank property, e.g., named RankZeroPropertyMixin
Motivation
There are some parts of the code base that use a rank property in combination with the @rank_zero_only decorator. Refactoring this into a mixin would avoid code duplication and it would make it straightforward to add to a new callback for example.
PR #1408 already solves the problem of code duplication.
Pitch
class RankZeroPropertyMixin:
    def __init__(self):
        self._rank = 0

    @property
    def rank(self) -> int:
        return self._rank

    @rank.setter
    def rank(self, value: int) -> None:
        self._rank = value
In the Trainer init or distributed_parts, we will check each callback, logger for the rank property and set it to the appropriate value.
Then, when we add a new callback:
class NewFancyCallback(RankZeroPropertyMixin, Callback):
    def __init__(self):
        ...

    @rank_zero_only
    def on_train_start():
        print('only on rank 0')
This does not just apply to callbacks of course, could be added to Logger, etc.
Alternatives
Leave as is or go with #1408. In the future, Lightning will probably add more callbacks and features that are restricted to rank 0, so it would lead to code duplication.