Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
User authored and d-ochs committed Dec 18, 2024
0 parents commit 5afe094
Show file tree
Hide file tree
Showing 53 changed files with 9,105 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#Environment file to specify workspace dir and API Keys
WORKSPACE_DIR="/workspaces/ASN_dev/AnswerSetNetworks"


#AIML cluster root
HF_HOME=/workspaces/ASN_dev/AnswerSetNetworks
HUGGINGFACE_HUB_CACHE=/workspaces/ASN_dev/AnswerSetNetworks

#42 cluster root
#HF_HOME=/pfss/mlde/workspaces/mlde_wsp_Multimodal_on_42/multimodal_changes/LLaVA-changes/hfcache
#HUGGINGFACE_HUB_CACHE=/pfss/mlde/workspaces/mlde_wsp_Multimodal_on_42/multimodal_changes/LLaVA-changes/hfcache

#wandb
WANDB_PROJECT=answer-set-networks
WANDB_API_KEY=cb7eae87a4af67e7866c061f0b05d574e98e9e82
HF_TOKEN=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

#OpenAI
#Manuel
OPENAI_API_KEY=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

#AIML
#OPENAI_API_KEY=sk-TI4p-AGQ3kOtU1wdq92ZQDADlIsA9yZ7bwDbjy9gCWT3BlbkFJhfk3wC4Uqbara_JoFw0_TW3vhNUg_fT3T66ZRC9VEA

#My own
# OPENAI_API_KEY=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

#perplexity
# OPENAI_API_KEY=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
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
__pycache__/
.ipynb_checkpoints/
*.egg-info/
experiments/logs/*
experiments/logs*/*
experiments/*logs/*
*/data/*
data/*
*/plots/*
build/
.vscode/
.devcontainer/
.hypothesis/
spin_up_containers.sh
hf/*
hfcache/*
**/checkpoints/**
**/wandb/**
install.sh
install_transformers.sh
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "GroundSLASH"]
path = GroundSLASH
url = [email protected]:pdeibert/GroundSLASH.git
ignore = untracked
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM nvcr.io/nvidia/pytorch:24.06-py3
WORKDIR "/asn"
COPY . .
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update

RUN echo "Upgrade pip"
RUN python -m pip install -U pip
RUN echo "Install torch==2.3.0 & dependencies..."
RUN python -m pip install torch==2.3.0 \
torchvision==0.18.0 \
torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121
RUN echo "Install torch_geometric==2.5.3 & dependencies..."
RUN python -m pip install pyg_lib \
torch_scatter \
torch_sparse \
torch_cluster \
torch_spline_conv -f https://data.pyg.org/whl/torch-2.3.0+cu121.html
RUN python -m pip install torch_geometric==2.5.3
RUN echo "Install ASN grounder"
WORKDIR "/asn/GroundSLASH/"
RUN python -m pip install -e .
WORKDIR "/asn"
RUN echo "Install Graphviz development libraries"
RUN apt-get update && apt-get install -y \
graphviz \
graphviz-dev \
pkg-config
RUN echo "Install ASN"
RUN python -m pip install -e .
RUN echo "All installations completed successfully!"
1 change: 1 addition & 0 deletions GroundSLASH
Submodule GroundSLASH added at a0b75d
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Answer Set Networks: Casting Answer Set Programming into Deep Learning
Arseny Skryagin, Daniel Ochs, Philipp Deibert, Simon Kohaut, Devendra Singh Dhami , Kristian Kersting
<div style="text-align:center">

![Fancy logo](./imgs/logo_dark.png#gh-dark-mode-only)
![Fancy logo](./imgs/logo_light.png#gh-light-mode-only)

</div>

[![MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)


# Abstract
Although Answer Set Programming (ASP) allows constraining neural-symbolic (NeSy) systems, its employment is hindered by the prohibitive costs of computing stable models and the CPU-bound nature of state-of-the-art solvers.
To this end, we propose Answer Set Networks (ASN), a NeSy solver.
Based on Graph Neural Networks (GNN), ASNs are a scalable approach to ASP-based Deep Probabilistic Logic Programming (DPPL).
Specifically, we show how to translate ASPs into ASNs and demonstrate how ASNs can efficiently solve the encoded problem by leveraging GPU's batching and parallelization capabilities.
Our experimental evaluations demonstrate that ASNs outperform state-of-the-art CPU-bound NeSy systems on multiple tasks.
Simultaneously, we make the following two contributions based on the strengths of ASNs.
Namely, we are the first to show the finetuning of Large Language Models (LLM) with DPPLs, employing ASNs to guide the training with logic.
Further, we show the "constitutional navigation" of drones, i.e., encoding public aviation laws in an ASN for routing Unmanned Aerial Vehicles in uncertain environments.




# Installation

### Environment
First you need a PyTorch environment. You can either use our prebuilt docker container available on the docker hub (see [hansiwusti/asn:1.0](https://hub.docker.com/r/hansiwusti/asn)) or create an environment yourself. For this we provided a `Dockerfile` and the `pyproject.toml`. Note that we found the environment with PyTorch==2.3.0 and PyTorch Geometric==2.5.3 to work well, but you may need to select a PyTorch version which fits to your own GPU/Cuda environment.

### Cloning the repo and ASP Grrounder
After setting up your environment you need to install ASN and a grounder. We use the GroundSlash grounder from https://github.com/pdeibert/GroundSLASH for ASN.

Start by cloning the ASN and Grounder repositories
```
git clone [email protected]:pdeibert/AnswerSetNetworks.git
cd AnswerSetNetworks/
git clone [email protected]:pdeibert/GroundSLASH.git
```

Then install all python modules using:
```
python -m pip install --upgrade pip
python -m pip install -e .
python -m pip install ./GroundSLASH
```
This will also install PyTorch and other requirements if not installed yet.

### LLMs in ASN
if you want to use ASN to train LLMs you have to install additional packages (Huggingface transformers, wandb, ...). In your project root run:
```
python -m pip install .[transformer_libs]
```


# Run ASN
We put together a folder containing all experiment scripts in '/experiments/scripts'.
To start ASN for MNIST addition with two images you can run:
```
. experiments/scripts/mnist_add.sh
```
This script will provide you with a good starting point to explore all python args. Also you can check out the other scripts in the folder to get an idea of how to start ASN for other experiments. The script will call the mnist_addition.py which exemplifies how to connect your PyTorch models to NPP objects, create a dataloader with Constraint as your labels and calls the ASN forward and backward pass.
Loading

0 comments on commit 5afe094

Please sign in to comment.