libsdca 0.3.0__py3-none-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. libsdca/__init__.py +142 -0
  2. libsdca/_core.py +1884 -0
  3. libsdca/_cpu.py +1110 -0
  4. libsdca/_cpu_entropy.py +146 -0
  5. libsdca/_cross_entropy.py +650 -0
  6. libsdca/_cuda_launch.py +235 -0
  7. libsdca/_entropy.py +268 -0
  8. libsdca/_extensions.py +315 -0
  9. libsdca/_first_order.py +50 -0
  10. libsdca/_hinge.py +98 -0
  11. libsdca/_jax_ffi.cpp +253 -0
  12. libsdca/_jax_ffi.py +221 -0
  13. libsdca/_jax_losses.py +1235 -0
  14. libsdca/_libsdca_native.cpython-312-darwin.so +0 -0
  15. libsdca/_linear_cross_entropy.py +1014 -0
  16. libsdca/_linear_full_range.py +81 -0
  17. libsdca/_multilabel.py +188 -0
  18. libsdca/_ops.py +565 -0
  19. libsdca/_tensor_losses.py +520 -0
  20. libsdca/_tensor_prox.py +446 -0
  21. libsdca/_topk.py +104 -0
  22. libsdca/_torch_ce.h +832 -0
  23. libsdca/_torch_cuda.h +771 -0
  24. libsdca/_torch_distill.h +1627 -0
  25. libsdca/_torch_distributed.py +76 -0
  26. libsdca/_torch_entropy.cpp +427 -0
  27. libsdca/_torch_lanes.h +1123 -0
  28. libsdca/_torch_prox.h +1157 -0
  29. libsdca/_torch_topk_hinge.h +1822 -0
  30. libsdca/_triton_distillation.py +1715 -0
  31. libsdca/_triton_entropy.py +601 -0
  32. libsdca/_triton_hinge.py +363 -0
  33. libsdca/_triton_linear.py +30 -0
  34. libsdca/_triton_multilabel.py +1101 -0
  35. libsdca/_triton_prox.py +866 -0
  36. libsdca/_triton_reduce.py +187 -0
  37. libsdca/_triton_topk.py +1070 -0
  38. libsdca/_triton_weighted_entropy.py +388 -0
  39. libsdca/jax.py +1335 -0
  40. libsdca/py.typed +0 -0
  41. libsdca/sklearn.py +205 -0
  42. libsdca/torch.py +1978 -0
  43. libsdca-0.3.0.dist-info/METADATA +205 -0
  44. libsdca-0.3.0.dist-info/RECORD +47 -0
  45. libsdca-0.3.0.dist-info/WHEEL +6 -0
  46. libsdca-0.3.0.dist-info/licenses/LICENSE +22 -0
  47. libsdca-0.3.0.dist-info/top_level.txt +1 -0
