Skip to content

Commit

Permalink
[examples] better PL version check (huggingface#8429)
Browse files Browse the repository at this point in the history
  • Loading branch information
stas00 authored and fabiocapsouza committed Nov 15, 2020
1 parent 3c67702 commit 4c7582c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions examples/lightning_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from typing import Any, Dict

import packaging
import pytorch_lightning as pl
from pytorch_lightning.utilities import rank_zero_info

Expand Down Expand Up @@ -33,15 +34,17 @@

logger = logging.getLogger(__name__)

try:
pkg = "pytorch_lightning"
min_ver = "1.0.4"
pkg_resources.require(f"{pkg}>={min_ver}")
except pkg_resources.VersionConflict:
logger.warning(
f"{pkg}>={min_ver} is required for a normal functioning of this module, but found {pkg}=={pkg_resources.get_distribution(pkg).version}. Try pip install -r examples/requirements.txt"
)

def require_min_ver(pkg, min_ver):
got_ver = pkg_resources.get_distribution(pkg).version
if packaging.version.parse(got_ver) < packaging.version.parse(min_ver):
logger.warning(
f"{pkg}>={min_ver} is required for a normal functioning of this module, but found {pkg}=={got_ver}. "
"Try: pip install -r examples/requirements.txt"
)


require_min_ver("pytorch_lightning", "1.0.4")

MODEL_MODES = {
"base": AutoModel,
Expand Down

0 comments on commit 4c7582c

Please sign in to comment.