Skip to content

Commit

Permalink
update version with file + cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Mamalet committed Oct 14, 2024
1 parent 2cfa164 commit d7481a2
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/generic_bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ body:
description: |
examples:
- **OS**: linux
- **Python version**: 3.7
- **Python version**: 3.11
- **Packages used version**: PyTorch, Numpy, scikit-learn, etc..
value: |
- OS:
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include deel/torchlip/VERSION
include LICENSE
1 change: 1 addition & 0 deletions deel/torchlip/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.2
5 changes: 4 additions & 1 deletion deel/torchlip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
# =====================================================================================
# flake8: noqa

__version__ = "0.1.1"
from os import path

with open(path.join(path.dirname(__file__), "VERSION")) as f:
__version__ = f.read().strip()

from . import functional, init, normalizers, utils
from .modules import *
Expand Down
126 changes: 0 additions & 126 deletions deel/torchlip/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,33 +404,6 @@ def neg_kr_loss(
return -kr_loss(input, target, multi_gpu=multi_gpu)


# def neg_kr_loss_multi_gpu(
# input: torch.Tensor,
# target: torch.Tensor,
# ) -> torch.Tensor:
# """
# Loss to estimate the negative wasserstein-1 distance using Kantorovich-Rubinstein
# duality.

# `target` and `input` can be either of shape (batch_size, 1) or
# (batch_size, # classes).

# When using this loss function, the labels `target` must be pre-processed with the
# `process_labels_for_multi_gpu()` function.

# Args:
# input: Tensor of arbitrary shape.
# target: pre-processed Tensor of the same shape as input.

# Returns:
# The negative Wasserstein-1 loss between ``input`` and ``target``.

# See Also:
# :py:func:`kr_loss`
# """
# return -kr_loss_multi_gpu(input, target)


def hinge_margin_loss(
input: torch.Tensor,
target: torch.Tensor,
Expand Down Expand Up @@ -497,69 +470,6 @@ def hkr_loss(
) * kr_loss_fct(input, target)


# def hkr_loss_multi_gpu(
# input: torch.Tensor,
# target: torch.Tensor,
# alpha: float,
# min_margin: float = 1.0,
# ) -> torch.Tensor:
# """
# Loss to estimate the wasserstein-1 distance with a hinge regularization using
# Kantorovich-Rubinstein duality.

# Args:
# input: Tensor of arbitrary shape.
# target: Tensor of the same shape as input.
# alpha: Regularization factor between the hinge and the KR loss.
# min_margin: Minimal margin for the hinge loss.
# true_values: tuple containing the two label for each predicted class.

# Returns:
# The regularized Wasserstein-1 loss.

# See Also:
# :py:func:`hinge_margin_loss`
# :py:func:`kr_loss`
# """
# assert alpha <= 1.0
# if alpha == 1.0: # alpha for hinge only
# return hinge_margin_loss(input, target, min_margin)
# if alpha == 0:
# return -kr_loss_multi_gpu(input, target)
# # true value: positive value should be the first to be coherent with the
# # hinge loss (positive y_pred)
# return alpha * hinge_margin_loss(input, target, min_margin) - (
# 1 - alpha
# ) * kr_loss_multi_gpu(input, target)


# def kr_multiclass_loss(
# input: torch.Tensor,
# target: torch.Tensor,
# ) -> torch.Tensor:
# r"""
# Loss to estimate average of W1 distance using Kantorovich-Rubinstein
# duality over outputs. In this multiclass setup thr KR term is computed
# for each class and then averaged.

# Args:
# input: Tensor of arbitrary shape.
# target: Tensor of the same shape as input.
# target has to be one hot encoded (labels being 1s and 0s ).

# Returns:
# The Wasserstein multiclass loss between ``input`` and ``target``.
# """
# return kr_loss(input, target)
# # true_target = torch.where(target > 0, 1.0, 0.0).to(input.dtype)
# # esp_true_true = torch.sum(input * true_target, 0) / torch.sum(true_target, 0)
# # esp_false_true = torch.sum(input * (1 - true_target), 0) / torch.sum(
# # (1 - true_target), 0
# # )

# # return torch.mean(esp_true_true - esp_false_true)


def hinge_multiclass_loss(
input: torch.Tensor,
target: torch.Tensor,
Expand Down Expand Up @@ -629,42 +539,6 @@ def hkr_multiclass_loss(
) * kr_loss_fct(input, target)


# def hkr_multiclass_loss_multi_gpu(
# input: torch.Tensor,
# target: torch.Tensor,
# alpha: float = 0.0,
# min_margin: float = 1.0,
# ) -> torch.Tensor:
# """
# Loss to estimate the wasserstein-1 distance with a hinge regularization using
# Kantorovich-Rubinstein duality.

# Args:
# input: Tensor of arbitrary shape.
# target: Tensor of the same shape as input.
# alpha: Regularization factor between the hinge and the KR loss.
# min_margin: Minimal margin for the hinge loss.
# true_values: tuple containing the two label for each predicted class.

# Returns:
# The regularized Wasserstein-1 loss.

# See Also:
# :py:func:`hinge_margin_loss`
# :py:func:`kr_loss`
# """

# assert alpha <= 1.0
# if alpha == 1.0: # alpha hinge only
# return hinge_multiclass_loss(input, target, min_margin)
# elif alpha == 0.0: # alpha = 0 => KR only
# return -kr_loss_multi_gpu(input, target)
# else:
# return alpha * hinge_multiclass_loss(input, target, min_margin) - (
# 1 - alpha
# ) * kr_loss_multi_gpu(input, target)


def process_labels_for_multi_gpu(labels: torch.Tensor) -> torch.Tensor:
"""Process labels to be fed to any loss based on KR estimation with a multi-GPU/TPU
strategy.
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
with open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
long_description = f.read()

with open(path.join(this_directory, "deel/torchlip/VERSION")) as f:
version = f.read().strip()

dev_requires = ["tox", "black", "flake8", "flake8-black", "numpy", "torch_testing"]

docs_requires = [
Expand All @@ -49,7 +52,7 @@

setuptools.setup(
name="deel-torchlip",
version="0.1.1",
version=version,
author=", ".join(
[
"Mathieu SERRURIER",
Expand All @@ -74,7 +77,6 @@
packages=setuptools.find_namespace_packages(include=["deel.*"]),
install_requires=[
"numpy",
"inflection",
"torch",
],
license="MIT",
Expand Down
2 changes: 0 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ def test_warning_unsupported_1Lip_layers():
tActivation, {"activation": "gelu"}
), # kl.Activation("relu"),
]
# if version.parse(tf.__version__) >= version.parse("2.4.0"):
# unsupported_layers.append(kl.Activation("gelu"))

for lay in unsupported_layers:
if lay is not None:
Expand Down

0 comments on commit d7481a2

Please sign in to comment.