Skip to content

Commit

Permalink
Merge pull request #1606 from AntonioCarta/qp
Browse files Browse the repository at this point in the history
Qp
  • Loading branch information
AntonioCarta authored Feb 27, 2024
2 parents f0b8481 + 6396b18 commit 49b7e4d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
7 changes: 5 additions & 2 deletions avalanche/training/plugins/gem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict
import numpy as np
import quadprog
import qpsolvers
import torch
from torch import Tensor
from torch.utils.data import DataLoader
Expand Down Expand Up @@ -171,7 +171,10 @@ def solve_quadprog(self, g):
q = np.dot(memories_np, gradient_np) * -1
G = np.eye(t)
h = np.zeros(t) + self.memory_strength
v = quadprog.solve_qp(P, q, G, h)[0]
# solution with old quadprog library, same as the author's implementation
# v = quadprog.solve_qp(P, q, G, h)[0]
# using new library qpsolvers
v = qpsolvers.solve_qp(P=P, q=-q, G=-G.transpose(), h=-h, solver="quadprog")
v_star = np.dot(v, memories_np) + gradient_np

return torch.from_numpy(v_star).float()
11 changes: 0 additions & 11 deletions docker/Dockerfile_dev
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
# syntax=docker/dockerfile:1

FROM nvcr.io/nvidia/pytorch:23.09-py3

# Needed for quadprog
RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*

ADD requirements.txt .

# RUN pip install virtualenv
# RUN python -m venv local_venv
# RUN source local_venv/bin/activate
RUN pip install -r requirements.txt

SHELL ["/bin/bash", "--login", "-c"]
7 changes: 0 additions & 7 deletions docker/nightly/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
# syntax=docker/dockerfile:1

FROM continualai/avalanche-test-3.9:latest

# Needed for quadprog
RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*

RUN echo "conda activate avalanche-env" >> ~/.bashrc
SHELL ["/bin/bash", "--login", "-c"]

RUN pip install git+https://github.com/ContinualAI/avalanche.git
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ torchmetrics
gdown
dill
packaging
quadprog @ git+https://github.com/HKaras/quadprog.git@690081f3285d4eb554394209473a274f230cd9ba
qpsolvers

0 comments on commit 49b7e4d

Please sign in to comment.