waterfall 0.2.3__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {waterfall-0.2.3 → waterfall-0.2.5}/.gitignore +1 -2
  2. {waterfall-0.2.3 → waterfall-0.2.5}/PKG-INFO +2 -2
  3. waterfall-0.2.5/pypi.txt +2 -0
  4. {waterfall-0.2.3 → waterfall-0.2.5}/pyproject.toml +2 -2
  5. {waterfall-0.2.3 → waterfall-0.2.5}/requirements.txt +1 -1
  6. waterfall-0.2.5/test.ipynb +129 -0
  7. waterfall-0.2.5/test_.ipynb +118 -0
  8. {waterfall-0.2.3 → waterfall-0.2.5}/waterfall/WatermarkerBase.py +1 -1
  9. waterfall-0.2.3/decode.gif +0 -0
  10. waterfall-0.2.3/demo.ipynb +0 -1346
  11. waterfall-0.2.3/test_animation.py +0 -60
  12. waterfall-0.2.3/test_vllm.ipynb +0 -697
  13. waterfall-0.2.3/token_tree_generator.py +0 -221
  14. {waterfall-0.2.3 → waterfall-0.2.5}/.vscode/settings.json +0 -0
  15. {waterfall-0.2.3 → waterfall-0.2.5}/Images/Illustration.gif +0 -0
  16. {waterfall-0.2.3 → waterfall-0.2.5}/Images/Problem_formulation.jpg +0 -0
  17. {waterfall-0.2.3 → waterfall-0.2.5}/Images/Watermarking_process.png +0 -0
  18. {waterfall-0.2.3 → waterfall-0.2.5}/LICENSE +0 -0
  19. {waterfall-0.2.3 → waterfall-0.2.5}/README.md +0 -0
  20. {waterfall-0.2.3 → waterfall-0.2.5}/__init__.py +0 -0
  21. {waterfall-0.2.3 → waterfall-0.2.5}/waterfall/WatermarkingFn.py +0 -0
  22. {waterfall-0.2.3 → waterfall-0.2.5}/waterfall/WatermarkingFnFourier.py +0 -0
  23. {waterfall-0.2.3 → waterfall-0.2.5}/waterfall/WatermarkingFnSquare.py +0 -0
  24. {waterfall-0.2.3 → waterfall-0.2.5}/waterfall/__init__.py +0 -0
  25. {waterfall-0.2.3 → waterfall-0.2.5}/waterfall/permute.py +0 -0
  26. {waterfall-0.2.3 → waterfall-0.2.5}/waterfall/watermark.py +0 -0
@@ -3,5 +3,4 @@
3
3
  *.egg-info
4
4
  /.python-version
5
5
  /.idea
6
- dist
7
- media
6
+ dist
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: waterfall
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Scalable Framework for Robust Text Watermarking and Provenance for LLMs
5
5
  Project-URL: Homepage, https://github.com/aoi3142/Waterfall
6
6
  Project-URL: Issues, https://github.com/aoi3142/Waterfall/issues
@@ -11,7 +11,7 @@ Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Requires-Python: >=3.10
13
13
  Requires-Dist: accelerate>=0.29.0
14
- Requires-Dist: numpy>=2.0.0
14
+ Requires-Dist: numpy>=1.25.0
15
15
  Requires-Dist: scipy>=1.13.0
16
16
  Requires-Dist: sentence-transformers>=3.0.0
17
17
  Requires-Dist: torch>=2.3.0
