Instructions to use Zipeng365/WISP with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Zipeng365/WISP with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Zipeng365/WISP", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Download tests/test_conv_kernels.py from Zipeng365/WISP: direct link, hf CLI and curl.
- Browser
- Download file 2.95 kB
-
https://huggingface.co/Zipeng365/WISP/resolve/main/tests/test_conv_kernels.py
- Command line
-
hf download hf://Zipeng365/WISP/tests/test_conv_kernels.py
-
curl -L -o test_conv_kernels.py https://huggingface.co/Zipeng365/WISP/resolve/main/tests/test_conv_kernels.py
2.95 kB
| """Packed random-convolution parity with the previous release backend.""" | |
| from unittest import TestCase, skipIf | |
| from unittest.mock import patch | |
| import pickle | |
| import warnings | |
| import numpy as np | |
| from wisp_fast import features as fx | |
| class TestPackedConvolution(TestCase): | |
| def test_exact_tails_and_pairwise_reductions(self): | |
| rng = np.random.default_rng(707) | |
| cases = [15, 16, 17, 18, 19, 23, 32, 35, 37, 63, 96, | |
| 126, 127, 128, 129, 130, 131, 159, 160, 161, 259, 2049] | |
| for index, length in enumerate(cases): | |
| for c in [1, 2, 3, 5]: | |
| with self.subTest(length=length, channels=c): | |
| x = rng.normal(size=(3, length, c)) | |
| if index % 4 == 0: | |
| x = np.rint(x) | |
| if index % 3 == 0: | |
| x[0, 3, 0] = np.nan | |
| x[2, :, -1] = 0. | |
| for turbo in [False, True]: | |
| model = fx.RandomConvSketch(n_kernels=16, kernel_lengths=(1, 5, 7, 9, 15), | |
| fast_profile=turbo, random_state=312) | |
| model.fit(x) | |
| with patch.object(fx, '_cis_conv', None): | |
| old = model.transform(x) | |
| with warnings.catch_warnings(): | |
| warnings.simplefilter('ignore', RuntimeWarning) | |
| out = model.transform(x) | |
| np.testing.assert_array_equal(out, old) | |
| def test_validation_and_fallback(self): | |
| x = np.random.default_rng(874).normal(size=(3, 32, 3)) | |
| m = fx.RandomConvSketch(n_kernels=8).fit(x) | |
| expected = m.transform(x) | |
| with patch.object(fx, '_verified_conv_blas', return_value=False): | |
| np.testing.assert_array_equal(m.transform(x), expected) | |
| kernel = m.kernels_[0] | |
| kernel['weights'] *= 0. | |
| kernel['bias'] = 0. | |
| m.invalidate_plan() | |
| np.testing.assert_array_equal(m.transform(x)[:, :4], np.zeros((3,4))) | |
| p = pickle.loads(pickle.dumps(m)) | |
| self.assertNotIn('_conv_plan', vars(p)) | |
| np.testing.assert_array_equal(m.transform(x), p.transform(x)) | |
| layout, weights, bias, _, _ = m._conv_plan[1] | |
| for wrong in ('channel', 'length', 'stride', 'output', 'dtype'): | |
| l = layout.copy() | |
| if wrong == 'channel': l[0,3] = 4 | |
| if wrong == 'length': l[1,0] = 0 | |
| out = np.empty((3,8,5 if wrong == 'output' else 4)) | |
| with self.assertRaises((ValueError, BufferError)): | |
| fx._cis_conv.transform(np.ascontiguousarray(x.transpose(0,2,1)),l, | |
| weights.astype('f4') if wrong=='dtype' else weights, | |
| bias,40 if wrong=='stride' else 1,False,False,out) | |