Skip to content

Commit

Permalink
Merge branch 'main' of github.com:simplymathematics/deckard into repr…
Browse files Browse the repository at this point in the history
…oduce
  • Loading branch information
simplymathematics committed Nov 28, 2023
2 parents 34e2c57 + 6cb0fce commit 97aafe7
Show file tree
Hide file tree
Showing 254 changed files with 83,396 additions and 1,336 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ RUN apt-get install -y python3 python3-distutils python3-pip ffmpeg libavcodec-e
RUN python3 -m pip install nvidia-pyindex nvidia-cuda-runtime-cu11
RUN git clone https://github.com/simplymathematics/deckard.git
WORKDIR /deckard
RUN python3 -m pip install --editable .[torch,torchvision,tensorflow]
RUN python3 -m pip install pytest
RUN python3 -m pip install --editable .
RUN python3 -m pip install pytest torch torchvision tensorflow
RUN git clone https://github.com/Trusted-AI/adversarial-robustness-toolbox.git
RUN cd adversarial-robustness-toolbox && python3 -m pip install .
RUN apt install python-is-python3
RUN pytest test
32 changes: 3 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,9 @@ Running `dvc repro` in that folder will reproduce the experiment outlined in the
├── setup.sh : for installation using bash
└── test : test suite


###

To build the package (optional and is a very rough draft):

```
######################################
# Ubuntu 22.04, 20.04
sudo apt update
sudo apt install python3-venv python3-pip python3-dev python3-setuptools
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.9 -y
sudo apt install msttcorefonts -qqpython3-distutils #fonts (optional)
export SETUPTOOLS_USE_DISTUTILS=stdlib
######################################
python3 -m venv env
source env/bin/activate
git clone --recurse-submodules -j8 https://github.com/simplymathematics/deckard.git
# git submodule update --init --recursive # To just update the submodules
python3 -m pip install deckard/adversarial-robustness-toolbox/
python3 -m pip install -e deckard/
python3 -m pip install pyinstaller
python3 -m pip install -u numba pip setuptools
cd deckard && pyinstaller --onefile deckard.py -n deckard
```

After adding it to your path, you can then run deckard like a package:
After adding it to your path, you can then run it as a module:

```
deckard examples/sklearn
cd examples/power
python -m deckard --config_name mnist.yaml
```
24 changes: 24 additions & 0 deletions build_instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

To build the package (optional and is a very rough draft):

```
######################################
# Ubuntu 22.04, 20.04
sudo apt update
sudo apt install python3-venv python3-pip python3-dev python3-setuptools
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.9 -y
sudo apt install msttcorefonts -qqpython3-distutils #fonts (optional)
export SETUPTOOLS_USE_DISTUTILS=stdlib
######################################
python3 -m venv env
source env/bin/activate
git clone --recurse-submodules -j8 https://github.com/simplymathematics/deckard.git
# git submodule update --init --recursive # To just update the submodules
python3 -m pip install deckard/adversarial-robustness-toolbox/
python3 -m pip install -e deckard/
python3 -m pip install pyinstaller
python3 -m pip install -u numba pip setuptools
cd deckard && pyinstaller --onefile deckard.py -n deckard
```
15 changes: 14 additions & 1 deletion deckard.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,18 @@
"python.envFile": "${workspaceFolder}/.env",
"yaml.schemas": {
"https://raw.githubusercontent.com/iterative/dvcyaml-schema/master/schema.json": ["dvc.yaml"] }
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-toolsai.jupyter",
]
}
},
"features": {
"ghcr.io/devcontainers/features/nvidia-cuda:1": {
"installCudnn": true
}
},
}
2 changes: 1 addition & 1 deletion deckard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# from deckard import layers # noqa: F401

# Semantic Version
__version__ = "0.630"
__version__ = "0.70"

# pylint: disable=C0103

Expand Down
36 changes: 30 additions & 6 deletions deckard/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import subprocess
import logging
from pathlib import Path
from omegaconf import OmegaConf
from .layers.parse import save_params_file

OmegaConf.register_new_resolver("eval", eval)

logger = logging.getLogger(__name__)
layer_list = list(Path(Path(__file__).parent, "layers").glob("*.py"))
layer_list = [layer.stem for layer in layer_list]
if "__init__" in layer_list:
layer_list.remove("__init__")
layer_list.append(None)


def run_submodule(submodule, args):
Expand All @@ -36,12 +40,20 @@ def run_submodule(submodule, args):
return 0


def parse_and_repro(args):
def parse_and_repro(args, default_config="default.yaml", config_dir="conf"):
if len(args) == 0:
assert save_params_file(config_dir=Path(Path(), "conf")) is None
assert (
save_params_file(
config_dir=Path(Path(), config_dir)
if not Path(config_dir).is_absolute()
else Path(config_dir),
config_file=default_config,
)
is None
)
assert Path(Path(), "params.yaml").exists()
else:
cmd = f"python -m deckard.layers.parse {args}"
cmd = f"python -m deckard.layers.parse {args} --config_file {default_config}"
# error = f"error parsing command: {cmd} {args}"
with subprocess.Popen(
cmd,
Expand All @@ -65,21 +77,33 @@ def parse_and_repro(args):
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument(
"submodule",
"--submodule",
type=str,
nargs="?",
help=f"Submodule to run. Choices: {layer_list}",
)
parser.add_argument(
"--config_file",
type=str,
help="default hydra configuration file that you would like to reproduce with dvc repro.",
)
parser.add_argument("--config_dir", type=str, default="conf")
parser.add_argument("other_args", type=str, nargs="*")
args = parser.parse_args()
submodule = args.submodule
if submodule is not None:
assert (
args.config_file is None
), "config_file and submodule cannot be specified at the same time"
if submodule not in layer_list and submodule is not None:
raise ValueError(f"Submodule {submodule} not found. Choices: {layer_list}")
if len(args.other_args) > 0:
other_args = " ".join(args.other_args)
else:
other_args = []
if submodule is None:
assert parse_and_repro(other_args) == 0
assert (
parse_and_repro(other_args, args.config_file, config_dir=args.config_dir)
== 0
)
else:
assert run_submodule(submodule, other_args) == 0
Loading

0 comments on commit 97aafe7

Please sign in to comment.