ZTWHHH commited on
Commit
ab3bfca
·
verified ·
1 Parent(s): 02a6931

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. videollama2/lib/python3.10/site-packages/sklearn/decomposition/__pycache__/_dict_learning.cpython-310.pyc +0 -0
  2. videollama2/lib/python3.10/site-packages/sklearn/decomposition/__pycache__/_nmf.cpython-310.pyc +0 -0
  3. videollama2/lib/python3.10/site-packages/sklearn/decomposition/__pycache__/_pca.cpython-310.pyc +0 -0
  4. videollama2/lib/python3.10/site-packages/sklearn/decomposition/__pycache__/_truncated_svd.cpython-310.pyc +0 -0
  5. videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/__pycache__/test_fastica.cpython-310.pyc +0 -0
  6. videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/__pycache__/test_kernel_pca.cpython-310.pyc +0 -0
  7. videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/__pycache__/test_nmf.cpython-310.pyc +0 -0
  8. videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/__pycache__/test_sparse_pca.cpython-310.pyc +0 -0
  9. videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/__pycache__/test_truncated_svd.cpython-310.pyc +0 -0
  10. videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/test_kernel_pca.py +525 -0
  11. videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/test_nmf.py +908 -0
  12. videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/test_truncated_svd.py +213 -0
  13. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_cast_Double_native.h +21 -0
  14. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_cummin_helper_cpu_dispatch.h +23 -0
  15. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_debug_has_internal_overlap_native.h +21 -0
  16. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_ceil.h +44 -0
  17. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_erf_ops.h +50 -0
  18. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_norm.h +39 -0
  19. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_round_compositeexplicitautograd_dispatch.h +26 -0
  20. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_functional_assert_scalar_ops.h +28 -0
  21. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_histogramdd_bin_edges.h +39 -0
  22. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_log_softmax_cpu_dispatch.h +25 -0
  23. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_sample_dirichlet_ops.h +39 -0
  24. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_sobol_engine_ff.h +30 -0
  25. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_sparse_log_softmax_backward_data_native.h +23 -0
  26. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_test_optional_intlist.h +39 -0
  27. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_to_sparse_csr_native.h +24 -0
  28. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_upsample_bicubic2d_aa_backward_native.h +26 -0
  29. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_int4pack_mm.h +30 -0
  30. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_norm_differentiable_backward_compositeimplicitautograd_dispatch.h +23 -0
  31. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_norm_interface_backward_cpu_dispatch.h +23 -0
  32. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_norm_interface_backward_native.h +23 -0
  33. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/absolute_compositeimplicitautograd_dispatch.h +26 -0
  34. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/alias.h +30 -0
  35. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/amax_cuda_dispatch.h +25 -0
  36. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/atleast_1d.h +35 -0
  37. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/chalf_native.h +21 -0
  38. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/column_stack_compositeimplicitautograd_dispatch.h +25 -0
  39. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/conv2d.h +69 -0
  40. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/cumsum_meta.h +27 -0
  41. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/diag_embed_ops.h +39 -0
  42. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/embedding_ops.h +39 -0
  43. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/gcd_meta.h +27 -0
  44. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/hardsigmoid_backward_ops.h +39 -0
  45. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/hinge_embedding_loss.h +30 -0
  46. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/isreal_ops.h +28 -0
  47. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/kron_native.h +22 -0
  48. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/le_ops.h +83 -0
  49. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/linalg_diagonal_ops.h +28 -0
  50. vllm/lib/python3.10/site-packages/torch/include/ATen/ops/logical_or_cuda_dispatch.h +24 -0
videollama2/lib/python3.10/site-packages/sklearn/decomposition/__pycache__/_dict_learning.cpython-310.pyc ADDED
Binary file (65.9 kB). View file
 
videollama2/lib/python3.10/site-packages/sklearn/decomposition/__pycache__/_nmf.cpython-310.pyc ADDED
Binary file (61 kB). View file
 
videollama2/lib/python3.10/site-packages/sklearn/decomposition/__pycache__/_pca.cpython-310.pyc ADDED
Binary file (20.6 kB). View file
 
videollama2/lib/python3.10/site-packages/sklearn/decomposition/__pycache__/_truncated_svd.cpython-310.pyc ADDED
Binary file (10.7 kB). View file
 
videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/__pycache__/test_fastica.cpython-310.pyc ADDED
Binary file (12.5 kB). View file
 
videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/__pycache__/test_kernel_pca.cpython-310.pyc ADDED
Binary file (14.9 kB). View file
 
videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/__pycache__/test_nmf.cpython-310.pyc ADDED
Binary file (20.4 kB). View file
 
videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/__pycache__/test_sparse_pca.cpython-310.pyc ADDED
Binary file (10.7 kB). View file
 
videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/__pycache__/test_truncated_svd.cpython-310.pyc ADDED
Binary file (5.91 kB). View file
 
videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/test_kernel_pca.py ADDED
@@ -0,0 +1,525 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import scipy.sparse as sp
3
+ import pytest
4
+ import warnings
5
+
6
+ from sklearn.utils._testing import (
7
+ assert_array_almost_equal,
8
+ assert_array_equal,
9
+ assert_allclose,
10
+ )
11
+
12
+ from sklearn.decomposition import PCA, KernelPCA
13
+ from sklearn.datasets import make_circles
14
+ from sklearn.datasets import make_blobs
15
+ from sklearn.exceptions import NotFittedError
16
+ from sklearn.linear_model import Perceptron
17
+ from sklearn.pipeline import Pipeline
18
+ from sklearn.preprocessing import StandardScaler
19
+ from sklearn.model_selection import GridSearchCV
20
+ from sklearn.metrics.pairwise import rbf_kernel
21
+ from sklearn.utils.validation import _check_psd_eigenvalues
22
+
23
+
24
+ def test_kernel_pca():
25
+ """Nominal test for all solvers and all known kernels + a custom one
26
+
27
+ It tests
28
+ - that fit_transform is equivalent to fit+transform
29
+ - that the shapes of transforms and inverse transforms are correct
30
+ """
31
+ rng = np.random.RandomState(0)
32
+ X_fit = rng.random_sample((5, 4))
33
+ X_pred = rng.random_sample((2, 4))
34
+
35
+ def histogram(x, y, **kwargs):
36
+ # Histogram kernel implemented as a callable.
37
+ assert kwargs == {} # no kernel_params that we didn't ask for
38
+ return np.minimum(x, y).sum()
39
+
40
+ for eigen_solver in ("auto", "dense", "arpack", "randomized"):
41
+ for kernel in ("linear", "rbf", "poly", histogram):
42
+ # histogram kernel produces singular matrix inside linalg.solve
43
+ # XXX use a least-squares approximation?
44
+ inv = not callable(kernel)
45
+
46
+ # transform fit data
47
+ kpca = KernelPCA(
48
+ 4, kernel=kernel, eigen_solver=eigen_solver, fit_inverse_transform=inv
49
+ )
50
+ X_fit_transformed = kpca.fit_transform(X_fit)
51
+ X_fit_transformed2 = kpca.fit(X_fit).transform(X_fit)
52
+ assert_array_almost_equal(
53
+ np.abs(X_fit_transformed), np.abs(X_fit_transformed2)
54
+ )
55
+
56
+ # non-regression test: previously, gamma would be 0 by default,
57
+ # forcing all eigenvalues to 0 under the poly kernel
58
+ assert X_fit_transformed.size != 0
59
+
60
+ # transform new data
61
+ X_pred_transformed = kpca.transform(X_pred)
62
+ assert X_pred_transformed.shape[1] == X_fit_transformed.shape[1]
63
+
64
+ # inverse transform
65
+ if inv:
66
+ X_pred2 = kpca.inverse_transform(X_pred_transformed)
67
+ assert X_pred2.shape == X_pred.shape
68
+
69
+
70
+ def test_kernel_pca_invalid_parameters():
71
+ """Check that kPCA raises an error if the parameters are invalid
72
+
73
+ Tests fitting inverse transform with a precomputed kernel raises a
74
+ ValueError.
75
+ """
76
+ estimator = KernelPCA(
77
+ n_components=10, fit_inverse_transform=True, kernel="precomputed"
78
+ )
79
+ err_ms = "Cannot fit_inverse_transform with a precomputed kernel"
80
+ with pytest.raises(ValueError, match=err_ms):
81
+ estimator.fit(np.random.randn(10, 10))
82
+
83
+
84
+ def test_kernel_pca_consistent_transform():
85
+ """Check robustness to mutations in the original training array
86
+
87
+ Test that after fitting a kPCA model, it stays independent of any
88
+ mutation of the values of the original data object by relying on an
89
+ internal copy.
90
+ """
91
+ # X_fit_ needs to retain the old, unmodified copy of X
92
+ state = np.random.RandomState(0)
93
+ X = state.rand(10, 10)
94
+ kpca = KernelPCA(random_state=state).fit(X)
95
+ transformed1 = kpca.transform(X)
96
+
97
+ X_copy = X.copy()
98
+ X[:, 0] = 666
99
+ transformed2 = kpca.transform(X_copy)
100
+ assert_array_almost_equal(transformed1, transformed2)
101
+
102
+
103
+ def test_kernel_pca_deterministic_output():
104
+ """Test that Kernel PCA produces deterministic output
105
+
106
+ Tests that the same inputs and random state produce the same output.
107
+ """
108
+ rng = np.random.RandomState(0)
109
+ X = rng.rand(10, 10)
110
+ eigen_solver = ("arpack", "dense")
111
+
112
+ for solver in eigen_solver:
113
+ transformed_X = np.zeros((20, 2))
114
+ for i in range(20):
115
+ kpca = KernelPCA(n_components=2, eigen_solver=solver, random_state=rng)
116
+ transformed_X[i, :] = kpca.fit_transform(X)[0]
117
+ assert_allclose(transformed_X, np.tile(transformed_X[0, :], 20).reshape(20, 2))
118
+
119
+
120
+ def test_kernel_pca_sparse():
121
+ """Test that kPCA works on a sparse data input.
122
+
123
+ Same test as ``test_kernel_pca except inverse_transform`` since it's not
124
+ implemented for sparse matrices.
125
+ """
126
+ rng = np.random.RandomState(0)
127
+ X_fit = sp.csr_matrix(rng.random_sample((5, 4)))
128
+ X_pred = sp.csr_matrix(rng.random_sample((2, 4)))
129
+
130
+ for eigen_solver in ("auto", "arpack", "randomized"):
131
+ for kernel in ("linear", "rbf", "poly"):
132
+ # transform fit data
133
+ kpca = KernelPCA(
134
+ 4,
135
+ kernel=kernel,
136
+ eigen_solver=eigen_solver,
137
+ fit_inverse_transform=False,
138
+ random_state=0,
139
+ )
140
+ X_fit_transformed = kpca.fit_transform(X_fit)
141
+ X_fit_transformed2 = kpca.fit(X_fit).transform(X_fit)
142
+ assert_array_almost_equal(
143
+ np.abs(X_fit_transformed), np.abs(X_fit_transformed2)
144
+ )
145
+
146
+ # transform new data
147
+ X_pred_transformed = kpca.transform(X_pred)
148
+ assert X_pred_transformed.shape[1] == X_fit_transformed.shape[1]
149
+
150
+ # inverse transform: not available for sparse matrices
151
+ # XXX: should we raise another exception type here? For instance:
152
+ # NotImplementedError.
153
+ with pytest.raises(NotFittedError):
154
+ kpca.inverse_transform(X_pred_transformed)
155
+
156
+
157
+ @pytest.mark.parametrize("solver", ["auto", "dense", "arpack", "randomized"])
158
+ @pytest.mark.parametrize("n_features", [4, 10])
159
+ def test_kernel_pca_linear_kernel(solver, n_features):
160
+ """Test that kPCA with linear kernel is equivalent to PCA for all solvers.
161
+
162
+ KernelPCA with linear kernel should produce the same output as PCA.
163
+ """
164
+ rng = np.random.RandomState(0)
165
+ X_fit = rng.random_sample((5, n_features))
166
+ X_pred = rng.random_sample((2, n_features))
167
+
168
+ # for a linear kernel, kernel PCA should find the same projection as PCA
169
+ # modulo the sign (direction)
170
+ # fit only the first four components: fifth is near zero eigenvalue, so
171
+ # can be trimmed due to roundoff error
172
+ n_comps = 3 if solver == "arpack" else 4
173
+ assert_array_almost_equal(
174
+ np.abs(KernelPCA(n_comps, eigen_solver=solver).fit(X_fit).transform(X_pred)),
175
+ np.abs(
176
+ PCA(n_comps, svd_solver=solver if solver != "dense" else "full")
177
+ .fit(X_fit)
178
+ .transform(X_pred)
179
+ ),
180
+ )
181
+
182
+
183
+ def test_kernel_pca_n_components():
184
+ """Test that `n_components` is correctly taken into account for projections
185
+
186
+ For all solvers this tests that the output has the correct shape depending
187
+ on the selected number of components.
188
+ """
189
+ rng = np.random.RandomState(0)
190
+ X_fit = rng.random_sample((5, 4))
191
+ X_pred = rng.random_sample((2, 4))
192
+
193
+ for eigen_solver in ("dense", "arpack", "randomized"):
194
+ for c in [1, 2, 4]:
195
+ kpca = KernelPCA(n_components=c, eigen_solver=eigen_solver)
196
+ shape = kpca.fit(X_fit).transform(X_pred).shape
197
+
198
+ assert shape == (2, c)
199
+
200
+
201
+ def test_remove_zero_eig():
202
+ """Check that the ``remove_zero_eig`` parameter works correctly.
203
+
204
+ Tests that the null-space (Zero) eigenvalues are removed when
205
+ remove_zero_eig=True, whereas they are not by default.
206
+ """
207
+ X = np.array([[1 - 1e-30, 1], [1, 1], [1, 1 - 1e-20]])
208
+
209
+ # n_components=None (default) => remove_zero_eig is True
210
+ kpca = KernelPCA()
211
+ Xt = kpca.fit_transform(X)
212
+ assert Xt.shape == (3, 0)
213
+
214
+ kpca = KernelPCA(n_components=2)
215
+ Xt = kpca.fit_transform(X)
216
+ assert Xt.shape == (3, 2)
217
+
218
+ kpca = KernelPCA(n_components=2, remove_zero_eig=True)
219
+ Xt = kpca.fit_transform(X)
220
+ assert Xt.shape == (3, 0)
221
+
222
+
223
+ def test_leave_zero_eig():
224
+ """Non-regression test for issue #12141 (PR #12143)
225
+
226
+ This test checks that fit().transform() returns the same result as
227
+ fit_transform() in case of non-removed zero eigenvalue.
228
+ """
229
+ X_fit = np.array([[1, 1], [0, 0]])
230
+
231
+ # Assert that even with all np warnings on, there is no div by zero warning
232
+ with warnings.catch_warnings():
233
+ # There might be warnings about the kernel being badly conditioned,
234
+ # but there should not be warnings about division by zero.
235
+ # (Numpy division by zero warning can have many message variants, but
236
+ # at least we know that it is a RuntimeWarning so lets check only this)
237
+ warnings.simplefilter("error", RuntimeWarning)
238
+ with np.errstate(all="warn"):
239
+ k = KernelPCA(n_components=2, remove_zero_eig=False, eigen_solver="dense")
240
+ # Fit, then transform
241
+ A = k.fit(X_fit).transform(X_fit)
242
+ # Do both at once
243
+ B = k.fit_transform(X_fit)
244
+ # Compare
245
+ assert_array_almost_equal(np.abs(A), np.abs(B))
246
+
247
+
248
+ def test_kernel_pca_precomputed():
249
+ """Test that kPCA works with a precomputed kernel, for all solvers"""
250
+ rng = np.random.RandomState(0)
251
+ X_fit = rng.random_sample((5, 4))
252
+ X_pred = rng.random_sample((2, 4))
253
+
254
+ for eigen_solver in ("dense", "arpack", "randomized"):
255
+ X_kpca = (
256
+ KernelPCA(4, eigen_solver=eigen_solver, random_state=0)
257
+ .fit(X_fit)
258
+ .transform(X_pred)
259
+ )
260
+
261
+ X_kpca2 = (
262
+ KernelPCA(
263
+ 4, eigen_solver=eigen_solver, kernel="precomputed", random_state=0
264
+ )
265
+ .fit(np.dot(X_fit, X_fit.T))
266
+ .transform(np.dot(X_pred, X_fit.T))
267
+ )
268
+
269
+ X_kpca_train = KernelPCA(
270
+ 4, eigen_solver=eigen_solver, kernel="precomputed", random_state=0
271
+ ).fit_transform(np.dot(X_fit, X_fit.T))
272
+
273
+ X_kpca_train2 = (
274
+ KernelPCA(
275
+ 4, eigen_solver=eigen_solver, kernel="precomputed", random_state=0
276
+ )
277
+ .fit(np.dot(X_fit, X_fit.T))
278
+ .transform(np.dot(X_fit, X_fit.T))
279
+ )
280
+
281
+ assert_array_almost_equal(np.abs(X_kpca), np.abs(X_kpca2))
282
+
283
+ assert_array_almost_equal(np.abs(X_kpca_train), np.abs(X_kpca_train2))
284
+
285
+
286
+ @pytest.mark.parametrize("solver", ["auto", "dense", "arpack", "randomized"])
287
+ def test_kernel_pca_precomputed_non_symmetric(solver):
288
+ """Check that the kernel centerer works.
289
+
290
+ Tests that a non symmetric precomputed kernel is actually accepted
291
+ because the kernel centerer does its job correctly.
292
+ """
293
+
294
+ # a non symmetric gram matrix
295
+ K = [[1, 2], [3, 40]]
296
+ kpca = KernelPCA(
297
+ kernel="precomputed", eigen_solver=solver, n_components=1, random_state=0
298
+ )
299
+ kpca.fit(K) # no error
300
+
301
+ # same test with centered kernel
302
+ Kc = [[9, -9], [-9, 9]]
303
+ kpca_c = KernelPCA(
304
+ kernel="precomputed", eigen_solver=solver, n_components=1, random_state=0
305
+ )
306
+ kpca_c.fit(Kc)
307
+
308
+ # comparison between the non-centered and centered versions
309
+ assert_array_equal(kpca.eigenvectors_, kpca_c.eigenvectors_)
310
+ assert_array_equal(kpca.eigenvalues_, kpca_c.eigenvalues_)
311
+
312
+
313
+ def test_gridsearch_pipeline():
314
+ """Check that kPCA works as expected in a grid search pipeline
315
+
316
+ Test if we can do a grid-search to find parameters to separate
317
+ circles with a perceptron model.
318
+ """
319
+ X, y = make_circles(n_samples=400, factor=0.3, noise=0.05, random_state=0)
320
+ kpca = KernelPCA(kernel="rbf", n_components=2)
321
+ pipeline = Pipeline([("kernel_pca", kpca), ("Perceptron", Perceptron(max_iter=5))])
322
+ param_grid = dict(kernel_pca__gamma=2.0 ** np.arange(-2, 2))
323
+ grid_search = GridSearchCV(pipeline, cv=3, param_grid=param_grid)
324
+ grid_search.fit(X, y)
325
+ assert grid_search.best_score_ == 1
326
+
327
+
328
+ def test_gridsearch_pipeline_precomputed():
329
+ """Check that kPCA works as expected in a grid search pipeline (2)
330
+
331
+ Test if we can do a grid-search to find parameters to separate
332
+ circles with a perceptron model. This test uses a precomputed kernel.
333
+ """
334
+ X, y = make_circles(n_samples=400, factor=0.3, noise=0.05, random_state=0)
335
+ kpca = KernelPCA(kernel="precomputed", n_components=2)
336
+ pipeline = Pipeline([("kernel_pca", kpca), ("Perceptron", Perceptron(max_iter=5))])
337
+ param_grid = dict(Perceptron__max_iter=np.arange(1, 5))
338
+ grid_search = GridSearchCV(pipeline, cv=3, param_grid=param_grid)
339
+ X_kernel = rbf_kernel(X, gamma=2.0)
340
+ grid_search.fit(X_kernel, y)
341
+ assert grid_search.best_score_ == 1
342
+
343
+
344
+ def test_nested_circles():
345
+ """Check that kPCA projects in a space where nested circles are separable
346
+
347
+ Tests that 2D nested circles become separable with a perceptron when
348
+ projected in the first 2 kPCA using an RBF kernel, while raw samples
349
+ are not directly separable in the original space.
350
+ """
351
+ X, y = make_circles(n_samples=400, factor=0.3, noise=0.05, random_state=0)
352
+
353
+ # 2D nested circles are not linearly separable
354
+ train_score = Perceptron(max_iter=5).fit(X, y).score(X, y)
355
+ assert train_score < 0.8
356
+
357
+ # Project the circles data into the first 2 components of a RBF Kernel
358
+ # PCA model.
359
+ # Note that the gamma value is data dependent. If this test breaks
360
+ # and the gamma value has to be updated, the Kernel PCA example will
361
+ # have to be updated too.
362
+ kpca = KernelPCA(
363
+ kernel="rbf", n_components=2, fit_inverse_transform=True, gamma=2.0
364
+ )
365
+ X_kpca = kpca.fit_transform(X)
366
+
367
+ # The data is perfectly linearly separable in that space
368
+ train_score = Perceptron(max_iter=5).fit(X_kpca, y).score(X_kpca, y)
369
+ assert train_score == 1.0
370
+
371
+
372
+ def test_kernel_conditioning():
373
+ """Check that ``_check_psd_eigenvalues`` is correctly called in kPCA
374
+
375
+ Non-regression test for issue #12140 (PR #12145).
376
+ """
377
+
378
+ # create a pathological X leading to small non-zero eigenvalue
379
+ X = [[5, 1], [5 + 1e-8, 1e-8], [5 + 1e-8, 0]]
380
+ kpca = KernelPCA(kernel="linear", n_components=2, fit_inverse_transform=True)
381
+ kpca.fit(X)
382
+
383
+ # check that the small non-zero eigenvalue was correctly set to zero
384
+ assert kpca.eigenvalues_.min() == 0
385
+ assert np.all(kpca.eigenvalues_ == _check_psd_eigenvalues(kpca.eigenvalues_))
386
+
387
+
388
+ @pytest.mark.parametrize("solver", ["auto", "dense", "arpack", "randomized"])
389
+ def test_precomputed_kernel_not_psd(solver):
390
+ """Check how KernelPCA works with non-PSD kernels depending on n_components
391
+
392
+ Tests for all methods what happens with a non PSD gram matrix (this
393
+ can happen in an isomap scenario, or with custom kernel functions, or
394
+ maybe with ill-posed datasets).
395
+
396
+ When ``n_component`` is large enough to capture a negative eigenvalue, an
397
+ error should be raised. Otherwise, KernelPCA should run without error
398
+ since the negative eigenvalues are not selected.
399
+ """
400
+
401
+ # a non PSD kernel with large eigenvalues, already centered
402
+ # it was captured from an isomap call and multiplied by 100 for compacity
403
+ K = [
404
+ [4.48, -1.0, 8.07, 2.33, 2.33, 2.33, -5.76, -12.78],
405
+ [-1.0, -6.48, 4.5, -1.24, -1.24, -1.24, -0.81, 7.49],
406
+ [8.07, 4.5, 15.48, 2.09, 2.09, 2.09, -11.1, -23.23],
407
+ [2.33, -1.24, 2.09, 4.0, -3.65, -3.65, 1.02, -0.9],
408
+ [2.33, -1.24, 2.09, -3.65, 4.0, -3.65, 1.02, -0.9],
409
+ [2.33, -1.24, 2.09, -3.65, -3.65, 4.0, 1.02, -0.9],
410
+ [-5.76, -0.81, -11.1, 1.02, 1.02, 1.02, 4.86, 9.75],
411
+ [-12.78, 7.49, -23.23, -0.9, -0.9, -0.9, 9.75, 21.46],
412
+ ]
413
+ # this gram matrix has 5 positive eigenvalues and 3 negative ones
414
+ # [ 52.72, 7.65, 7.65, 5.02, 0. , -0. , -6.13, -15.11]
415
+
416
+ # 1. ask for enough components to get a significant negative one
417
+ kpca = KernelPCA(kernel="precomputed", eigen_solver=solver, n_components=7)
418
+ # make sure that the appropriate error is raised
419
+ with pytest.raises(ValueError, match="There are significant negative eigenvalues"):
420
+ kpca.fit(K)
421
+
422
+ # 2. ask for a small enough n_components to get only positive ones
423
+ kpca = KernelPCA(kernel="precomputed", eigen_solver=solver, n_components=2)
424
+ if solver == "randomized":
425
+ # the randomized method is still inconsistent with the others on this
426
+ # since it selects the eigenvalues based on the largest 2 modules, not
427
+ # on the largest 2 values.
428
+ #
429
+ # At least we can ensure that we return an error instead of returning
430
+ # the wrong eigenvalues
431
+ with pytest.raises(
432
+ ValueError, match="There are significant negative eigenvalues"
433
+ ):
434
+ kpca.fit(K)
435
+ else:
436
+ # general case: make sure that it works
437
+ kpca.fit(K)
438
+
439
+
440
+ @pytest.mark.parametrize("n_components", [4, 10, 20])
441
+ def test_kernel_pca_solvers_equivalence(n_components):
442
+ """Check that 'dense' 'arpack' & 'randomized' solvers give similar results"""
443
+
444
+ # Generate random data
445
+ n_train, n_test = 1_000, 100
446
+ X, _ = make_circles(
447
+ n_samples=(n_train + n_test), factor=0.3, noise=0.05, random_state=0
448
+ )
449
+ X_fit, X_pred = X[:n_train, :], X[n_train:, :]
450
+
451
+ # reference (full)
452
+ ref_pred = (
453
+ KernelPCA(n_components, eigen_solver="dense", random_state=0)
454
+ .fit(X_fit)
455
+ .transform(X_pred)
456
+ )
457
+
458
+ # arpack
459
+ a_pred = (
460
+ KernelPCA(n_components, eigen_solver="arpack", random_state=0)
461
+ .fit(X_fit)
462
+ .transform(X_pred)
463
+ )
464
+ # check that the result is still correct despite the approx
465
+ assert_array_almost_equal(np.abs(a_pred), np.abs(ref_pred))
466
+
467
+ # randomized
468
+ r_pred = (
469
+ KernelPCA(n_components, eigen_solver="randomized", random_state=0)
470
+ .fit(X_fit)
471
+ .transform(X_pred)
472
+ )
473
+ # check that the result is still correct despite the approximation
474
+ assert_array_almost_equal(np.abs(r_pred), np.abs(ref_pred))
475
+
476
+
477
+ def test_kernel_pca_inverse_transform_reconstruction():
478
+ """Test if the reconstruction is a good approximation.
479
+
480
+ Note that in general it is not possible to get an arbitrarily good
481
+ reconstruction because of kernel centering that does not
482
+ preserve all the information of the original data.
483
+ """
484
+ X, *_ = make_blobs(n_samples=100, n_features=4, random_state=0)
485
+
486
+ kpca = KernelPCA(
487
+ n_components=20, kernel="rbf", fit_inverse_transform=True, alpha=1e-3
488
+ )
489
+ X_trans = kpca.fit_transform(X)
490
+ X_reconst = kpca.inverse_transform(X_trans)
491
+ assert np.linalg.norm(X - X_reconst) / np.linalg.norm(X) < 1e-1
492
+
493
+
494
+ def test_kernel_pca_raise_not_fitted_error():
495
+ X = np.random.randn(15).reshape(5, 3)
496
+ kpca = KernelPCA()
497
+ kpca.fit(X)
498
+ with pytest.raises(NotFittedError):
499
+ kpca.inverse_transform(X)
500
+
501
+
502
+ def test_32_64_decomposition_shape():
503
+ """Test that the decomposition is similar for 32 and 64 bits data
504
+
505
+ Non regression test for
506
+ https://github.com/scikit-learn/scikit-learn/issues/18146
507
+ """
508
+ X, y = make_blobs(
509
+ n_samples=30, centers=[[0, 0, 0], [1, 1, 1]], random_state=0, cluster_std=0.1
510
+ )
511
+ X = StandardScaler().fit_transform(X)
512
+ X -= X.min()
513
+
514
+ # Compare the shapes (corresponds to the number of non-zero eigenvalues)
515
+ kpca = KernelPCA()
516
+ assert kpca.fit_transform(X).shape == kpca.fit_transform(X.astype(np.float32)).shape
517
+
518
+
519
+ def test_kernel_pca_feature_names_out():
520
+ """Check feature names out for KernelPCA."""
521
+ X, *_ = make_blobs(n_samples=100, n_features=4, random_state=0)
522
+ kpca = KernelPCA(n_components=2).fit(X)
523
+
524
+ names = kpca.get_feature_names_out()
525
+ assert_array_equal([f"kernelpca{i}" for i in range(2)], names)
videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/test_nmf.py ADDED
@@ -0,0 +1,908 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import sys
3
+ from io import StringIO
4
+
5
+ import numpy as np
6
+ import scipy.sparse as sp
7
+
8
+ from scipy import linalg
9
+ from sklearn.decomposition import NMF, MiniBatchNMF
10
+ from sklearn.decomposition import non_negative_factorization
11
+ from sklearn.decomposition import _nmf as nmf # For testing internals
12
+ from scipy.sparse import csc_matrix
13
+
14
+ import pytest
15
+
16
+ from sklearn.utils._testing import assert_array_equal
17
+ from sklearn.utils._testing import assert_array_almost_equal
18
+ from sklearn.utils._testing import assert_almost_equal
19
+ from sklearn.utils._testing import assert_allclose
20
+ from sklearn.utils._testing import ignore_warnings
21
+ from sklearn.utils.extmath import squared_norm
22
+ from sklearn.base import clone
23
+ from sklearn.exceptions import ConvergenceWarning
24
+
25
+
26
+ @pytest.mark.parametrize(
27
+ ["Estimator", "solver"],
28
+ [[NMF, {"solver": "cd"}], [NMF, {"solver": "mu"}], [MiniBatchNMF, {}]],
29
+ )
30
+ def test_convergence_warning(Estimator, solver):
31
+ convergence_warning = (
32
+ "Maximum number of iterations 1 reached. Increase it to improve convergence."
33
+ )
34
+ A = np.ones((2, 2))
35
+ with pytest.warns(ConvergenceWarning, match=convergence_warning):
36
+ Estimator(max_iter=1, **solver).fit(A)
37
+
38
+
39
+ def test_initialize_nn_output():
40
+ # Test that initialization does not return negative values
41
+ rng = np.random.mtrand.RandomState(42)
42
+ data = np.abs(rng.randn(10, 10))
43
+ for init in ("random", "nndsvd", "nndsvda", "nndsvdar"):
44
+ W, H = nmf._initialize_nmf(data, 10, init=init, random_state=0)
45
+ assert not ((W < 0).any() or (H < 0).any())
46
+
47
+
48
+ @pytest.mark.filterwarnings(
49
+ r"ignore:The multiplicative update \('mu'\) solver cannot update zeros present in"
50
+ r" the initialization"
51
+ )
52
+ def test_parameter_checking():
53
+ # Here we only check for invalid parameter values that are not already
54
+ # automatically tested in the common tests.
55
+
56
+ A = np.ones((2, 2))
57
+
58
+ msg = "Invalid beta_loss parameter: solver 'cd' does not handle beta_loss = 1.0"
59
+ with pytest.raises(ValueError, match=msg):
60
+ NMF(solver="cd", beta_loss=1.0).fit(A)
61
+ msg = "Negative values in data passed to"
62
+ with pytest.raises(ValueError, match=msg):
63
+ NMF().fit(-A)
64
+ clf = NMF(2, tol=0.1).fit(A)
65
+ with pytest.raises(ValueError, match=msg):
66
+ clf.transform(-A)
67
+ with pytest.raises(ValueError, match=msg):
68
+ nmf._initialize_nmf(-A, 2, "nndsvd")
69
+
70
+ for init in ["nndsvd", "nndsvda", "nndsvdar"]:
71
+ msg = re.escape(
72
+ "init = '{}' can only be used when "
73
+ "n_components <= min(n_samples, n_features)".format(init)
74
+ )
75
+ with pytest.raises(ValueError, match=msg):
76
+ NMF(3, init=init).fit(A)
77
+ with pytest.raises(ValueError, match=msg):
78
+ MiniBatchNMF(3, init=init).fit(A)
79
+ with pytest.raises(ValueError, match=msg):
80
+ nmf._initialize_nmf(A, 3, init)
81
+
82
+
83
+ def test_initialize_close():
84
+ # Test NNDSVD error
85
+ # Test that _initialize_nmf error is less than the standard deviation of
86
+ # the entries in the matrix.
87
+ rng = np.random.mtrand.RandomState(42)
88
+ A = np.abs(rng.randn(10, 10))
89
+ W, H = nmf._initialize_nmf(A, 10, init="nndsvd")
90
+ error = linalg.norm(np.dot(W, H) - A)
91
+ sdev = linalg.norm(A - A.mean())
92
+ assert error <= sdev
93
+
94
+
95
+ def test_initialize_variants():
96
+ # Test NNDSVD variants correctness
97
+ # Test that the variants 'nndsvda' and 'nndsvdar' differ from basic
98
+ # 'nndsvd' only where the basic version has zeros.
99
+ rng = np.random.mtrand.RandomState(42)
100
+ data = np.abs(rng.randn(10, 10))
101
+ W0, H0 = nmf._initialize_nmf(data, 10, init="nndsvd")
102
+ Wa, Ha = nmf._initialize_nmf(data, 10, init="nndsvda")
103
+ War, Har = nmf._initialize_nmf(data, 10, init="nndsvdar", random_state=0)
104
+
105
+ for ref, evl in ((W0, Wa), (W0, War), (H0, Ha), (H0, Har)):
106
+ assert_almost_equal(evl[ref != 0], ref[ref != 0])
107
+
108
+
109
+ # ignore UserWarning raised when both solver='mu' and init='nndsvd'
110
+ @ignore_warnings(category=UserWarning)
111
+ @pytest.mark.parametrize(
112
+ ["Estimator", "solver"],
113
+ [[NMF, {"solver": "cd"}], [NMF, {"solver": "mu"}], [MiniBatchNMF, {}]],
114
+ )
115
+ @pytest.mark.parametrize("init", (None, "nndsvd", "nndsvda", "nndsvdar", "random"))
116
+ @pytest.mark.parametrize("alpha_W", (0.0, 1.0))
117
+ @pytest.mark.parametrize("alpha_H", (0.0, 1.0, "same"))
118
+ def test_nmf_fit_nn_output(Estimator, solver, init, alpha_W, alpha_H):
119
+ # Test that the decomposition does not contain negative values
120
+ A = np.c_[5.0 - np.arange(1, 6), 5.0 + np.arange(1, 6)]
121
+ model = Estimator(
122
+ n_components=2,
123
+ init=init,
124
+ alpha_W=alpha_W,
125
+ alpha_H=alpha_H,
126
+ random_state=0,
127
+ **solver,
128
+ )
129
+ transf = model.fit_transform(A)
130
+ assert not ((model.components_ < 0).any() or (transf < 0).any())
131
+
132
+
133
+ @pytest.mark.parametrize(
134
+ ["Estimator", "solver"],
135
+ [[NMF, {"solver": "cd"}], [NMF, {"solver": "mu"}], [MiniBatchNMF, {}]],
136
+ )
137
+ def test_nmf_fit_close(Estimator, solver):
138
+ rng = np.random.mtrand.RandomState(42)
139
+ # Test that the fit is not too far away
140
+ pnmf = Estimator(
141
+ 5,
142
+ init="nndsvdar",
143
+ random_state=0,
144
+ max_iter=600,
145
+ **solver,
146
+ )
147
+ X = np.abs(rng.randn(6, 5))
148
+ assert pnmf.fit(X).reconstruction_err_ < 0.1
149
+
150
+
151
+ def test_nmf_true_reconstruction():
152
+ # Test that the fit is not too far away from an exact solution
153
+ # (by construction)
154
+ n_samples = 15
155
+ n_features = 10
156
+ n_components = 5
157
+ beta_loss = 1
158
+ batch_size = 3
159
+ max_iter = 1000
160
+
161
+ rng = np.random.mtrand.RandomState(42)
162
+ W_true = np.zeros([n_samples, n_components])
163
+ W_array = np.abs(rng.randn(n_samples))
164
+ for j in range(n_components):
165
+ W_true[j % n_samples, j] = W_array[j % n_samples]
166
+ H_true = np.zeros([n_components, n_features])
167
+ H_array = np.abs(rng.randn(n_components))
168
+ for j in range(n_features):
169
+ H_true[j % n_components, j] = H_array[j % n_components]
170
+ X = np.dot(W_true, H_true)
171
+
172
+ model = NMF(
173
+ n_components=n_components,
174
+ solver="mu",
175
+ beta_loss=beta_loss,
176
+ max_iter=max_iter,
177
+ random_state=0,
178
+ )
179
+ transf = model.fit_transform(X)
180
+ X_calc = np.dot(transf, model.components_)
181
+
182
+ assert model.reconstruction_err_ < 0.1
183
+ assert_allclose(X, X_calc)
184
+
185
+ mbmodel = MiniBatchNMF(
186
+ n_components=n_components,
187
+ beta_loss=beta_loss,
188
+ batch_size=batch_size,
189
+ random_state=0,
190
+ max_iter=max_iter,
191
+ )
192
+ transf = mbmodel.fit_transform(X)
193
+ X_calc = np.dot(transf, mbmodel.components_)
194
+
195
+ assert mbmodel.reconstruction_err_ < 0.1
196
+ assert_allclose(X, X_calc, atol=1)
197
+
198
+
199
+ @pytest.mark.parametrize("solver", ["cd", "mu"])
200
+ def test_nmf_transform(solver):
201
+ # Test that fit_transform is equivalent to fit.transform for NMF
202
+ # Test that NMF.transform returns close values
203
+ rng = np.random.mtrand.RandomState(42)
204
+ A = np.abs(rng.randn(6, 5))
205
+ m = NMF(
206
+ solver=solver,
207
+ n_components=3,
208
+ init="random",
209
+ random_state=0,
210
+ tol=1e-6,
211
+ )
212
+ ft = m.fit_transform(A)
213
+ t = m.transform(A)
214
+ assert_allclose(ft, t, atol=1e-1)
215
+
216
+
217
+ def test_minibatch_nmf_transform():
218
+ # Test that fit_transform is equivalent to fit.transform for MiniBatchNMF
219
+ # Only guaranteed with fresh restarts
220
+ rng = np.random.mtrand.RandomState(42)
221
+ A = np.abs(rng.randn(6, 5))
222
+ m = MiniBatchNMF(
223
+ n_components=3,
224
+ random_state=0,
225
+ tol=1e-3,
226
+ fresh_restarts=True,
227
+ )
228
+ ft = m.fit_transform(A)
229
+ t = m.transform(A)
230
+ assert_allclose(ft, t)
231
+
232
+
233
+ @pytest.mark.parametrize(
234
+ ["Estimator", "solver"],
235
+ [[NMF, {"solver": "cd"}], [NMF, {"solver": "mu"}], [MiniBatchNMF, {}]],
236
+ )
237
+ def test_nmf_transform_custom_init(Estimator, solver):
238
+ # Smoke test that checks if NMF.transform works with custom initialization
239
+ random_state = np.random.RandomState(0)
240
+ A = np.abs(random_state.randn(6, 5))
241
+ n_components = 4
242
+ avg = np.sqrt(A.mean() / n_components)
243
+ H_init = np.abs(avg * random_state.randn(n_components, 5))
244
+ W_init = np.abs(avg * random_state.randn(6, n_components))
245
+
246
+ m = Estimator(
247
+ n_components=n_components, init="custom", random_state=0, tol=1e-3, **solver
248
+ )
249
+ m.fit_transform(A, W=W_init, H=H_init)
250
+ m.transform(A)
251
+
252
+
253
+ @pytest.mark.parametrize("solver", ("cd", "mu"))
254
+ def test_nmf_inverse_transform(solver):
255
+ # Test that NMF.inverse_transform returns close values
256
+ random_state = np.random.RandomState(0)
257
+ A = np.abs(random_state.randn(6, 4))
258
+ m = NMF(
259
+ solver=solver,
260
+ n_components=4,
261
+ init="random",
262
+ random_state=0,
263
+ max_iter=1000,
264
+ )
265
+ ft = m.fit_transform(A)
266
+ A_new = m.inverse_transform(ft)
267
+ assert_array_almost_equal(A, A_new, decimal=2)
268
+
269
+
270
+ def test_mbnmf_inverse_transform():
271
+ # Test that MiniBatchNMF.transform followed by MiniBatchNMF.inverse_transform
272
+ # is close to the identity
273
+ rng = np.random.RandomState(0)
274
+ A = np.abs(rng.randn(6, 4))
275
+ nmf = MiniBatchNMF(
276
+ random_state=rng,
277
+ max_iter=500,
278
+ init="nndsvdar",
279
+ fresh_restarts=True,
280
+ )
281
+ ft = nmf.fit_transform(A)
282
+ A_new = nmf.inverse_transform(ft)
283
+ assert_allclose(A, A_new, rtol=1e-3, atol=1e-2)
284
+
285
+
286
+ @pytest.mark.parametrize("Estimator", [NMF, MiniBatchNMF])
287
+ def test_n_components_greater_n_features(Estimator):
288
+ # Smoke test for the case of more components than features.
289
+ rng = np.random.mtrand.RandomState(42)
290
+ A = np.abs(rng.randn(30, 10))
291
+ Estimator(n_components=15, random_state=0, tol=1e-2).fit(A)
292
+
293
+
294
+ @pytest.mark.parametrize(
295
+ ["Estimator", "solver"],
296
+ [[NMF, {"solver": "cd"}], [NMF, {"solver": "mu"}], [MiniBatchNMF, {}]],
297
+ )
298
+ @pytest.mark.parametrize("alpha_W", (0.0, 1.0))
299
+ @pytest.mark.parametrize("alpha_H", (0.0, 1.0, "same"))
300
+ def test_nmf_sparse_input(Estimator, solver, alpha_W, alpha_H):
301
+ # Test that sparse matrices are accepted as input
302
+ from scipy.sparse import csc_matrix
303
+
304
+ rng = np.random.mtrand.RandomState(42)
305
+ A = np.abs(rng.randn(10, 10))
306
+ A[:, 2 * np.arange(5)] = 0
307
+ A_sparse = csc_matrix(A)
308
+
309
+ est1 = Estimator(
310
+ n_components=5,
311
+ init="random",
312
+ alpha_W=alpha_W,
313
+ alpha_H=alpha_H,
314
+ random_state=0,
315
+ tol=0,
316
+ max_iter=100,
317
+ **solver,
318
+ )
319
+ est2 = clone(est1)
320
+
321
+ W1 = est1.fit_transform(A)
322
+ W2 = est2.fit_transform(A_sparse)
323
+ H1 = est1.components_
324
+ H2 = est2.components_
325
+
326
+ assert_allclose(W1, W2)
327
+ assert_allclose(H1, H2)
328
+
329
+
330
+ @pytest.mark.parametrize(
331
+ ["Estimator", "solver"],
332
+ [[NMF, {"solver": "cd"}], [NMF, {"solver": "mu"}], [MiniBatchNMF, {}]],
333
+ )
334
+ def test_nmf_sparse_transform(Estimator, solver):
335
+ # Test that transform works on sparse data. Issue #2124
336
+ rng = np.random.mtrand.RandomState(42)
337
+ A = np.abs(rng.randn(3, 2))
338
+ A[1, 1] = 0
339
+ A = csc_matrix(A)
340
+
341
+ model = Estimator(random_state=0, n_components=2, max_iter=400, **solver)
342
+ A_fit_tr = model.fit_transform(A)
343
+ A_tr = model.transform(A)
344
+ assert_allclose(A_fit_tr, A_tr, atol=1e-1)
345
+
346
+
347
+ @pytest.mark.parametrize("init", ["random", "nndsvd"])
348
+ @pytest.mark.parametrize("solver", ("cd", "mu"))
349
+ @pytest.mark.parametrize("alpha_W", (0.0, 1.0))
350
+ @pytest.mark.parametrize("alpha_H", (0.0, 1.0, "same"))
351
+ def test_non_negative_factorization_consistency(init, solver, alpha_W, alpha_H):
352
+ # Test that the function is called in the same way, either directly
353
+ # or through the NMF class
354
+ max_iter = 500
355
+ rng = np.random.mtrand.RandomState(42)
356
+ A = np.abs(rng.randn(10, 10))
357
+ A[:, 2 * np.arange(5)] = 0
358
+
359
+ W_nmf, H, _ = non_negative_factorization(
360
+ A,
361
+ init=init,
362
+ solver=solver,
363
+ max_iter=max_iter,
364
+ alpha_W=alpha_W,
365
+ alpha_H=alpha_H,
366
+ random_state=1,
367
+ tol=1e-2,
368
+ )
369
+ W_nmf_2, H, _ = non_negative_factorization(
370
+ A,
371
+ H=H,
372
+ update_H=False,
373
+ init=init,
374
+ solver=solver,
375
+ max_iter=max_iter,
376
+ alpha_W=alpha_W,
377
+ alpha_H=alpha_H,
378
+ random_state=1,
379
+ tol=1e-2,
380
+ )
381
+
382
+ model_class = NMF(
383
+ init=init,
384
+ solver=solver,
385
+ max_iter=max_iter,
386
+ alpha_W=alpha_W,
387
+ alpha_H=alpha_H,
388
+ random_state=1,
389
+ tol=1e-2,
390
+ )
391
+ W_cls = model_class.fit_transform(A)
392
+ W_cls_2 = model_class.transform(A)
393
+
394
+ assert_allclose(W_nmf, W_cls)
395
+ assert_allclose(W_nmf_2, W_cls_2)
396
+
397
+
398
+ def test_non_negative_factorization_checking():
399
+ # Note that the validity of parameter types and range of possible values
400
+ # for scalar numerical or str parameters is already checked in the common
401
+ # tests. Here we only check for problems that cannot be captured by simple
402
+ # declarative constraints on the valid parameter values.
403
+
404
+ A = np.ones((2, 2))
405
+ # Test parameters checking in public function
406
+ nnmf = non_negative_factorization
407
+ msg = re.escape("Negative values in data passed to NMF (input H)")
408
+ with pytest.raises(ValueError, match=msg):
409
+ nnmf(A, A, -A, 2, init="custom")
410
+ msg = re.escape("Negative values in data passed to NMF (input W)")
411
+ with pytest.raises(ValueError, match=msg):
412
+ nnmf(A, -A, A, 2, init="custom")
413
+ msg = re.escape("Array passed to NMF (input H) is full of zeros")
414
+ with pytest.raises(ValueError, match=msg):
415
+ nnmf(A, A, 0 * A, 2, init="custom")
416
+
417
+
418
+ def _beta_divergence_dense(X, W, H, beta):
419
+ """Compute the beta-divergence of X and W.H for dense array only.
420
+
421
+ Used as a reference for testing nmf._beta_divergence.
422
+ """
423
+ WH = np.dot(W, H)
424
+
425
+ if beta == 2:
426
+ return squared_norm(X - WH) / 2
427
+
428
+ WH_Xnonzero = WH[X != 0]
429
+ X_nonzero = X[X != 0]
430
+ np.maximum(WH_Xnonzero, 1e-9, out=WH_Xnonzero)
431
+
432
+ if beta == 1:
433
+ res = np.sum(X_nonzero * np.log(X_nonzero / WH_Xnonzero))
434
+ res += WH.sum() - X.sum()
435
+
436
+ elif beta == 0:
437
+ div = X_nonzero / WH_Xnonzero
438
+ res = np.sum(div) - X.size - np.sum(np.log(div))
439
+ else:
440
+ res = (X_nonzero**beta).sum()
441
+ res += (beta - 1) * (WH**beta).sum()
442
+ res -= beta * (X_nonzero * (WH_Xnonzero ** (beta - 1))).sum()
443
+ res /= beta * (beta - 1)
444
+
445
+ return res
446
+
447
+
448
+ def test_beta_divergence():
449
+ # Compare _beta_divergence with the reference _beta_divergence_dense
450
+ n_samples = 20
451
+ n_features = 10
452
+ n_components = 5
453
+ beta_losses = [0.0, 0.5, 1.0, 1.5, 2.0, 3.0]
454
+
455
+ # initialization
456
+ rng = np.random.mtrand.RandomState(42)
457
+ X = rng.randn(n_samples, n_features)
458
+ np.clip(X, 0, None, out=X)
459
+ X_csr = sp.csr_matrix(X)
460
+ W, H = nmf._initialize_nmf(X, n_components, init="random", random_state=42)
461
+
462
+ for beta in beta_losses:
463
+ ref = _beta_divergence_dense(X, W, H, beta)
464
+ loss = nmf._beta_divergence(X, W, H, beta)
465
+ loss_csr = nmf._beta_divergence(X_csr, W, H, beta)
466
+
467
+ assert_almost_equal(ref, loss, decimal=7)
468
+ assert_almost_equal(ref, loss_csr, decimal=7)
469
+
470
+
471
+ def test_special_sparse_dot():
472
+ # Test the function that computes np.dot(W, H), only where X is non zero.
473
+ n_samples = 10
474
+ n_features = 5
475
+ n_components = 3
476
+ rng = np.random.mtrand.RandomState(42)
477
+ X = rng.randn(n_samples, n_features)
478
+ np.clip(X, 0, None, out=X)
479
+ X_csr = sp.csr_matrix(X)
480
+
481
+ W = np.abs(rng.randn(n_samples, n_components))
482
+ H = np.abs(rng.randn(n_components, n_features))
483
+
484
+ WH_safe = nmf._special_sparse_dot(W, H, X_csr)
485
+ WH = nmf._special_sparse_dot(W, H, X)
486
+
487
+ # test that both results have same values, in X_csr nonzero elements
488
+ ii, jj = X_csr.nonzero()
489
+ WH_safe_data = np.asarray(WH_safe[ii, jj]).ravel()
490
+ assert_array_almost_equal(WH_safe_data, WH[ii, jj], decimal=10)
491
+
492
+ # test that WH_safe and X_csr have the same sparse structure
493
+ assert_array_equal(WH_safe.indices, X_csr.indices)
494
+ assert_array_equal(WH_safe.indptr, X_csr.indptr)
495
+ assert_array_equal(WH_safe.shape, X_csr.shape)
496
+
497
+
498
+ @ignore_warnings(category=ConvergenceWarning)
499
+ def test_nmf_multiplicative_update_sparse():
500
+ # Compare sparse and dense input in multiplicative update NMF
501
+ # Also test continuity of the results with respect to beta_loss parameter
502
+ n_samples = 20
503
+ n_features = 10
504
+ n_components = 5
505
+ alpha = 0.1
506
+ l1_ratio = 0.5
507
+ n_iter = 20
508
+
509
+ # initialization
510
+ rng = np.random.mtrand.RandomState(1337)
511
+ X = rng.randn(n_samples, n_features)
512
+ X = np.abs(X)
513
+ X_csr = sp.csr_matrix(X)
514
+ W0, H0 = nmf._initialize_nmf(X, n_components, init="random", random_state=42)
515
+
516
+ for beta_loss in (-1.2, 0, 0.2, 1.0, 2.0, 2.5):
517
+ # Reference with dense array X
518
+ W, H = W0.copy(), H0.copy()
519
+ W1, H1, _ = non_negative_factorization(
520
+ X,
521
+ W,
522
+ H,
523
+ n_components,
524
+ init="custom",
525
+ update_H=True,
526
+ solver="mu",
527
+ beta_loss=beta_loss,
528
+ max_iter=n_iter,
529
+ alpha_W=alpha,
530
+ l1_ratio=l1_ratio,
531
+ random_state=42,
532
+ )
533
+
534
+ # Compare with sparse X
535
+ W, H = W0.copy(), H0.copy()
536
+ W2, H2, _ = non_negative_factorization(
537
+ X_csr,
538
+ W,
539
+ H,
540
+ n_components,
541
+ init="custom",
542
+ update_H=True,
543
+ solver="mu",
544
+ beta_loss=beta_loss,
545
+ max_iter=n_iter,
546
+ alpha_W=alpha,
547
+ l1_ratio=l1_ratio,
548
+ random_state=42,
549
+ )
550
+
551
+ assert_allclose(W1, W2, atol=1e-7)
552
+ assert_allclose(H1, H2, atol=1e-7)
553
+
554
+ # Compare with almost same beta_loss, since some values have a specific
555
+ # behavior, but the results should be continuous w.r.t beta_loss
556
+ beta_loss -= 1.0e-5
557
+ W, H = W0.copy(), H0.copy()
558
+ W3, H3, _ = non_negative_factorization(
559
+ X_csr,
560
+ W,
561
+ H,
562
+ n_components,
563
+ init="custom",
564
+ update_H=True,
565
+ solver="mu",
566
+ beta_loss=beta_loss,
567
+ max_iter=n_iter,
568
+ alpha_W=alpha,
569
+ l1_ratio=l1_ratio,
570
+ random_state=42,
571
+ )
572
+
573
+ assert_allclose(W1, W3, atol=1e-4)
574
+ assert_allclose(H1, H3, atol=1e-4)
575
+
576
+
577
+ def test_nmf_negative_beta_loss():
578
+ # Test that an error is raised if beta_loss < 0 and X contains zeros.
579
+ # Test that the output has not NaN values when the input contains zeros.
580
+ n_samples = 6
581
+ n_features = 5
582
+ n_components = 3
583
+
584
+ rng = np.random.mtrand.RandomState(42)
585
+ X = rng.randn(n_samples, n_features)
586
+ np.clip(X, 0, None, out=X)
587
+ X_csr = sp.csr_matrix(X)
588
+
589
+ def _assert_nmf_no_nan(X, beta_loss):
590
+ W, H, _ = non_negative_factorization(
591
+ X,
592
+ init="random",
593
+ n_components=n_components,
594
+ solver="mu",
595
+ beta_loss=beta_loss,
596
+ random_state=0,
597
+ max_iter=1000,
598
+ )
599
+ assert not np.any(np.isnan(W))
600
+ assert not np.any(np.isnan(H))
601
+
602
+ msg = "When beta_loss <= 0 and X contains zeros, the solver may diverge."
603
+ for beta_loss in (-0.6, 0.0):
604
+ with pytest.raises(ValueError, match=msg):
605
+ _assert_nmf_no_nan(X, beta_loss)
606
+ _assert_nmf_no_nan(X + 1e-9, beta_loss)
607
+
608
+ for beta_loss in (0.2, 1.0, 1.2, 2.0, 2.5):
609
+ _assert_nmf_no_nan(X, beta_loss)
610
+ _assert_nmf_no_nan(X_csr, beta_loss)
611
+
612
+
613
+ @pytest.mark.parametrize("beta_loss", [-0.5, 0.0])
614
+ def test_minibatch_nmf_negative_beta_loss(beta_loss):
615
+ """Check that an error is raised if beta_loss < 0 and X contains zeros."""
616
+ rng = np.random.RandomState(0)
617
+ X = rng.normal(size=(6, 5))
618
+ X[X < 0] = 0
619
+
620
+ nmf = MiniBatchNMF(beta_loss=beta_loss, random_state=0)
621
+
622
+ msg = "When beta_loss <= 0 and X contains zeros, the solver may diverge."
623
+ with pytest.raises(ValueError, match=msg):
624
+ nmf.fit(X)
625
+
626
+
627
+ @pytest.mark.parametrize(
628
+ ["Estimator", "solver"],
629
+ [[NMF, {"solver": "cd"}], [NMF, {"solver": "mu"}], [MiniBatchNMF, {}]],
630
+ )
631
+ def test_nmf_regularization(Estimator, solver):
632
+ # Test the effect of L1 and L2 regularizations
633
+ n_samples = 6
634
+ n_features = 5
635
+ n_components = 3
636
+ rng = np.random.mtrand.RandomState(42)
637
+ X = np.abs(rng.randn(n_samples, n_features))
638
+
639
+ # L1 regularization should increase the number of zeros
640
+ l1_ratio = 1.0
641
+ regul = Estimator(
642
+ n_components=n_components,
643
+ alpha_W=0.5,
644
+ l1_ratio=l1_ratio,
645
+ random_state=42,
646
+ **solver,
647
+ )
648
+ model = Estimator(
649
+ n_components=n_components,
650
+ alpha_W=0.0,
651
+ l1_ratio=l1_ratio,
652
+ random_state=42,
653
+ **solver,
654
+ )
655
+
656
+ W_regul = regul.fit_transform(X)
657
+ W_model = model.fit_transform(X)
658
+
659
+ H_regul = regul.components_
660
+ H_model = model.components_
661
+
662
+ eps = np.finfo(np.float64).eps
663
+ W_regul_n_zeros = W_regul[W_regul <= eps].size
664
+ W_model_n_zeros = W_model[W_model <= eps].size
665
+ H_regul_n_zeros = H_regul[H_regul <= eps].size
666
+ H_model_n_zeros = H_model[H_model <= eps].size
667
+
668
+ assert W_regul_n_zeros > W_model_n_zeros
669
+ assert H_regul_n_zeros > H_model_n_zeros
670
+
671
+ # L2 regularization should decrease the sum of the squared norm
672
+ # of the matrices W and H
673
+ l1_ratio = 0.0
674
+ regul = Estimator(
675
+ n_components=n_components,
676
+ alpha_W=0.5,
677
+ l1_ratio=l1_ratio,
678
+ random_state=42,
679
+ **solver,
680
+ )
681
+ model = Estimator(
682
+ n_components=n_components,
683
+ alpha_W=0.0,
684
+ l1_ratio=l1_ratio,
685
+ random_state=42,
686
+ **solver,
687
+ )
688
+
689
+ W_regul = regul.fit_transform(X)
690
+ W_model = model.fit_transform(X)
691
+
692
+ H_regul = regul.components_
693
+ H_model = model.components_
694
+
695
+ assert (linalg.norm(W_model)) ** 2.0 + (linalg.norm(H_model)) ** 2.0 > (
696
+ linalg.norm(W_regul)
697
+ ) ** 2.0 + (linalg.norm(H_regul)) ** 2.0
698
+
699
+
700
+ @ignore_warnings(category=ConvergenceWarning)
701
+ @pytest.mark.parametrize("solver", ("cd", "mu"))
702
+ def test_nmf_decreasing(solver):
703
+ # test that the objective function is decreasing at each iteration
704
+ n_samples = 20
705
+ n_features = 15
706
+ n_components = 10
707
+ alpha = 0.1
708
+ l1_ratio = 0.5
709
+ tol = 0.0
710
+
711
+ # initialization
712
+ rng = np.random.mtrand.RandomState(42)
713
+ X = rng.randn(n_samples, n_features)
714
+ np.abs(X, X)
715
+ W0, H0 = nmf._initialize_nmf(X, n_components, init="random", random_state=42)
716
+
717
+ for beta_loss in (-1.2, 0, 0.2, 1.0, 2.0, 2.5):
718
+ if solver != "mu" and beta_loss != 2:
719
+ # not implemented
720
+ continue
721
+ W, H = W0.copy(), H0.copy()
722
+ previous_loss = None
723
+ for _ in range(30):
724
+ # one more iteration starting from the previous results
725
+ W, H, _ = non_negative_factorization(
726
+ X,
727
+ W,
728
+ H,
729
+ beta_loss=beta_loss,
730
+ init="custom",
731
+ n_components=n_components,
732
+ max_iter=1,
733
+ alpha_W=alpha,
734
+ solver=solver,
735
+ tol=tol,
736
+ l1_ratio=l1_ratio,
737
+ verbose=0,
738
+ random_state=0,
739
+ update_H=True,
740
+ )
741
+
742
+ loss = (
743
+ nmf._beta_divergence(X, W, H, beta_loss)
744
+ + alpha * l1_ratio * n_features * W.sum()
745
+ + alpha * l1_ratio * n_samples * H.sum()
746
+ + alpha * (1 - l1_ratio) * n_features * (W**2).sum()
747
+ + alpha * (1 - l1_ratio) * n_samples * (H**2).sum()
748
+ )
749
+ if previous_loss is not None:
750
+ assert previous_loss > loss
751
+ previous_loss = loss
752
+
753
+
754
+ def test_nmf_underflow():
755
+ # Regression test for an underflow issue in _beta_divergence
756
+ rng = np.random.RandomState(0)
757
+ n_samples, n_features, n_components = 10, 2, 2
758
+ X = np.abs(rng.randn(n_samples, n_features)) * 10
759
+ W = np.abs(rng.randn(n_samples, n_components)) * 10
760
+ H = np.abs(rng.randn(n_components, n_features))
761
+
762
+ X[0, 0] = 0
763
+ ref = nmf._beta_divergence(X, W, H, beta=1.0)
764
+ X[0, 0] = 1e-323
765
+ res = nmf._beta_divergence(X, W, H, beta=1.0)
766
+ assert_almost_equal(res, ref)
767
+
768
+
769
+ @pytest.mark.parametrize(
770
+ "dtype_in, dtype_out",
771
+ [
772
+ (np.float32, np.float32),
773
+ (np.float64, np.float64),
774
+ (np.int32, np.float64),
775
+ (np.int64, np.float64),
776
+ ],
777
+ )
778
+ @pytest.mark.parametrize(
779
+ ["Estimator", "solver"],
780
+ [[NMF, {"solver": "cd"}], [NMF, {"solver": "mu"}], [MiniBatchNMF, {}]],
781
+ )
782
+ def test_nmf_dtype_match(Estimator, solver, dtype_in, dtype_out):
783
+ # Check that NMF preserves dtype (float32 and float64)
784
+ X = np.random.RandomState(0).randn(20, 15).astype(dtype_in, copy=False)
785
+ np.abs(X, out=X)
786
+
787
+ nmf = Estimator(alpha_W=1.0, alpha_H=1.0, tol=1e-2, random_state=0, **solver)
788
+
789
+ assert nmf.fit(X).transform(X).dtype == dtype_out
790
+ assert nmf.fit_transform(X).dtype == dtype_out
791
+ assert nmf.components_.dtype == dtype_out
792
+
793
+
794
+ @pytest.mark.parametrize(
795
+ ["Estimator", "solver"],
796
+ [[NMF, {"solver": "cd"}], [NMF, {"solver": "mu"}], [MiniBatchNMF, {}]],
797
+ )
798
+ def test_nmf_float32_float64_consistency(Estimator, solver):
799
+ # Check that the result of NMF is the same between float32 and float64
800
+ X = np.random.RandomState(0).randn(50, 7)
801
+ np.abs(X, out=X)
802
+ nmf32 = Estimator(random_state=0, tol=1e-3, **solver)
803
+ W32 = nmf32.fit_transform(X.astype(np.float32))
804
+ nmf64 = Estimator(random_state=0, tol=1e-3, **solver)
805
+ W64 = nmf64.fit_transform(X)
806
+
807
+ assert_allclose(W32, W64, atol=1e-5)
808
+
809
+
810
+ @pytest.mark.parametrize("Estimator", [NMF, MiniBatchNMF])
811
+ def test_nmf_custom_init_dtype_error(Estimator):
812
+ # Check that an error is raise if custom H and/or W don't have the same
813
+ # dtype as X.
814
+ rng = np.random.RandomState(0)
815
+ X = rng.random_sample((20, 15))
816
+ H = rng.random_sample((15, 15)).astype(np.float32)
817
+ W = rng.random_sample((20, 15))
818
+
819
+ with pytest.raises(TypeError, match="should have the same dtype as X"):
820
+ Estimator(init="custom").fit(X, H=H, W=W)
821
+
822
+ with pytest.raises(TypeError, match="should have the same dtype as X"):
823
+ non_negative_factorization(X, H=H, update_H=False)
824
+
825
+
826
+ @pytest.mark.parametrize("beta_loss", [-0.5, 0, 0.5, 1, 1.5, 2, 2.5])
827
+ def test_nmf_minibatchnmf_equivalence(beta_loss):
828
+ # Test that MiniBatchNMF is equivalent to NMF when batch_size = n_samples and
829
+ # forget_factor 0.0 (stopping criterion put aside)
830
+ rng = np.random.mtrand.RandomState(42)
831
+ X = np.abs(rng.randn(48, 5))
832
+
833
+ nmf = NMF(
834
+ n_components=5,
835
+ beta_loss=beta_loss,
836
+ solver="mu",
837
+ random_state=0,
838
+ tol=0,
839
+ )
840
+ mbnmf = MiniBatchNMF(
841
+ n_components=5,
842
+ beta_loss=beta_loss,
843
+ random_state=0,
844
+ tol=0,
845
+ max_no_improvement=None,
846
+ batch_size=X.shape[0],
847
+ forget_factor=0.0,
848
+ )
849
+ W = nmf.fit_transform(X)
850
+ mbW = mbnmf.fit_transform(X)
851
+ assert_allclose(W, mbW)
852
+
853
+
854
+ def test_minibatch_nmf_partial_fit():
855
+ # Check fit / partial_fit equivalence. Applicable only with fresh restarts.
856
+ rng = np.random.mtrand.RandomState(42)
857
+ X = np.abs(rng.randn(100, 5))
858
+
859
+ n_components = 5
860
+ batch_size = 10
861
+ max_iter = 2
862
+
863
+ mbnmf1 = MiniBatchNMF(
864
+ n_components=n_components,
865
+ init="custom",
866
+ random_state=0,
867
+ max_iter=max_iter,
868
+ batch_size=batch_size,
869
+ tol=0,
870
+ max_no_improvement=None,
871
+ fresh_restarts=False,
872
+ )
873
+ mbnmf2 = MiniBatchNMF(n_components=n_components, init="custom", random_state=0)
874
+
875
+ # Force the same init of H (W is recomputed anyway) to be able to compare results.
876
+ W, H = nmf._initialize_nmf(
877
+ X, n_components=n_components, init="random", random_state=0
878
+ )
879
+
880
+ mbnmf1.fit(X, W=W, H=H)
881
+ for i in range(max_iter):
882
+ for j in range(batch_size):
883
+ mbnmf2.partial_fit(X[j : j + batch_size], W=W[:batch_size], H=H)
884
+
885
+ assert mbnmf1.n_steps_ == mbnmf2.n_steps_
886
+ assert_allclose(mbnmf1.components_, mbnmf2.components_)
887
+
888
+
889
+ def test_feature_names_out():
890
+ """Check feature names out for NMF."""
891
+ random_state = np.random.RandomState(0)
892
+ X = np.abs(random_state.randn(10, 4))
893
+ nmf = NMF(n_components=3).fit(X)
894
+
895
+ names = nmf.get_feature_names_out()
896
+ assert_array_equal([f"nmf{i}" for i in range(3)], names)
897
+
898
+
899
+ def test_minibatch_nmf_verbose():
900
+ # Check verbose mode of MiniBatchNMF for better coverage.
901
+ A = np.random.RandomState(0).random_sample((100, 10))
902
+ nmf = MiniBatchNMF(tol=1e-2, random_state=0, verbose=1)
903
+ old_stdout = sys.stdout
904
+ sys.stdout = StringIO()
905
+ try:
906
+ nmf.fit(A)
907
+ finally:
908
+ sys.stdout = old_stdout
videollama2/lib/python3.10/site-packages/sklearn/decomposition/tests/test_truncated_svd.py ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Test truncated SVD transformer."""
2
+
3
+ import numpy as np
4
+ import scipy.sparse as sp
5
+
6
+ import pytest
7
+
8
+ from sklearn.decomposition import TruncatedSVD, PCA
9
+ from sklearn.utils import check_random_state
10
+ from sklearn.utils._testing import assert_array_less, assert_allclose
11
+
12
+ SVD_SOLVERS = ["arpack", "randomized"]
13
+
14
+
15
+ @pytest.fixture(scope="module")
16
+ def X_sparse():
17
+ # Make an X that looks somewhat like a small tf-idf matrix.
18
+ rng = check_random_state(42)
19
+ X = sp.random(60, 55, density=0.2, format="csr", random_state=rng)
20
+ X.data[:] = 1 + np.log(X.data)
21
+ return X
22
+
23
+
24
+ @pytest.mark.parametrize("solver", ["randomized"])
25
+ @pytest.mark.parametrize("kind", ("dense", "sparse"))
26
+ def test_solvers(X_sparse, solver, kind):
27
+ X = X_sparse if kind == "sparse" else X_sparse.toarray()
28
+ svd_a = TruncatedSVD(30, algorithm="arpack")
29
+ svd = TruncatedSVD(30, algorithm=solver, random_state=42, n_oversamples=100)
30
+
31
+ Xa = svd_a.fit_transform(X)[:, :6]
32
+ Xr = svd.fit_transform(X)[:, :6]
33
+ assert_allclose(Xa, Xr, rtol=2e-3)
34
+
35
+ comp_a = np.abs(svd_a.components_)
36
+ comp = np.abs(svd.components_)
37
+ # All elements are equal, but some elements are more equal than others.
38
+ assert_allclose(comp_a[:9], comp[:9], rtol=1e-3)
39
+ assert_allclose(comp_a[9:], comp[9:], atol=1e-2)
40
+
41
+
42
+ @pytest.mark.parametrize("n_components", (10, 25, 41, 55))
43
+ def test_attributes(n_components, X_sparse):
44
+ n_features = X_sparse.shape[1]
45
+ tsvd = TruncatedSVD(n_components).fit(X_sparse)
46
+ assert tsvd.n_components == n_components
47
+ assert tsvd.components_.shape == (n_components, n_features)
48
+
49
+
50
+ @pytest.mark.parametrize(
51
+ "algorithm, n_components",
52
+ [
53
+ ("arpack", 55),
54
+ ("arpack", 56),
55
+ ("randomized", 56),
56
+ ],
57
+ )
58
+ def test_too_many_components(X_sparse, algorithm, n_components):
59
+ tsvd = TruncatedSVD(n_components=n_components, algorithm=algorithm)
60
+ with pytest.raises(ValueError):
61
+ tsvd.fit(X_sparse)
62
+
63
+
64
+ @pytest.mark.parametrize("fmt", ("array", "csr", "csc", "coo", "lil"))
65
+ def test_sparse_formats(fmt, X_sparse):
66
+ n_samples = X_sparse.shape[0]
67
+ Xfmt = X_sparse.toarray() if fmt == "dense" else getattr(X_sparse, "to" + fmt)()
68
+ tsvd = TruncatedSVD(n_components=11)
69
+ Xtrans = tsvd.fit_transform(Xfmt)
70
+ assert Xtrans.shape == (n_samples, 11)
71
+ Xtrans = tsvd.transform(Xfmt)
72
+ assert Xtrans.shape == (n_samples, 11)
73
+
74
+
75
+ @pytest.mark.parametrize("algo", SVD_SOLVERS)
76
+ def test_inverse_transform(algo, X_sparse):
77
+ # We need a lot of components for the reconstruction to be "almost
78
+ # equal" in all positions. XXX Test means or sums instead?
79
+ tsvd = TruncatedSVD(n_components=52, random_state=42, algorithm=algo)
80
+ Xt = tsvd.fit_transform(X_sparse)
81
+ Xinv = tsvd.inverse_transform(Xt)
82
+ assert_allclose(Xinv, X_sparse.toarray(), rtol=1e-1, atol=2e-1)
83
+
84
+
85
+ def test_integers(X_sparse):
86
+ n_samples = X_sparse.shape[0]
87
+ Xint = X_sparse.astype(np.int64)
88
+ tsvd = TruncatedSVD(n_components=6)
89
+ Xtrans = tsvd.fit_transform(Xint)
90
+ assert Xtrans.shape == (n_samples, tsvd.n_components)
91
+
92
+
93
+ @pytest.mark.parametrize("kind", ("dense", "sparse"))
94
+ @pytest.mark.parametrize("n_components", [10, 20])
95
+ @pytest.mark.parametrize("solver", SVD_SOLVERS)
96
+ def test_explained_variance(X_sparse, kind, n_components, solver):
97
+ X = X_sparse if kind == "sparse" else X_sparse.toarray()
98
+ svd = TruncatedSVD(n_components, algorithm=solver)
99
+ X_tr = svd.fit_transform(X)
100
+ # Assert that all the values are greater than 0
101
+ assert_array_less(0.0, svd.explained_variance_ratio_)
102
+
103
+ # Assert that total explained variance is less than 1
104
+ assert_array_less(svd.explained_variance_ratio_.sum(), 1.0)
105
+
106
+ # Test that explained_variance is correct
107
+ total_variance = np.var(X_sparse.toarray(), axis=0).sum()
108
+ variances = np.var(X_tr, axis=0)
109
+ true_explained_variance_ratio = variances / total_variance
110
+
111
+ assert_allclose(
112
+ svd.explained_variance_ratio_,
113
+ true_explained_variance_ratio,
114
+ )
115
+
116
+
117
+ @pytest.mark.parametrize("kind", ("dense", "sparse"))
118
+ @pytest.mark.parametrize("solver", SVD_SOLVERS)
119
+ def test_explained_variance_components_10_20(X_sparse, kind, solver):
120
+ X = X_sparse if kind == "sparse" else X_sparse.toarray()
121
+ svd_10 = TruncatedSVD(10, algorithm=solver, n_iter=10).fit(X)
122
+ svd_20 = TruncatedSVD(20, algorithm=solver, n_iter=10).fit(X)
123
+
124
+ # Assert the 1st component is equal
125
+ assert_allclose(
126
+ svd_10.explained_variance_ratio_,
127
+ svd_20.explained_variance_ratio_[:10],
128
+ rtol=5e-3,
129
+ )
130
+
131
+ # Assert that 20 components has higher explained variance than 10
132
+ assert (
133
+ svd_20.explained_variance_ratio_.sum() > svd_10.explained_variance_ratio_.sum()
134
+ )
135
+
136
+
137
+ @pytest.mark.parametrize("solver", SVD_SOLVERS)
138
+ def test_singular_values_consistency(solver):
139
+ # Check that the TruncatedSVD output has the correct singular values
140
+ rng = np.random.RandomState(0)
141
+ n_samples, n_features = 100, 80
142
+ X = rng.randn(n_samples, n_features)
143
+
144
+ pca = TruncatedSVD(n_components=2, algorithm=solver, random_state=rng).fit(X)
145
+
146
+ # Compare to the Frobenius norm
147
+ X_pca = pca.transform(X)
148
+ assert_allclose(
149
+ np.sum(pca.singular_values_**2.0),
150
+ np.linalg.norm(X_pca, "fro") ** 2.0,
151
+ rtol=1e-2,
152
+ )
153
+
154
+ # Compare to the 2-norms of the score vectors
155
+ assert_allclose(
156
+ pca.singular_values_, np.sqrt(np.sum(X_pca**2.0, axis=0)), rtol=1e-2
157
+ )
158
+
159
+
160
+ @pytest.mark.parametrize("solver", SVD_SOLVERS)
161
+ def test_singular_values_expected(solver):
162
+ # Set the singular values and see what we get back
163
+ rng = np.random.RandomState(0)
164
+ n_samples = 100
165
+ n_features = 110
166
+
167
+ X = rng.randn(n_samples, n_features)
168
+
169
+ pca = TruncatedSVD(n_components=3, algorithm=solver, random_state=rng)
170
+ X_pca = pca.fit_transform(X)
171
+
172
+ X_pca /= np.sqrt(np.sum(X_pca**2.0, axis=0))
173
+ X_pca[:, 0] *= 3.142
174
+ X_pca[:, 1] *= 2.718
175
+
176
+ X_hat_pca = np.dot(X_pca, pca.components_)
177
+ pca.fit(X_hat_pca)
178
+ assert_allclose(pca.singular_values_, [3.142, 2.718, 1.0], rtol=1e-14)
179
+
180
+
181
+ def test_truncated_svd_eq_pca(X_sparse):
182
+ # TruncatedSVD should be equal to PCA on centered data
183
+
184
+ X_dense = X_sparse.toarray()
185
+
186
+ X_c = X_dense - X_dense.mean(axis=0)
187
+
188
+ params = dict(n_components=10, random_state=42)
189
+
190
+ svd = TruncatedSVD(algorithm="arpack", **params)
191
+ pca = PCA(svd_solver="arpack", **params)
192
+
193
+ Xt_svd = svd.fit_transform(X_c)
194
+ Xt_pca = pca.fit_transform(X_c)
195
+
196
+ assert_allclose(Xt_svd, Xt_pca, rtol=1e-9)
197
+ assert_allclose(pca.mean_, 0, atol=1e-9)
198
+ assert_allclose(svd.components_, pca.components_)
199
+
200
+
201
+ @pytest.mark.parametrize(
202
+ "algorithm, tol", [("randomized", 0.0), ("arpack", 1e-6), ("arpack", 0.0)]
203
+ )
204
+ @pytest.mark.parametrize("kind", ("dense", "sparse"))
205
+ def test_fit_transform(X_sparse, algorithm, tol, kind):
206
+ # fit_transform(X) should equal fit(X).transform(X)
207
+ X = X_sparse if kind == "sparse" else X_sparse.toarray()
208
+ svd = TruncatedSVD(
209
+ n_components=5, n_iter=7, random_state=42, algorithm=algorithm, tol=tol
210
+ )
211
+ X_transformed_1 = svd.fit_transform(X)
212
+ X_transformed_2 = svd.fit(X).transform(X)
213
+ assert_allclose(X_transformed_1, X_transformed_2)
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_cast_Double_native.h ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from NativeFunction.h
4
+
5
+ #include <c10/core/Scalar.h>
6
+ #include <c10/core/Storage.h>
7
+ #include <c10/core/TensorOptions.h>
8
+ #include <c10/util/Deprecated.h>
9
+ #include <optional>
10
+ #include <c10/core/QScheme.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <tuple>
14
+ #include <vector>
15
+
16
+
17
+ namespace at {
18
+ namespace native {
19
+ TORCH_API at::Tensor _cast_Double(const at::Tensor & self, bool non_blocking=false);
20
+ } // namespace native
21
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_cummin_helper_cpu_dispatch.h ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
3
+
4
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
5
+
6
+ // The only #includes we need are for custom classes that have defaults in the C++ API
7
+ #include <c10/core/MemoryFormat.h>
8
+ #include <c10/core/Scalar.h>
9
+ #include <ATen/core/Reduction.h>
10
+
11
+ // Forward declarations of any types needed in the operator signatures.
12
+ // We can't directly include these classes because it will cause circular include dependencies.
13
+ // This file is included by TensorBody.h, which defines the Tensor class.
14
+ #include <ATen/core/ATen_fwd.h>
15
+
16
+ namespace at {
17
+
18
+ namespace cpu {
19
+
20
+ TORCH_API void _cummin_helper(const at::Tensor & self, at::Tensor & values, at::Tensor & indices, int64_t dim);
21
+
22
+ } // namespace cpu
23
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_debug_has_internal_overlap_native.h ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from NativeFunction.h
4
+
5
+ #include <c10/core/Scalar.h>
6
+ #include <c10/core/Storage.h>
7
+ #include <c10/core/TensorOptions.h>
8
+ #include <c10/util/Deprecated.h>
9
+ #include <optional>
10
+ #include <c10/core/QScheme.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <tuple>
14
+ #include <vector>
15
+
16
+
17
+ namespace at {
18
+ namespace native {
19
+ TORCH_API int64_t _debug_has_internal_overlap(const at::Tensor & self);
20
+ } // namespace native
21
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_ceil.h ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Function.h
4
+
5
+ #include <ATen/Context.h>
6
+ #include <ATen/DeviceGuard.h>
7
+ #include <ATen/TensorUtils.h>
8
+ #include <ATen/TracerMode.h>
9
+ #include <ATen/core/Generator.h>
10
+ #include <ATen/core/Reduction.h>
11
+ #include <ATen/core/Tensor.h>
12
+ #include <c10/core/Scalar.h>
13
+ #include <c10/core/Storage.h>
14
+ #include <c10/core/TensorOptions.h>
15
+ #include <c10/util/Deprecated.h>
16
+ #include <optional>
17
+
18
+
19
+
20
+ #include <ATen/ops/_foreach_ceil_ops.h>
21
+
22
+ namespace at {
23
+
24
+
25
+ // aten::_foreach_ceil(Tensor[] self) -> Tensor[]
26
+ inline ::std::vector<at::Tensor> _foreach_ceil(at::TensorList self) {
27
+ return at::_ops::_foreach_ceil::call(self);
28
+ }
29
+
30
+ // aten::_foreach_ceil_(Tensor(a!)[] self) -> ()
31
+ inline void _foreach_ceil_(at::TensorList self) {
32
+ return at::_ops::_foreach_ceil_::call(self);
33
+ }
34
+
35
+ // aten::_foreach_ceil.out(Tensor[] self, *, Tensor(a!)[] out) -> ()
36
+ inline void _foreach_ceil_out(at::TensorList out, at::TensorList self) {
37
+ return at::_ops::_foreach_ceil_out::call(self, out);
38
+ }
39
+ // aten::_foreach_ceil.out(Tensor[] self, *, Tensor(a!)[] out) -> ()
40
+ inline void _foreach_ceil_outf(at::TensorList self, at::TensorList out) {
41
+ return at::_ops::_foreach_ceil_out::call(self, out);
42
+ }
43
+
44
+ }
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_erf_ops.h ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Operator.h
4
+
5
+ #include <tuple>
6
+ #include <vector>
7
+
8
+ // Forward declarations of any types needed in the operator signatures.
9
+ // We can't directly include these classes because it will cause circular include dependencies.
10
+ // This file is included by TensorBody.h, which defines the Tensor class.
11
+ #include <ATen/core/ATen_fwd.h>
12
+
13
+ namespace at {
14
+ namespace _ops {
15
+
16
+
17
+ struct TORCH_API _foreach_erf {
18
+ using schema = ::std::vector<at::Tensor> (at::TensorList);
19
+ using ptr_schema = schema*;
20
+ // See Note [static constexpr char* members for windows NVCC]
21
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_foreach_erf")
22
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
23
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_foreach_erf(Tensor[] self) -> Tensor[]")
24
+ static ::std::vector<at::Tensor> call(at::TensorList self);
25
+ static ::std::vector<at::Tensor> redispatch(c10::DispatchKeySet dispatchKeySet, at::TensorList self);
26
+ };
27
+
28
+ struct TORCH_API _foreach_erf_ {
29
+ using schema = void (at::TensorList);
30
+ using ptr_schema = schema*;
31
+ // See Note [static constexpr char* members for windows NVCC]
32
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_foreach_erf_")
33
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
34
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_foreach_erf_(Tensor(a!)[] self) -> ()")
35
+ static void call(at::TensorList self);
36
+ static void redispatch(c10::DispatchKeySet dispatchKeySet, at::TensorList self);
37
+ };
38
+
39
+ struct TORCH_API _foreach_erf_out {
40
+ using schema = void (at::TensorList, at::TensorList);
41
+ using ptr_schema = schema*;
42
+ // See Note [static constexpr char* members for windows NVCC]
43
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_foreach_erf")
44
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
45
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_foreach_erf.out(Tensor[] self, *, Tensor(a!)[] out) -> ()")
46
+ static void call(at::TensorList self, at::TensorList out);
47
+ static void redispatch(c10::DispatchKeySet dispatchKeySet, at::TensorList self, at::TensorList out);
48
+ };
49
+
50
+ }} // namespace at::_ops
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_norm.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Function.h
4
+
5
+ #include <ATen/Context.h>
6
+ #include <ATen/DeviceGuard.h>
7
+ #include <ATen/TensorUtils.h>
8
+ #include <ATen/TracerMode.h>
9
+ #include <ATen/core/Generator.h>
10
+ #include <ATen/core/Reduction.h>
11
+ #include <ATen/core/Tensor.h>
12
+ #include <c10/core/Scalar.h>
13
+ #include <c10/core/Storage.h>
14
+ #include <c10/core/TensorOptions.h>
15
+ #include <c10/util/Deprecated.h>
16
+ #include <optional>
17
+
18
+
19
+
20
+ #include <ATen/ops/_foreach_norm_ops.h>
21
+
22
+ namespace at {
23
+
24
+
25
+ // aten::_foreach_norm.Scalar(Tensor[] self, Scalar ord=2, ScalarType? dtype=None) -> Tensor[]
26
+ inline ::std::vector<at::Tensor> _foreach_norm(at::TensorList self, const at::Scalar & ord=2, ::std::optional<at::ScalarType> dtype=::std::nullopt) {
27
+ return at::_ops::_foreach_norm_Scalar::call(self, ord, dtype);
28
+ }
29
+
30
+ // aten::_foreach_norm.Scalar_out(Tensor[] self, Scalar ord=2, ScalarType? dtype=None, *, Tensor(a!)[] out) -> ()
31
+ inline void _foreach_norm_out(at::TensorList out, at::TensorList self, const at::Scalar & ord=2, ::std::optional<at::ScalarType> dtype=::std::nullopt) {
32
+ return at::_ops::_foreach_norm_Scalar_out::call(self, ord, dtype, out);
33
+ }
34
+ // aten::_foreach_norm.Scalar_out(Tensor[] self, Scalar ord=2, ScalarType? dtype=None, *, Tensor(a!)[] out) -> ()
35
+ inline void _foreach_norm_outf(at::TensorList self, const at::Scalar & ord, ::std::optional<at::ScalarType> dtype, at::TensorList out) {
36
+ return at::_ops::_foreach_norm_Scalar_out::call(self, ord, dtype, out);
37
+ }
38
+
39
+ }
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_foreach_round_compositeexplicitautograd_dispatch.h ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
3
+
4
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
5
+
6
+ // The only #includes we need are for custom classes that have defaults in the C++ API
7
+ #include <c10/core/MemoryFormat.h>
8
+ #include <c10/core/Scalar.h>
9
+ #include <ATen/core/Reduction.h>
10
+
11
+ // Forward declarations of any types needed in the operator signatures.
12
+ // We can't directly include these classes because it will cause circular include dependencies.
13
+ // This file is included by TensorBody.h, which defines the Tensor class.
14
+ #include <ATen/core/ATen_fwd.h>
15
+
16
+ namespace at {
17
+
18
+ namespace compositeexplicitautograd {
19
+
20
+ TORCH_API ::std::vector<at::Tensor> _foreach_round(at::TensorList self);
21
+ TORCH_API void _foreach_round_out(at::TensorList out, at::TensorList self);
22
+ TORCH_API void _foreach_round_outf(at::TensorList self, at::TensorList out);
23
+ TORCH_API void _foreach_round_(at::TensorList self);
24
+
25
+ } // namespace compositeexplicitautograd
26
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_functional_assert_scalar_ops.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Operator.h
4
+
5
+ #include <tuple>
6
+ #include <vector>
7
+
8
+ // Forward declarations of any types needed in the operator signatures.
9
+ // We can't directly include these classes because it will cause circular include dependencies.
10
+ // This file is included by TensorBody.h, which defines the Tensor class.
11
+ #include <ATen/core/ATen_fwd.h>
12
+
13
+ namespace at {
14
+ namespace _ops {
15
+
16
+
17
+ struct TORCH_API _functional_assert_scalar {
18
+ using schema = at::Tensor (const at::Scalar &, c10::string_view, const at::Tensor &);
19
+ using ptr_schema = schema*;
20
+ // See Note [static constexpr char* members for windows NVCC]
21
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_functional_assert_scalar")
22
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
23
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_functional_assert_scalar(Scalar self, str assert_msg, Tensor dep_token) -> Tensor")
24
+ static at::Tensor call(const at::Scalar & self, c10::string_view assert_msg, const at::Tensor & dep_token);
25
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Scalar & self, c10::string_view assert_msg, const at::Tensor & dep_token);
26
+ };
27
+
28
+ }} // namespace at::_ops
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_histogramdd_bin_edges.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Function.h
4
+
5
+ #include <ATen/Context.h>
6
+ #include <ATen/DeviceGuard.h>
7
+ #include <ATen/TensorUtils.h>
8
+ #include <ATen/TracerMode.h>
9
+ #include <ATen/core/Generator.h>
10
+ #include <ATen/core/Reduction.h>
11
+ #include <ATen/core/Tensor.h>
12
+ #include <c10/core/Scalar.h>
13
+ #include <c10/core/Storage.h>
14
+ #include <c10/core/TensorOptions.h>
15
+ #include <c10/util/Deprecated.h>
16
+ #include <optional>
17
+
18
+
19
+
20
+ #include <ATen/ops/_histogramdd_bin_edges_ops.h>
21
+
22
+ namespace at {
23
+
24
+
25
+ // aten::_histogramdd_bin_edges(Tensor self, int[] bins, *, float[]? range=None, Tensor? weight=None, bool density=False) -> Tensor[]
26
+ inline ::std::vector<at::Tensor> _histogramdd_bin_edges(const at::Tensor & self, at::IntArrayRef bins, ::std::optional<at::ArrayRef<double>> range=::std::nullopt, const ::std::optional<at::Tensor> & weight={}, bool density=false) {
27
+ return at::_ops::_histogramdd_bin_edges::call(self, bins, range, weight, density);
28
+ }
29
+
30
+ // aten::_histogramdd_bin_edges.out(Tensor self, int[] bins, *, float[]? range=None, Tensor? weight=None, bool density=False, Tensor(a!)[] out) -> ()
31
+ inline void _histogramdd_bin_edges_out(at::TensorList out, const at::Tensor & self, at::IntArrayRef bins, ::std::optional<at::ArrayRef<double>> range=::std::nullopt, const ::std::optional<at::Tensor> & weight={}, bool density=false) {
32
+ return at::_ops::_histogramdd_bin_edges_out::call(self, bins, range, weight, density, out);
33
+ }
34
+ // aten::_histogramdd_bin_edges.out(Tensor self, int[] bins, *, float[]? range=None, Tensor? weight=None, bool density=False, Tensor(a!)[] out) -> ()
35
+ inline void _histogramdd_bin_edges_outf(const at::Tensor & self, at::IntArrayRef bins, ::std::optional<at::ArrayRef<double>> range, const ::std::optional<at::Tensor> & weight, bool density, at::TensorList out) {
36
+ return at::_ops::_histogramdd_bin_edges_out::call(self, bins, range, weight, density, out);
37
+ }
38
+
39
+ }
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_log_softmax_cpu_dispatch.h ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
3
+
4
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
5
+
6
+ // The only #includes we need are for custom classes that have defaults in the C++ API
7
+ #include <c10/core/MemoryFormat.h>
8
+ #include <c10/core/Scalar.h>
9
+ #include <ATen/core/Reduction.h>
10
+
11
+ // Forward declarations of any types needed in the operator signatures.
12
+ // We can't directly include these classes because it will cause circular include dependencies.
13
+ // This file is included by TensorBody.h, which defines the Tensor class.
14
+ #include <ATen/core/ATen_fwd.h>
15
+
16
+ namespace at {
17
+
18
+ namespace cpu {
19
+
20
+ TORCH_API at::Tensor _log_softmax(const at::Tensor & self, int64_t dim, bool half_to_float);
21
+ TORCH_API at::Tensor & _log_softmax_out(at::Tensor & out, const at::Tensor & self, int64_t dim, bool half_to_float);
22
+ TORCH_API at::Tensor & _log_softmax_outf(const at::Tensor & self, int64_t dim, bool half_to_float, at::Tensor & out);
23
+
24
+ } // namespace cpu
25
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_sample_dirichlet_ops.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Operator.h
4
+
5
+ #include <tuple>
6
+ #include <vector>
7
+
8
+ // Forward declarations of any types needed in the operator signatures.
9
+ // We can't directly include these classes because it will cause circular include dependencies.
10
+ // This file is included by TensorBody.h, which defines the Tensor class.
11
+ #include <ATen/core/ATen_fwd.h>
12
+
13
+ namespace at {
14
+ namespace _ops {
15
+
16
+
17
+ struct TORCH_API _sample_dirichlet {
18
+ using schema = at::Tensor (const at::Tensor &, ::std::optional<at::Generator>);
19
+ using ptr_schema = schema*;
20
+ // See Note [static constexpr char* members for windows NVCC]
21
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_sample_dirichlet")
22
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
23
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_sample_dirichlet(Tensor self, Generator? generator=None) -> Tensor")
24
+ static at::Tensor call(const at::Tensor & self, ::std::optional<at::Generator> generator);
25
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, ::std::optional<at::Generator> generator);
26
+ };
27
+
28
+ struct TORCH_API _sample_dirichlet_out {
29
+ using schema = at::Tensor & (const at::Tensor &, ::std::optional<at::Generator>, at::Tensor &);
30
+ using ptr_schema = schema*;
31
+ // See Note [static constexpr char* members for windows NVCC]
32
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_sample_dirichlet")
33
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
34
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_sample_dirichlet.out(Tensor self, Generator? generator=None, *, Tensor(a!) out) -> Tensor(a!)")
35
+ static at::Tensor & call(const at::Tensor & self, ::std::optional<at::Generator> generator, at::Tensor & out);
36
+ static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, ::std::optional<at::Generator> generator, at::Tensor & out);
37
+ };
38
+
39
+ }} // namespace at::_ops
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_sobol_engine_ff.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Function.h
4
+
5
+ #include <ATen/Context.h>
6
+ #include <ATen/DeviceGuard.h>
7
+ #include <ATen/TensorUtils.h>
8
+ #include <ATen/TracerMode.h>
9
+ #include <ATen/core/Generator.h>
10
+ #include <ATen/core/Reduction.h>
11
+ #include <ATen/core/Tensor.h>
12
+ #include <c10/core/Scalar.h>
13
+ #include <c10/core/Storage.h>
14
+ #include <c10/core/TensorOptions.h>
15
+ #include <c10/util/Deprecated.h>
16
+ #include <optional>
17
+
18
+
19
+
20
+ #include <ATen/ops/_sobol_engine_ff_ops.h>
21
+
22
+ namespace at {
23
+
24
+
25
+ // aten::_sobol_engine_ff_(Tensor(a!) self, int n, Tensor sobolstate, int dimension, int num_generated) -> Tensor(a!)
26
+ inline at::Tensor & _sobol_engine_ff_(at::Tensor & self, int64_t n, const at::Tensor & sobolstate, int64_t dimension, int64_t num_generated) {
27
+ return at::_ops::_sobol_engine_ff_::call(self, n, sobolstate, dimension, num_generated);
28
+ }
29
+
30
+ }
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_sparse_log_softmax_backward_data_native.h ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from NativeFunction.h
4
+
5
+ #include <c10/core/Scalar.h>
6
+ #include <c10/core/Storage.h>
7
+ #include <c10/core/TensorOptions.h>
8
+ #include <c10/util/Deprecated.h>
9
+ #include <optional>
10
+ #include <c10/core/QScheme.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <tuple>
14
+ #include <vector>
15
+
16
+
17
+ namespace at {
18
+ namespace native {
19
+ TORCH_API at::Tensor & _sparse_log_softmax_backward_data_out(const at::Tensor & grad_output, const at::Tensor & output, int64_t dim, const at::Tensor & self, at::Tensor & out);
20
+ TORCH_API at::Tensor log_softmax_backward_sparse_cpu(const at::Tensor & grad_output, const at::Tensor & output, int64_t dim, const at::Tensor & self);
21
+ TORCH_API at::Tensor log_softmax_backward_sparse_cuda(const at::Tensor & grad_output, const at::Tensor & output, int64_t dim, const at::Tensor & self);
22
+ } // namespace native
23
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_test_optional_intlist.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Function.h
4
+
5
+ #include <ATen/Context.h>
6
+ #include <ATen/DeviceGuard.h>
7
+ #include <ATen/TensorUtils.h>
8
+ #include <ATen/TracerMode.h>
9
+ #include <ATen/core/Generator.h>
10
+ #include <ATen/core/Reduction.h>
11
+ #include <ATen/core/Tensor.h>
12
+ #include <c10/core/Scalar.h>
13
+ #include <c10/core/Storage.h>
14
+ #include <c10/core/TensorOptions.h>
15
+ #include <c10/util/Deprecated.h>
16
+ #include <optional>
17
+
18
+
19
+
20
+ #include <ATen/ops/_test_optional_intlist_ops.h>
21
+
22
+ namespace at {
23
+
24
+
25
+ // aten::_test_optional_intlist(Tensor values, int[]? addends) -> Tensor
26
+ inline at::Tensor _test_optional_intlist(const at::Tensor & values, at::OptionalIntArrayRef addends) {
27
+ return at::_ops::_test_optional_intlist::call(values, addends);
28
+ }
29
+
30
+ // aten::_test_optional_intlist.out(Tensor values, int[]? addends, *, Tensor(a!) out) -> Tensor(a!)
31
+ inline at::Tensor & _test_optional_intlist_out(at::Tensor & out, const at::Tensor & values, at::OptionalIntArrayRef addends) {
32
+ return at::_ops::_test_optional_intlist_out::call(values, addends, out);
33
+ }
34
+ // aten::_test_optional_intlist.out(Tensor values, int[]? addends, *, Tensor(a!) out) -> Tensor(a!)
35
+ inline at::Tensor & _test_optional_intlist_outf(const at::Tensor & values, at::OptionalIntArrayRef addends, at::Tensor & out) {
36
+ return at::_ops::_test_optional_intlist_out::call(values, addends, out);
37
+ }
38
+
39
+ }
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_to_sparse_csr_native.h ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from NativeFunction.h
4
+
5
+ #include <c10/core/Scalar.h>
6
+ #include <c10/core/Storage.h>
7
+ #include <c10/core/TensorOptions.h>
8
+ #include <c10/util/Deprecated.h>
9
+ #include <optional>
10
+ #include <c10/core/QScheme.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <tuple>
14
+ #include <vector>
15
+
16
+
17
+ namespace at {
18
+ namespace native {
19
+ TORCH_API at::Tensor & _to_sparse_csr_out(const at::Tensor & self, ::std::optional<int64_t> dense_dim, at::Tensor & out);
20
+ TORCH_API at::Tensor dense_to_sparse_csr(const at::Tensor & self, ::std::optional<int64_t> dense_dim=::std::nullopt);
21
+ TORCH_API at::Tensor coo_to_sparse_csr(const at::Tensor & self, ::std::optional<int64_t> dense_dim=::std::nullopt);
22
+ TORCH_API at::Tensor sparse_compressed_to_sparse_csr(const at::Tensor & self, ::std::optional<int64_t> dense_dim=::std::nullopt);
23
+ } // namespace native
24
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_upsample_bicubic2d_aa_backward_native.h ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from NativeFunction.h
4
+
5
+ #include <c10/core/Scalar.h>
6
+ #include <c10/core/Storage.h>
7
+ #include <c10/core/TensorOptions.h>
8
+ #include <c10/util/Deprecated.h>
9
+ #include <optional>
10
+ #include <c10/core/QScheme.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <tuple>
14
+ #include <vector>
15
+ #include <ATen/ops/_upsample_bicubic2d_aa_backward_meta.h>
16
+
17
+ namespace at {
18
+ namespace native {
19
+ struct TORCH_API structured__upsample_bicubic2d_aa_backward_out_cpu : public at::meta::structured__upsample_bicubic2d_aa_backward {
20
+ void impl(const at::Tensor & grad_output, at::ArrayRef<int64_t> output_size, at::ArrayRef<int64_t> input_size, bool align_corners, ::std::optional<double> scales_h, ::std::optional<double> scales_w, const at::Tensor & grad_input);
21
+ };
22
+ struct TORCH_API structured__upsample_bicubic2d_aa_backward_out_cuda : public at::meta::structured__upsample_bicubic2d_aa_backward {
23
+ void impl(const at::Tensor & grad_output, at::ArrayRef<int64_t> output_size, at::ArrayRef<int64_t> input_size, bool align_corners, ::std::optional<double> scales_h, ::std::optional<double> scales_w, const at::Tensor & grad_input);
24
+ };
25
+ } // namespace native
26
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_int4pack_mm.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Function.h
4
+
5
+ #include <ATen/Context.h>
6
+ #include <ATen/DeviceGuard.h>
7
+ #include <ATen/TensorUtils.h>
8
+ #include <ATen/TracerMode.h>
9
+ #include <ATen/core/Generator.h>
10
+ #include <ATen/core/Reduction.h>
11
+ #include <ATen/core/Tensor.h>
12
+ #include <c10/core/Scalar.h>
13
+ #include <c10/core/Storage.h>
14
+ #include <c10/core/TensorOptions.h>
15
+ #include <c10/util/Deprecated.h>
16
+ #include <optional>
17
+
18
+
19
+
20
+ #include <ATen/ops/_weight_int4pack_mm_ops.h>
21
+
22
+ namespace at {
23
+
24
+
25
+ // aten::_weight_int4pack_mm(Tensor self, Tensor mat2, int qGroupSize, Tensor qScaleAndZeros) -> Tensor
26
+ inline at::Tensor _weight_int4pack_mm(const at::Tensor & self, const at::Tensor & mat2, int64_t qGroupSize, const at::Tensor & qScaleAndZeros) {
27
+ return at::_ops::_weight_int4pack_mm::call(self, mat2, qGroupSize, qScaleAndZeros);
28
+ }
29
+
30
+ }
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_norm_differentiable_backward_compositeimplicitautograd_dispatch.h ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
3
+
4
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
5
+
6
+ // The only #includes we need are for custom classes that have defaults in the C++ API
7
+ #include <c10/core/MemoryFormat.h>
8
+ #include <c10/core/Scalar.h>
9
+ #include <ATen/core/Reduction.h>
10
+
11
+ // Forward declarations of any types needed in the operator signatures.
12
+ // We can't directly include these classes because it will cause circular include dependencies.
13
+ // This file is included by TensorBody.h, which defines the Tensor class.
14
+ #include <ATen/core/ATen_fwd.h>
15
+
16
+ namespace at {
17
+
18
+ namespace compositeimplicitautograd {
19
+
20
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor> _weight_norm_differentiable_backward(const at::Tensor & grad_w, const at::Tensor & saved_v, const at::Tensor & saved_g, const at::Tensor & saved_norms, int64_t dim);
21
+
22
+ } // namespace compositeimplicitautograd
23
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_norm_interface_backward_cpu_dispatch.h ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
3
+
4
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
5
+
6
+ // The only #includes we need are for custom classes that have defaults in the C++ API
7
+ #include <c10/core/MemoryFormat.h>
8
+ #include <c10/core/Scalar.h>
9
+ #include <ATen/core/Reduction.h>
10
+
11
+ // Forward declarations of any types needed in the operator signatures.
12
+ // We can't directly include these classes because it will cause circular include dependencies.
13
+ // This file is included by TensorBody.h, which defines the Tensor class.
14
+ #include <ATen/core/ATen_fwd.h>
15
+
16
+ namespace at {
17
+
18
+ namespace cpu {
19
+
20
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor> _weight_norm_interface_backward(const at::Tensor & grad_w, const at::Tensor & saved_v, const at::Tensor & saved_g, const at::Tensor & saved_norms, int64_t dim);
21
+
22
+ } // namespace cpu
23
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/_weight_norm_interface_backward_native.h ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from NativeFunction.h
4
+
5
+ #include <c10/core/Scalar.h>
6
+ #include <c10/core/Storage.h>
7
+ #include <c10/core/TensorOptions.h>
8
+ #include <c10/util/Deprecated.h>
9
+ #include <optional>
10
+ #include <c10/core/QScheme.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <tuple>
14
+ #include <vector>
15
+
16
+
17
+ namespace at {
18
+ namespace native {
19
+ TORCH_API ::std::tuple<at::Tensor &,at::Tensor &> _weight_norm_interface_backward_out(const at::Tensor & grad_w, const at::Tensor & saved_v, const at::Tensor & saved_g, const at::Tensor & saved_norms, int64_t dim, at::Tensor & out0, at::Tensor & out1);
20
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor> weight_norm_backward_cpu(const at::Tensor & grad_w, const at::Tensor & saved_v, const at::Tensor & saved_g, const at::Tensor & saved_norms, int64_t dim);
21
+ TORCH_API ::std::tuple<at::Tensor,at::Tensor> weight_norm_backward_cuda(const at::Tensor & grad_w, const at::Tensor & saved_v, const at::Tensor & saved_g, const at::Tensor & saved_norms, int64_t dim);
22
+ } // namespace native
23
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/absolute_compositeimplicitautograd_dispatch.h ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
3
+
4
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
5
+
6
+ // The only #includes we need are for custom classes that have defaults in the C++ API
7
+ #include <c10/core/MemoryFormat.h>
8
+ #include <c10/core/Scalar.h>
9
+ #include <ATen/core/Reduction.h>
10
+
11
+ // Forward declarations of any types needed in the operator signatures.
12
+ // We can't directly include these classes because it will cause circular include dependencies.
13
+ // This file is included by TensorBody.h, which defines the Tensor class.
14
+ #include <ATen/core/ATen_fwd.h>
15
+
16
+ namespace at {
17
+
18
+ namespace compositeimplicitautograd {
19
+
20
+ TORCH_API at::Tensor absolute(const at::Tensor & self);
21
+ TORCH_API at::Tensor & absolute_out(at::Tensor & out, const at::Tensor & self);
22
+ TORCH_API at::Tensor & absolute_outf(const at::Tensor & self, at::Tensor & out);
23
+ TORCH_API at::Tensor & absolute_(at::Tensor & self);
24
+
25
+ } // namespace compositeimplicitautograd
26
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/alias.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Function.h
4
+
5
+ #include <ATen/Context.h>
6
+ #include <ATen/DeviceGuard.h>
7
+ #include <ATen/TensorUtils.h>
8
+ #include <ATen/TracerMode.h>
9
+ #include <ATen/core/Generator.h>
10
+ #include <ATen/core/Reduction.h>
11
+ #include <ATen/core/Tensor.h>
12
+ #include <c10/core/Scalar.h>
13
+ #include <c10/core/Storage.h>
14
+ #include <c10/core/TensorOptions.h>
15
+ #include <c10/util/Deprecated.h>
16
+ #include <optional>
17
+
18
+
19
+
20
+ #include <ATen/ops/alias_ops.h>
21
+
22
+ namespace at {
23
+
24
+
25
+ // aten::alias(Tensor(a) self) -> Tensor(a)
26
+ inline at::Tensor alias(const at::Tensor & self) {
27
+ return at::_ops::alias::call(self);
28
+ }
29
+
30
+ }
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/amax_cuda_dispatch.h ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
3
+
4
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
5
+
6
+ // The only #includes we need are for custom classes that have defaults in the C++ API
7
+ #include <c10/core/MemoryFormat.h>
8
+ #include <c10/core/Scalar.h>
9
+ #include <ATen/core/Reduction.h>
10
+
11
+ // Forward declarations of any types needed in the operator signatures.
12
+ // We can't directly include these classes because it will cause circular include dependencies.
13
+ // This file is included by TensorBody.h, which defines the Tensor class.
14
+ #include <ATen/core/ATen_fwd.h>
15
+
16
+ namespace at {
17
+
18
+ namespace cuda {
19
+
20
+ TORCH_API at::Tensor amax(const at::Tensor & self, at::IntArrayRef dim={}, bool keepdim=false);
21
+ TORCH_API at::Tensor & amax_out(at::Tensor & out, const at::Tensor & self, at::IntArrayRef dim={}, bool keepdim=false);
22
+ TORCH_API at::Tensor & amax_outf(const at::Tensor & self, at::IntArrayRef dim, bool keepdim, at::Tensor & out);
23
+
24
+ } // namespace cuda
25
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/atleast_1d.h ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Function.h
4
+
5
+ #include <ATen/Context.h>
6
+ #include <ATen/DeviceGuard.h>
7
+ #include <ATen/TensorUtils.h>
8
+ #include <ATen/TracerMode.h>
9
+ #include <ATen/core/Generator.h>
10
+ #include <ATen/core/Reduction.h>
11
+ #include <ATen/core/Tensor.h>
12
+ #include <c10/core/Scalar.h>
13
+ #include <c10/core/Storage.h>
14
+ #include <c10/core/TensorOptions.h>
15
+ #include <c10/util/Deprecated.h>
16
+ #include <optional>
17
+
18
+
19
+
20
+ #include <ATen/ops/atleast_1d_ops.h>
21
+
22
+ namespace at {
23
+
24
+
25
+ // aten::atleast_1d(Tensor self) -> Tensor
26
+ inline at::Tensor atleast_1d(const at::Tensor & self) {
27
+ return at::_ops::atleast_1d::call(self);
28
+ }
29
+
30
+ // aten::atleast_1d.Sequence(Tensor[] tensors) -> Tensor[]
31
+ inline ::std::vector<at::Tensor> atleast_1d(at::TensorList tensors) {
32
+ return at::_ops::atleast_1d_Sequence::call(tensors);
33
+ }
34
+
35
+ }
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/chalf_native.h ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from NativeFunction.h
4
+
5
+ #include <c10/core/Scalar.h>
6
+ #include <c10/core/Storage.h>
7
+ #include <c10/core/TensorOptions.h>
8
+ #include <c10/util/Deprecated.h>
9
+ #include <optional>
10
+ #include <c10/core/QScheme.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <tuple>
14
+ #include <vector>
15
+
16
+
17
+ namespace at {
18
+ namespace native {
19
+ TORCH_API at::Tensor chalf(const at::Tensor & self, ::std::optional<at::MemoryFormat> memory_format=::std::nullopt);
20
+ } // namespace native
21
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/column_stack_compositeimplicitautograd_dispatch.h ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
3
+
4
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
5
+
6
+ // The only #includes we need are for custom classes that have defaults in the C++ API
7
+ #include <c10/core/MemoryFormat.h>
8
+ #include <c10/core/Scalar.h>
9
+ #include <ATen/core/Reduction.h>
10
+
11
+ // Forward declarations of any types needed in the operator signatures.
12
+ // We can't directly include these classes because it will cause circular include dependencies.
13
+ // This file is included by TensorBody.h, which defines the Tensor class.
14
+ #include <ATen/core/ATen_fwd.h>
15
+
16
+ namespace at {
17
+
18
+ namespace compositeimplicitautograd {
19
+
20
+ TORCH_API at::Tensor column_stack(at::TensorList tensors);
21
+ TORCH_API at::Tensor & column_stack_out(at::Tensor & out, at::TensorList tensors);
22
+ TORCH_API at::Tensor & column_stack_outf(at::TensorList tensors, at::Tensor & out);
23
+
24
+ } // namespace compositeimplicitautograd
25
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/conv2d.h ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Function.h
4
+
5
+ #include <ATen/Context.h>
6
+ #include <ATen/DeviceGuard.h>
7
+ #include <ATen/TensorUtils.h>
8
+ #include <ATen/TracerMode.h>
9
+ #include <ATen/core/Generator.h>
10
+ #include <ATen/core/Reduction.h>
11
+ #include <ATen/core/Tensor.h>
12
+ #include <c10/core/Scalar.h>
13
+ #include <c10/core/Storage.h>
14
+ #include <c10/core/TensorOptions.h>
15
+ #include <c10/util/Deprecated.h>
16
+ #include <optional>
17
+
18
+
19
+
20
+ #include <ATen/ops/conv2d_ops.h>
21
+
22
+ namespace at {
23
+
24
+
25
+ // aten::conv2d(Tensor input, Tensor weight, Tensor? bias=None, SymInt[2] stride=1, SymInt[2] padding=0, SymInt[2] dilation=1, SymInt groups=1) -> Tensor
26
+ inline at::Tensor conv2d(const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & bias={}, at::IntArrayRef stride=1, at::IntArrayRef padding=0, at::IntArrayRef dilation=1, int64_t groups=1) {
27
+ return at::_ops::conv2d::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(dilation), groups);
28
+ }
29
+ namespace symint {
30
+ template <typename T, typename = std::enable_if_t<std::is_same<T, int64_t>::value>>
31
+ at::Tensor conv2d(const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & bias={}, at::IntArrayRef stride=1, at::IntArrayRef padding=0, at::IntArrayRef dilation=1, int64_t groups=1) {
32
+ return at::_ops::conv2d::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), c10::fromIntArrayRefSlow(padding), c10::fromIntArrayRefSlow(dilation), groups);
33
+ }
34
+ }
35
+
36
+ // aten::conv2d(Tensor input, Tensor weight, Tensor? bias=None, SymInt[2] stride=1, SymInt[2] padding=0, SymInt[2] dilation=1, SymInt groups=1) -> Tensor
37
+ inline at::Tensor conv2d_symint(const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & bias={}, c10::SymIntArrayRef stride=c10::SymInt(1), c10::SymIntArrayRef padding=c10::SymInt(0), c10::SymIntArrayRef dilation=c10::SymInt(1), c10::SymInt groups=1) {
38
+ return at::_ops::conv2d::call(input, weight, bias, stride, padding, dilation, groups);
39
+ }
40
+ namespace symint {
41
+ template <typename T, typename = std::enable_if_t<std::is_same<T, c10::SymInt>::value>>
42
+ at::Tensor conv2d(const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & bias={}, c10::SymIntArrayRef stride=c10::SymInt(1), c10::SymIntArrayRef padding=c10::SymInt(0), c10::SymIntArrayRef dilation=c10::SymInt(1), c10::SymInt groups=1) {
43
+ return at::_ops::conv2d::call(input, weight, bias, stride, padding, dilation, groups);
44
+ }
45
+ }
46
+
47
+ // aten::conv2d.padding(Tensor input, Tensor weight, Tensor? bias=None, SymInt[2] stride=1, str padding="valid", SymInt[2] dilation=1, SymInt groups=1) -> Tensor
48
+ inline at::Tensor conv2d(const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & bias, at::IntArrayRef stride, c10::string_view padding, at::IntArrayRef dilation=1, int64_t groups=1) {
49
+ return at::_ops::conv2d_padding::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), padding, c10::fromIntArrayRefSlow(dilation), groups);
50
+ }
51
+ namespace symint {
52
+ template <typename T, typename = std::enable_if_t<std::is_same<T, int64_t>::value>>
53
+ at::Tensor conv2d(const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & bias, at::IntArrayRef stride, c10::string_view padding, at::IntArrayRef dilation=1, int64_t groups=1) {
54
+ return at::_ops::conv2d_padding::call(input, weight, bias, c10::fromIntArrayRefSlow(stride), padding, c10::fromIntArrayRefSlow(dilation), groups);
55
+ }
56
+ }
57
+
58
+ // aten::conv2d.padding(Tensor input, Tensor weight, Tensor? bias=None, SymInt[2] stride=1, str padding="valid", SymInt[2] dilation=1, SymInt groups=1) -> Tensor
59
+ inline at::Tensor conv2d_symint(const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::string_view padding, c10::SymIntArrayRef dilation=c10::SymInt(1), c10::SymInt groups=1) {
60
+ return at::_ops::conv2d_padding::call(input, weight, bias, stride, padding, dilation, groups);
61
+ }
62
+ namespace symint {
63
+ template <typename T, typename = std::enable_if_t<std::is_same<T, c10::SymInt>::value>>
64
+ at::Tensor conv2d(const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & bias, c10::SymIntArrayRef stride, c10::string_view padding, c10::SymIntArrayRef dilation=c10::SymInt(1), c10::SymInt groups=1) {
65
+ return at::_ops::conv2d_padding::call(input, weight, bias, stride, padding, dilation, groups);
66
+ }
67
+ }
68
+
69
+ }
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/cumsum_meta.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from NativeMetaFunction.h
4
+
5
+ #include <c10/core/Scalar.h>
6
+ #include <c10/core/Storage.h>
7
+ #include <c10/core/TensorOptions.h>
8
+ #include <c10/util/Deprecated.h>
9
+ #include <optional>
10
+ #include <c10/core/QScheme.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/TensorIterator.h>
13
+ #include <ATen/TensorMeta.h>
14
+ #include <tuple>
15
+ #include <vector>
16
+
17
+ namespace at {
18
+ namespace meta {
19
+
20
+ struct TORCH_API structured_cumsum : public at::impl::MetaBase {
21
+
22
+
23
+ void meta(const at::Tensor & self, int64_t dim, ::std::optional<at::ScalarType> dtype);
24
+ };
25
+
26
+ } // namespace native
27
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/diag_embed_ops.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Operator.h
4
+
5
+ #include <tuple>
6
+ #include <vector>
7
+
8
+ // Forward declarations of any types needed in the operator signatures.
9
+ // We can't directly include these classes because it will cause circular include dependencies.
10
+ // This file is included by TensorBody.h, which defines the Tensor class.
11
+ #include <ATen/core/ATen_fwd.h>
12
+
13
+ namespace at {
14
+ namespace _ops {
15
+
16
+
17
+ struct TORCH_API diag_embed {
18
+ using schema = at::Tensor (const at::Tensor &, int64_t, int64_t, int64_t);
19
+ using ptr_schema = schema*;
20
+ // See Note [static constexpr char* members for windows NVCC]
21
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::diag_embed")
22
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
23
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "diag_embed(Tensor self, int offset=0, int dim1=-2, int dim2=-1) -> Tensor")
24
+ static at::Tensor call(const at::Tensor & self, int64_t offset, int64_t dim1, int64_t dim2);
25
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, int64_t offset, int64_t dim1, int64_t dim2);
26
+ };
27
+
28
+ struct TORCH_API diag_embed_out {
29
+ using schema = at::Tensor & (const at::Tensor &, int64_t, int64_t, int64_t, at::Tensor &);
30
+ using ptr_schema = schema*;
31
+ // See Note [static constexpr char* members for windows NVCC]
32
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::diag_embed")
33
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
34
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "diag_embed.out(Tensor self, int offset=0, int dim1=-2, int dim2=-1, *, Tensor(a!) out) -> Tensor(a!)")
35
+ static at::Tensor & call(const at::Tensor & self, int64_t offset, int64_t dim1, int64_t dim2, at::Tensor & out);
36
+ static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, int64_t offset, int64_t dim1, int64_t dim2, at::Tensor & out);
37
+ };
38
+
39
+ }} // namespace at::_ops
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/embedding_ops.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Operator.h
4
+
5
+ #include <tuple>
6
+ #include <vector>
7
+
8
+ // Forward declarations of any types needed in the operator signatures.
9
+ // We can't directly include these classes because it will cause circular include dependencies.
10
+ // This file is included by TensorBody.h, which defines the Tensor class.
11
+ #include <ATen/core/ATen_fwd.h>
12
+
13
+ namespace at {
14
+ namespace _ops {
15
+
16
+
17
+ struct TORCH_API embedding {
18
+ using schema = at::Tensor (const at::Tensor &, const at::Tensor &, c10::SymInt, bool, bool);
19
+ using ptr_schema = schema*;
20
+ // See Note [static constexpr char* members for windows NVCC]
21
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::embedding")
22
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
23
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "embedding(Tensor weight, Tensor indices, SymInt padding_idx=-1, bool scale_grad_by_freq=False, bool sparse=False) -> Tensor")
24
+ static at::Tensor call(const at::Tensor & weight, const at::Tensor & indices, c10::SymInt padding_idx, bool scale_grad_by_freq, bool sparse);
25
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & weight, const at::Tensor & indices, c10::SymInt padding_idx, bool scale_grad_by_freq, bool sparse);
26
+ };
27
+
28
+ struct TORCH_API embedding_out {
29
+ using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, c10::SymInt, bool, bool, at::Tensor &);
30
+ using ptr_schema = schema*;
31
+ // See Note [static constexpr char* members for windows NVCC]
32
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::embedding")
33
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
34
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "embedding.out(Tensor weight, Tensor indices, SymInt padding_idx=-1, bool scale_grad_by_freq=False, bool sparse=False, *, Tensor(a!) out) -> Tensor(a!)")
35
+ static at::Tensor & call(const at::Tensor & weight, const at::Tensor & indices, c10::SymInt padding_idx, bool scale_grad_by_freq, bool sparse, at::Tensor & out);
36
+ static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & weight, const at::Tensor & indices, c10::SymInt padding_idx, bool scale_grad_by_freq, bool sparse, at::Tensor & out);
37
+ };
38
+
39
+ }} // namespace at::_ops
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/gcd_meta.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from NativeMetaFunction.h
4
+
5
+ #include <c10/core/Scalar.h>
6
+ #include <c10/core/Storage.h>
7
+ #include <c10/core/TensorOptions.h>
8
+ #include <c10/util/Deprecated.h>
9
+ #include <optional>
10
+ #include <c10/core/QScheme.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/TensorIterator.h>
13
+ #include <ATen/TensorMeta.h>
14
+ #include <tuple>
15
+ #include <vector>
16
+
17
+ namespace at {
18
+ namespace meta {
19
+
20
+ struct TORCH_API structured_gcd : public TensorIteratorBase {
21
+
22
+
23
+ void meta(const at::Tensor & self, const at::Tensor & other);
24
+ };
25
+
26
+ } // namespace native
27
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/hardsigmoid_backward_ops.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Operator.h
4
+
5
+ #include <tuple>
6
+ #include <vector>
7
+
8
+ // Forward declarations of any types needed in the operator signatures.
9
+ // We can't directly include these classes because it will cause circular include dependencies.
10
+ // This file is included by TensorBody.h, which defines the Tensor class.
11
+ #include <ATen/core/ATen_fwd.h>
12
+
13
+ namespace at {
14
+ namespace _ops {
15
+
16
+
17
+ struct TORCH_API hardsigmoid_backward_grad_input {
18
+ using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, at::Tensor &);
19
+ using ptr_schema = schema*;
20
+ // See Note [static constexpr char* members for windows NVCC]
21
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::hardsigmoid_backward")
22
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "grad_input")
23
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "hardsigmoid_backward.grad_input(Tensor grad_output, Tensor self, *, Tensor(a!) grad_input) -> Tensor(a!)")
24
+ static at::Tensor & call(const at::Tensor & grad_output, const at::Tensor & self, at::Tensor & grad_input);
25
+ static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad_output, const at::Tensor & self, at::Tensor & grad_input);
26
+ };
27
+
28
+ struct TORCH_API hardsigmoid_backward {
29
+ using schema = at::Tensor (const at::Tensor &, const at::Tensor &);
30
+ using ptr_schema = schema*;
31
+ // See Note [static constexpr char* members for windows NVCC]
32
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::hardsigmoid_backward")
33
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
34
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "hardsigmoid_backward(Tensor grad_output, Tensor self) -> Tensor")
35
+ static at::Tensor call(const at::Tensor & grad_output, const at::Tensor & self);
36
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad_output, const at::Tensor & self);
37
+ };
38
+
39
+ }} // namespace at::_ops
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/hinge_embedding_loss.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Function.h
4
+
5
+ #include <ATen/Context.h>
6
+ #include <ATen/DeviceGuard.h>
7
+ #include <ATen/TensorUtils.h>
8
+ #include <ATen/TracerMode.h>
9
+ #include <ATen/core/Generator.h>
10
+ #include <ATen/core/Reduction.h>
11
+ #include <ATen/core/Tensor.h>
12
+ #include <c10/core/Scalar.h>
13
+ #include <c10/core/Storage.h>
14
+ #include <c10/core/TensorOptions.h>
15
+ #include <c10/util/Deprecated.h>
16
+ #include <optional>
17
+
18
+
19
+
20
+ #include <ATen/ops/hinge_embedding_loss_ops.h>
21
+
22
+ namespace at {
23
+
24
+
25
+ // aten::hinge_embedding_loss(Tensor self, Tensor target, float margin=1.0, int reduction=Mean) -> Tensor
26
+ inline at::Tensor hinge_embedding_loss(const at::Tensor & self, const at::Tensor & target, double margin=1.0, int64_t reduction=at::Reduction::Mean) {
27
+ return at::_ops::hinge_embedding_loss::call(self, target, margin, reduction);
28
+ }
29
+
30
+ }
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/isreal_ops.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Operator.h
4
+
5
+ #include <tuple>
6
+ #include <vector>
7
+
8
+ // Forward declarations of any types needed in the operator signatures.
9
+ // We can't directly include these classes because it will cause circular include dependencies.
10
+ // This file is included by TensorBody.h, which defines the Tensor class.
11
+ #include <ATen/core/ATen_fwd.h>
12
+
13
+ namespace at {
14
+ namespace _ops {
15
+
16
+
17
+ struct TORCH_API isreal {
18
+ using schema = at::Tensor (const at::Tensor &);
19
+ using ptr_schema = schema*;
20
+ // See Note [static constexpr char* members for windows NVCC]
21
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::isreal")
22
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
23
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "isreal(Tensor self) -> Tensor")
24
+ static at::Tensor call(const at::Tensor & self);
25
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self);
26
+ };
27
+
28
+ }} // namespace at::_ops
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/kron_native.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from NativeFunction.h
4
+
5
+ #include <c10/core/Scalar.h>
6
+ #include <c10/core/Storage.h>
7
+ #include <c10/core/TensorOptions.h>
8
+ #include <c10/util/Deprecated.h>
9
+ #include <optional>
10
+ #include <c10/core/QScheme.h>
11
+ #include <ATen/core/Reduction.h>
12
+ #include <ATen/core/Tensor.h>
13
+ #include <tuple>
14
+ #include <vector>
15
+
16
+
17
+ namespace at {
18
+ namespace native {
19
+ TORCH_API at::Tensor kron(const at::Tensor & self, const at::Tensor & other);
20
+ TORCH_API at::Tensor & kron_out(const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
21
+ } // namespace native
22
+ } // namespace at
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/le_ops.h ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Operator.h
4
+
5
+ #include <tuple>
6
+ #include <vector>
7
+
8
+ // Forward declarations of any types needed in the operator signatures.
9
+ // We can't directly include these classes because it will cause circular include dependencies.
10
+ // This file is included by TensorBody.h, which defines the Tensor class.
11
+ #include <ATen/core/ATen_fwd.h>
12
+
13
+ namespace at {
14
+ namespace _ops {
15
+
16
+
17
+ struct TORCH_API le_Scalar_out {
18
+ using schema = at::Tensor & (const at::Tensor &, const at::Scalar &, at::Tensor &);
19
+ using ptr_schema = schema*;
20
+ // See Note [static constexpr char* members for windows NVCC]
21
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::le")
22
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Scalar_out")
23
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "le.Scalar_out(Tensor self, Scalar other, *, Tensor(a!) out) -> Tensor(a!)")
24
+ static at::Tensor & call(const at::Tensor & self, const at::Scalar & other, at::Tensor & out);
25
+ static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Scalar & other, at::Tensor & out);
26
+ };
27
+
28
+ struct TORCH_API le_Scalar {
29
+ using schema = at::Tensor (const at::Tensor &, const at::Scalar &);
30
+ using ptr_schema = schema*;
31
+ // See Note [static constexpr char* members for windows NVCC]
32
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::le")
33
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Scalar")
34
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "le.Scalar(Tensor self, Scalar other) -> Tensor")
35
+ static at::Tensor call(const at::Tensor & self, const at::Scalar & other);
36
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Scalar & other);
37
+ };
38
+
39
+ struct TORCH_API le_Tensor_out {
40
+ using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, at::Tensor &);
41
+ using ptr_schema = schema*;
42
+ // See Note [static constexpr char* members for windows NVCC]
43
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::le")
44
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Tensor_out")
45
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "le.Tensor_out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)")
46
+ static at::Tensor & call(const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
47
+ static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
48
+ };
49
+
50
+ struct TORCH_API le_Tensor {
51
+ using schema = at::Tensor (const at::Tensor &, const at::Tensor &);
52
+ using ptr_schema = schema*;
53
+ // See Note [static constexpr char* members for windows NVCC]
54
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::le")
55
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Tensor")
56
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "le.Tensor(Tensor self, Tensor other) -> Tensor")
57
+ static at::Tensor call(const at::Tensor & self, const at::Tensor & other);
58
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Tensor & other);
59
+ };
60
+
61
+ struct TORCH_API le__Scalar {
62
+ using schema = at::Tensor & (at::Tensor &, const at::Scalar &);
63
+ using ptr_schema = schema*;
64
+ // See Note [static constexpr char* members for windows NVCC]
65
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::le_")
66
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Scalar")
67
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "le_.Scalar(Tensor(a!) self, Scalar other) -> Tensor(a!)")
68
+ static at::Tensor & call(at::Tensor & self, const at::Scalar & other);
69
+ static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, at::Tensor & self, const at::Scalar & other);
70
+ };
71
+
72
+ struct TORCH_API le__Tensor {
73
+ using schema = at::Tensor & (at::Tensor &, const at::Tensor &);
74
+ using ptr_schema = schema*;
75
+ // See Note [static constexpr char* members for windows NVCC]
76
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::le_")
77
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Tensor")
78
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "le_.Tensor(Tensor(a!) self, Tensor other) -> Tensor(a!)")
79
+ static at::Tensor & call(at::Tensor & self, const at::Tensor & other);
80
+ static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, at::Tensor & self, const at::Tensor & other);
81
+ };
82
+
83
+ }} // namespace at::_ops
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/linalg_diagonal_ops.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated by torchgen/gen.py from Operator.h
4
+
5
+ #include <tuple>
6
+ #include <vector>
7
+
8
+ // Forward declarations of any types needed in the operator signatures.
9
+ // We can't directly include these classes because it will cause circular include dependencies.
10
+ // This file is included by TensorBody.h, which defines the Tensor class.
11
+ #include <ATen/core/ATen_fwd.h>
12
+
13
+ namespace at {
14
+ namespace _ops {
15
+
16
+
17
+ struct TORCH_API linalg_diagonal {
18
+ using schema = at::Tensor (const at::Tensor &, int64_t, int64_t, int64_t);
19
+ using ptr_schema = schema*;
20
+ // See Note [static constexpr char* members for windows NVCC]
21
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::linalg_diagonal")
22
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
23
+ STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "linalg_diagonal(Tensor(a) A, *, int offset=0, int dim1=-2, int dim2=-1) -> Tensor(a)")
24
+ static at::Tensor call(const at::Tensor & A, int64_t offset, int64_t dim1, int64_t dim2);
25
+ static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & A, int64_t offset, int64_t dim1, int64_t dim2);
26
+ };
27
+
28
+ }} // namespace at::_ops
vllm/lib/python3.10/site-packages/torch/include/ATen/ops/logical_or_cuda_dispatch.h ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ // @generated by torchgen/gen.py from DispatchKeyFunction.h
3
+
4
+ // NB: The implementing C++ file is RegisterDispatchKey.cpp
5
+
6
+ // The only #includes we need are for custom classes that have defaults in the C++ API
7
+ #include <c10/core/MemoryFormat.h>
8
+ #include <c10/core/Scalar.h>
9
+ #include <ATen/core/Reduction.h>
10
+
11
+ // Forward declarations of any types needed in the operator signatures.
12
+ // We can't directly include these classes because it will cause circular include dependencies.
13
+ // This file is included by TensorBody.h, which defines the Tensor class.
14
+ #include <ATen/core/ATen_fwd.h>
15
+
16
+ namespace at {
17
+
18
+ namespace cuda {
19
+
20
+ TORCH_API at::Tensor & logical_or_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & other);
21
+ TORCH_API at::Tensor & logical_or_outf(const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
22
+
23
+ } // namespace cuda
24
+ } // namespace at