@@ -0,0 +1,2 @@
1
+ python3 -m build
2
+ python3 -m twine upload dist/*
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "waterfall"
7
- version = "0.2.3"
7
+ version = "0.2.5"
8
8
  authors = [
9
9
  { name = "Xinyuan Niu", email="aperture@outlook.sg" }
10
10
  ]
@@ -20,7 +20,7 @@ license-files = ["LICEN[CS]E*"]
20
20
 
21
21
  dependencies = [
22
22
  "accelerate>=0.29.0",
23
- "numpy>=2.0.0",
23
+ "numpy>=1.25.0",
24
24
  "scipy>=1.13.0",
25
25
  "sentence-transformers>=3.0.0",
26
26
  "torch>=2.3.0",
@@ -1,5 +1,5 @@
1
1
  accelerate>=0.29.0
2
- numpy>=2.0.0
2
+ numpy>=1.25.0
3
3
  scipy>=1.13.0
4
4
  sentence-transformers>=3.0.0
5
5
  torch>=2.3.0
@@ -0,0 +1,129 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "ddca610d",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from waterfall.watermark import *\n",
11
+ "import torch"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 2,
17
+ "id": "f0b0a02a",
18
+ "metadata": {},
19
+ "outputs": [],
20
+ "source": [
21
+ "model_name_or_path = 'meta-llama/Llama-3.1-8B-Instruct'"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 3,
27
+ "id": "ca5f7d55",
28
+ "metadata": {},
29
+ "outputs": [
30
+ {
31
+ "data": {
32
+ "application/vnd.jupyter.widget-view+json": {
33
+ "model_id": "2ef1e58174204e879a462a2a829d74fa",
34
+ "version_major": 2,
35
+ "version_minor": 0
36
+ },
37
+ "text/plain": [
38
+ "Loading checkpoint shards: 0%| | 0/4 [00:00<?, ?it/s]"
39
+ ]
40
+ },
41
+ "metadata": {},
42
+ "output_type": "display_data"
43
+ }
44
+ ],
45
+ "source": [
46
+ "\n",
47
+ "tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)\n",
48
+ "model = AutoModelForCausalLM.from_pretrained(\n",
49
+ " model_name_or_path,\n",
50
+ " torch_dtype=torch.bfloat16,\n",
51
+ " device_map=\"cuda:5\",\n",
52
+ " )"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": 4,
58
+ "id": "2c475de5",
59
+ "metadata": {},
60
+ "outputs": [],
61
+ "source": [
62
+ "watermarker = Watermarker(tokenizer=tokenizer, model=model, id=1)"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": 5,
68
+ "id": "e74a58b5",
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "texts = [\"James is a scary man who loves to scare children\", \"There were 3 birds that ate the whole bowl\"]"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": 8,
78
+ "id": "fd0af01e",
79
+ "metadata": {},
80
+ "outputs": [],
81
+ "source": [
82
+ "watermarked_text = watermark_texts(texts, id, watermarker=watermarker)"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "execution_count": 10,
88
+ "id": "4d58ec82",
89
+ "metadata": {},
90
+ "outputs": [
91
+ {
92
+ "data": {
93
+ "text/plain": [
94
+ "['James is an intimidating individual known for taking great pleasure in frightening kids, and this tendency often sends them running in terror.',\n",
95
+ " \"A small flock comprised of three birds consumed the entirety of the offered bowl's contents within a single meal session.\"]"
96
+ ]
97
+ },
98
+ "execution_count": 10,
99
+ "metadata": {},
100
+ "output_type": "execute_result"
101
+ }
102
+ ],
103
+ "source": [
104
+ "watermarked_text"
105
+ ]
106
+ }
107
+ ],
108
+ "metadata": {
109
+ "kernelspec": {
110
+ "display_name": "Python 3",
111
+ "language": "python",
112
+ "name": "python3"
113
+ },
114
+ "language_info": {
115
+ "codemirror_mode": {
116
+ "name": "ipython",
117
+ "version": 3
118
+ },
119
+ "file_extension": ".py",
120
+ "mimetype": "text/x-python",
121
+ "name": "python",
122
+ "nbconvert_exporter": "python",
123
+ "pygments_lexer": "ipython3",
124
+ "version": "3.12.9"
125
+ }
126
+ },
127
+ "nbformat": 4,
128
+ "nbformat_minor": 5
129
+ }
@@ -0,0 +1,118 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 49,
6
+ "id": "116f61a2",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import numpy as np\n",
11
+ "from tqdm import tqdm\n",
12
+ "from itertools import product, combinations\n",
13
+ "from scipy.stats import binom"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 50,
19
+ "id": "53c66973",
20
+ "metadata": {},
21
+ "outputs": [
22
+ {
23
+ "data": {
24
+ "text/plain": [
25
+ "np.float64(0.38742048899999965)"
26
+ ]
27
+ },
28
+ "execution_count": 50,
29
+ "metadata": {},
30
+ "output_type": "execute_result"
31
+ }
32
+ ],
33
+ "source": [
34
+ "binom.pmf(1, 10, 0.1)"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": 56,
40
+ "metadata": {},
41
+ "outputs": [
42
+ {
43
+ "name": "stderr",
44
+ "output_type": "stream",
45
+ "text": [
46
+ "100%|██████████| 32/32 [00:00<00:00, 10845.88it/s]\n",
47
+ "100%|██████████| 32/32 [00:00<00:00, 3035.09it/s]\n",
48
+ "100%|██████████| 32/32 [00:00<00:00, 1622.42it/s]\n",
49
+ "100%|██████████| 32/32 [00:00<00:00, 2020.93it/s]\n",
50
+ "100%|██████████| 32/32 [00:00<00:00, 4749.72it/s]"
51
+ ]
52
+ },
53
+ {
54
+ "name": "stdout",
55
+ "output_type": "stream",
56
+ "text": [
57
+ "0.6582226332676197\n"
58
+ ]
59
+ },
60
+ {
61
+ "name": "stderr",
62
+ "output_type": "stream",
63
+ "text": [
64
+ "\n"
65
+ ]
66
+ }
67
+ ],
68
+ "source": [
69
+ "n = 5 # n-gram\n",
70
+ "# k = 1 # no of bits modified\n",
71
+ "l = 8 # bits of watermark\n",
72
+ "p = 0.1 # probability of modification\n",
73
+ "\n",
74
+ "result = 0\n",
75
+ "for k in range(0, n + 1):\n",
76
+ " binomial_prob = binom.pmf(k, n, p)\n",
77
+ " if k == 0:\n",
78
+ " result += binomial_prob * 1\n",
79
+ " continue\n",
80
+ " results = []\n",
81
+ "\n",
82
+ " original = np.zeros(n, dtype=bool)\n",
83
+ " for original in tqdm(product([True, False], repeat=n), total=2**n):\n",
84
+ " original = np.array(original, dtype=bool)\n",
85
+ " original_agreement = original.mean() > 0.5\n",
86
+ " for modified_indices in combinations(range(n), k):\n",
87
+ " modified = original.copy()\n",
88
+ " for i in product([True, False], repeat=k):\n",
89
+ " modified[np.array(modified_indices)] = i\n",
90
+ " modified_agreement = modified.mean() > 0.5\n",
91
+ " results.append(original_agreement == modified_agreement)\n",
92
+ " result += binomial_prob * np.mean(results) ** l\n",
93
+ "print(result)"
94
+ ]
95
+ }
96
+ ],
97
+ "metadata": {
98
+ "kernelspec": {
99
+ "display_name": "Python 3",
100
+ "language": "python",
101
+ "name": "python3"
102
+ },
103
+ "language_info": {
104
+ "codemirror_mode": {
105
+ "name": "ipython",
106
+ "version": 3
107
+ },
108
+ "file_extension": ".py",
109
+ "mimetype": "text/x-python",
110
+ "name": "python",
111
+ "nbconvert_exporter": "python",
112
+ "pygments_lexer": "ipython3",
113
+ "version": "3.12.9"
114
+ }
115
+ },
116
+ "nbformat": 4,
117
+ "nbformat_minor": 5
118
+ }
@@ -116,7 +116,7 @@ class Watermarker:
116
116
  self.N = self.tokenizer.vocab_size
117
117
 
118
118
  if isinstance(model, str):
119
- self.load_model(model, device_map=device, dtype=dtype)
119
+ self.load_model(model, device_map=device if device is not None else "auto", dtype=dtype)
120
120
  else:
121
121
  self.model = model
122
122
 
Binary file