libsdca/__init__.py ADDED
@@ -0,0 +1,142 @@
1
+ """SDCA solvers and classification losses.
2
+
3
+ NumPy:
4
+ fit, loss_and_grad, coordinate_update, Model; Solver for another
5
+ precision or library.
6
+ scikit-learn (imported on first use; needs scikit-learn):
7
+ SDCAClassifier (libsdca.sklearn).
8
+ PyTorch (imported on first use; needs torch):
9
+ CrossEntropyLoss, TopKCrossEntropyLoss, MulticlassHingeLoss, TopKHingeLoss
10
+ (TopKHingeAlphaLoss, TopKHingeBetaLoss), MultilabelCrossEntropyLoss,
11
+ MultilabelHingeLoss, ProximalCrossEntropyLoss, DistillationLoss,
12
+ ProximalDistillationLoss, SDCALoss, and their functions (cross_entropy, ...).
13
+ JAX (import libsdca.jax; needs jax):
14
+ sdca_loss, distillation_loss and the loss functions above.
15
+ Names: LOSSES, OBJECTIVES (the trainable LOSSES), their subsets TOPK, HINGES
16
+ and MULTILABEL, PRECISIONS, HISTORY (Model.history fields) and STATUS
17
+ (Model.status values); array types FloatArray, IndexArray and Targets.
18
+
19
+ Arrays use conventional Python layouts: X (n,d), W (d,m), A (n,m) for m classes.
20
+ Objective = 0.5*||W||^2 + C*sum_i loss(X[i]@W, y[i]).
21
+ No implicit intercept; append a constant feature for a regularized intercept.
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ from importlib import import_module
27
+ from typing import TYPE_CHECKING, Any
28
+
29
+ from ._core import (
30
+ HINGES,
31
+ HISTORY,
32
+ LOSSES,
33
+ MULTILABEL,
34
+ OBJECTIVES,
35
+ PRECISIONS,
36
+ STATUS,
37
+ TOPK,
38
+ FloatArray,
39
+ IndexArray,
40
+ Model,
41
+ Solver,
42
+ Targets,
43
+ coordinate_update,
44
+ distillation_loss_and_grad,
45
+ fit,
46
+ loss_and_grad,
47
+ proximal_distillation_loss_and_grad,
48
+ )
49
+
50
+ if TYPE_CHECKING:
51
+ from .sklearn import SDCAClassifier as SDCAClassifier
52
+ from .torch import CrossEntropyLoss as CrossEntropyLoss
53
+ from .torch import DistillationLoss as DistillationLoss
54
+ from .torch import LinearCrossEntropyLoss as LinearCrossEntropyLoss
55
+ from .torch import MulticlassHingeLoss as MulticlassHingeLoss
56
+ from .torch import MultilabelCrossEntropyLoss as MultilabelCrossEntropyLoss
57
+ from .torch import MultilabelHingeLoss as MultilabelHingeLoss
58
+ from .torch import ProximalCrossEntropyLoss as ProximalCrossEntropyLoss
59
+ from .torch import ProximalDistillationLoss as ProximalDistillationLoss
60
+ from .torch import SDCALoss as SDCALoss
61
+ from .torch import TopKCrossEntropyLoss as TopKCrossEntropyLoss
62
+ from .torch import TopKHingeAlphaLoss as TopKHingeAlphaLoss
63
+ from .torch import TopKHingeBetaLoss as TopKHingeBetaLoss
64
+ from .torch import TopKHingeLoss as TopKHingeLoss
65
+ from .torch import cross_entropy as cross_entropy
66
+ from .torch import distillation_loss as distillation_loss
67
+ from .torch import linear_cross_entropy as linear_cross_entropy
68
+ from .torch import multiclass_hinge_loss as multiclass_hinge_loss
69
+ from .torch import multilabel_cross_entropy as multilabel_cross_entropy
70
+ from .torch import multilabel_hinge_loss as multilabel_hinge_loss
71
+ from .torch import proximal_cross_entropy as proximal_cross_entropy
72
+ from .torch import proximal_distillation_loss as proximal_distillation_loss
73
+ from .torch import sdca_loss as sdca_loss
74
+ from .torch import topk_cross_entropy as topk_cross_entropy
75
+ from .torch import topk_hinge_alpha_loss as topk_hinge_alpha_loss
76
+ from .torch import topk_hinge_beta_loss as topk_hinge_beta_loss
77
+ from .torch import topk_hinge_loss as topk_hinge_loss
78
+
79
+ __version__ = "0.3.0"
80
+ # Names of the optional submodules, imported on first use.
81
+ _LAZY = {
82
+ "SDCAClassifier": ".sklearn",
83
+ "CrossEntropyLoss": ".torch",
84
+ "DistillationLoss": ".torch",
85
+ "LinearCrossEntropyLoss": ".torch",
86
+ "MulticlassHingeLoss": ".torch",
87
+ "MultilabelCrossEntropyLoss": ".torch",
88
+ "MultilabelHingeLoss": ".torch",
89
+ "ProximalCrossEntropyLoss": ".torch",
90
+ "ProximalDistillationLoss": ".torch",
91
+ "SDCALoss": ".torch",
92
+ "TopKCrossEntropyLoss": ".torch",
93
+ "TopKHingeAlphaLoss": ".torch",
94
+ "TopKHingeBetaLoss": ".torch",
95
+ "TopKHingeLoss": ".torch",
96
+ "cross_entropy": ".torch",
97
+ "distillation_loss": ".torch",
98
+ "linear_cross_entropy": ".torch",
99
+ "multiclass_hinge_loss": ".torch",
100
+ "multilabel_cross_entropy": ".torch",
101
+ "multilabel_hinge_loss": ".torch",
102
+ "proximal_cross_entropy": ".torch",
103
+ "proximal_distillation_loss": ".torch",
104
+ "sdca_loss": ".torch",
105
+ "topk_cross_entropy": ".torch",
106
+ "topk_hinge_alpha_loss": ".torch",
107
+ "topk_hinge_beta_loss": ".torch",
108
+ "topk_hinge_loss": ".torch",
109
+ }
110
+
111
+ # The lazy names stay out of __all__: a star import must not need torch.
112
+ __all__ = [
113
+ "HINGES",
114
+ "HISTORY",
115
+ "LOSSES",
116
+ "MULTILABEL",
117
+ "OBJECTIVES",
118
+ "PRECISIONS",
119
+ "STATUS",
120
+ "TOPK",
121
+ "FloatArray",
122
+ "IndexArray",
123
+ "Model",
124
+ "Solver",
125
+ "Targets",
126
+ "coordinate_update",
127
+ "distillation_loss_and_grad",
128
+ "fit",
129
+ "loss_and_grad",
130
+ "proximal_distillation_loss_and_grad",
131
+ ]
132
+
133
+
134
+ def __getattr__(name: str) -> Any:
135
+ # The scikit-learn and PyTorch layers import their framework only when used.
136
+ if name in _LAZY:
137
+ return getattr(import_module(_LAZY[name], __name__), name)
138
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
139
+
140
+
141
+ def __dir__() -> list[str]:
142
+ return sorted(set(globals()) | set(_LAZY))