Skip to content

Commit

Permalink
Update setup.py: Make more requirements optional (#4133)
Browse files Browse the repository at this point in the history
* Move yacs, hydra-core, class-resolver, and googledrivedownloader to full_install

* minimal installation action

* typo

* do not install in dev mode

* optional yacs

* fix import

* typo

Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
  • Loading branch information
adelizer and rusty1s authored Feb 25, 2022
1 parent e7f47a8 commit cd04dd2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 22 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Minimal Installation

on: # yamllint disable-line rule:truthy
push:
branches:
- master
pull_request:

jobs:

import:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.9]
torch-version: [1.10.0]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install PyTorch ${{ matrix.torch-version }}+cpu
run: |
pip install torch==${{ matrix.torch-version}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
- name: Install internal dependencies
run: |
pip install torch-scatter -f https://data.pyg.org/whl/torch-${{ matrix.torch-version }}+cpu.html
pip install torch-sparse -f https://data.pyg.org/whl/torch-${{ matrix.torch-version }}+cpu.html
- name: Install main package
run: |
pip install .
- name: Test imports
run: |
python -c "import torch_geometric"
python -c "import torch_geometric.datasets"
python -c "import torch_geometric.nn"
python -c "import torch_geometric.graphgym"
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@

install_requires = [
'tqdm',
'yacs',
'numpy',
'scipy',
'pandas',
'jinja2',
'requests',
'pyparsing',
'hydra-core',
'scikit-learn',
'class-resolver>=0.3.2',
'googledrivedownloader',
]

full_install_requires = [
'h5py',
'yacs',
'numba',
'captum',
'rdflib',
'trimesh',
'networkx',
'tabulate',
'hydra-core',
'matplotlib',
'scikit-image',
'pytorch-memlab',
'class-resolver>=0.3.2',
'googledrivedownloader',
]

test_requires = [
Expand Down
14 changes: 10 additions & 4 deletions torch_geometric/graphgym/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
import logging
import os
import shutil
import warnings
from collections.abc import Iterable
from dataclasses import asdict
from typing import Any

from yacs.config import CfgNode as CN

import torch_geometric.graphgym.register as register
from torch_geometric.data.makedirs import makedirs

# Global config object
cfg = CN()
try: # Define global config object
from yacs.config import CfgNode as CN
cfg = CN()
except ImportError:
cfg = None
warnings.warn("Could not define global config object. Please install "
"'yacs' for using the GraphGym experiment manager.")


def set_cfg(cfg):
Expand All @@ -26,6 +30,8 @@ def set_cfg(cfg):
:return: configuration use by the experiment.
'''
if cfg is None:
return cfg

# ----------------------------------------------------------------------- #
# Basic options
Expand Down
15 changes: 8 additions & 7 deletions torch_geometric/graphgym/models/act.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from torch_geometric.graphgym.config import cfg
from torch_geometric.graphgym.register import register_act

register_act('relu', nn.ReLU(inplace=cfg.mem.inplace))
register_act('selu', nn.SELU(inplace=cfg.mem.inplace))
register_act('prelu', nn.PReLU())
register_act('elu', nn.ELU(inplace=cfg.mem.inplace))
register_act('lrelu_01', nn.LeakyReLU(0.1, inplace=cfg.mem.inplace))
register_act('lrelu_025', nn.LeakyReLU(0.25, inplace=cfg.mem.inplace))
register_act('lrelu_05', nn.LeakyReLU(0.5, inplace=cfg.mem.inplace))
if cfg is not None:
register_act('relu', nn.ReLU(inplace=cfg.mem.inplace))
register_act('selu', nn.SELU(inplace=cfg.mem.inplace))
register_act('prelu', nn.PReLU())
register_act('elu', nn.ELU(inplace=cfg.mem.inplace))
register_act('lrelu_01', nn.LeakyReLU(0.1, inplace=cfg.mem.inplace))
register_act('lrelu_025', nn.LeakyReLU(0.25, inplace=cfg.mem.inplace))
register_act('lrelu_05', nn.LeakyReLU(0.5, inplace=cfg.mem.inplace))
5 changes: 0 additions & 5 deletions torch_geometric/graphgym/models/gnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,3 @@ def forward(self, batch):
for module in self.children():
batch = module(batch)
return batch

if cfg.benchmark:
# register to measure the forward pass
from torch_geometric.graphgym.benchmark import global_line_profiler
global_line_profiler.add_function(forward)
4 changes: 2 additions & 2 deletions torch_geometric/graphgym/utils/comp_budget.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import math

from yacs.config import CfgNode as CN

from torch_geometric.graphgym.config import cfg, set_cfg
from torch_geometric.graphgym.model_builder import create_model

Expand Down Expand Up @@ -60,6 +58,7 @@ def match_computation(stats_baseline, key=['gnn', 'dim_inner'], mode='sqrt'):


def dict_to_stats(cfg_dict):
from yacs.config import CfgNode as CN
set_cfg(cfg)
cfg_new = CN(cfg_dict)
cfg.merge_from_other_cfg(cfg_new)
Expand All @@ -80,6 +79,7 @@ def match_baseline_cfg(cfg_dict, cfg_dict_baseline, verbose=True):
'''
from yacs.config import CfgNode as CN
stats_baseline = dict_to_stats(cfg_dict_baseline)
set_cfg(cfg)
cfg_new = CN(cfg_dict)
Expand Down

0 comments on commit cd04dd2

Please sign in to comment.