MarkLLM icon indicating copy to clipboard operation
MarkLLM copied to clipboard

Unbiased Watermark

Open kirudang opened this issue 2 years ago • 4 comments

Hello,

Could you help me with a sample code of Invoking watermarking algorithms for Unbias Watermark? I know from the original paper that we can either choose delta-reweight or gamma-reweight, but from your code, I dont know how to apply to my use case. Thank you

kirudang avatar Oct 11 '24 02:10 kirudang

Thank you for your issue. We currently only support Gamma reweight, as delta-reweight significantly impacts text quality. We appreciate your suggestion and plan to add delta-reweight implementation in a future update. Thanks for helping us improve. 😊

panly2003 avatar Oct 11 '24 03:10 panly2003

Hello there, Thank you for your prompt return and I really appreciate your effort to make the code run.

If you are able to run the delta-reweight, may you share the file with me? Sorry If I am asking too much. I think it is okay to take a look at the watermarked output of delta-reweight as delta-rewieght is more logit-based watermark than gamma (in term of logic and intuition), I believe. Actually, I am able to run the code from the original paper (link: https://github.com/xiaoniu-578fa6bff964d005/UnbiasedWatermark ) but for some reasons, it always stops at 499th data point due to the below error:

Processing input 498 of 2000
Traceback (most recent call last):
  File "/network/rit/lab/Lai_ReSecureAI/kiel/Unbiased_WM/Gen_llama2.py", line 84, in <module>
    outputs = model.generate(
              ^^^^^^^^^^^^^^^
  File "/network/rit/lab/Lai_ReSecureAI/kiel/Unbiased_WM/unbiased_watermark/monkeypatch.py", line 20, in generate
    return original_generate(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/network/rit/lab/Lai_ReSecureAI/kiel/Unbiased_WM/unbiased_watermark/monkeypatch.py", line 20, in generate
    return original_generate(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/network/rit/lab/Lai_ReSecureAI/kiel/Unbiased_WM/unbiased_watermark/monkeypatch.py", line 20, in generate
    return original_generate(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 495 more times]
  File "/network/rit/lab/Lai_ReSecureAI/kiel/anaconda3/envs/unbias_wm/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/network/rit/lab/Lai_ReSecureAI/kiel/anaconda3/envs/unbias_wm/lib/python3.12/site-packages/transformers/generation/utils.py", line 1945, in generate
    prepared_logits_processor = self._get_logits_processor(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/network/rit/lab/Lai_ReSecureAI/kiel/Unbiased_WM/unbiased_watermark/monkeypatch.py", line 23, in _get_logits_processor
    processors = original__get_logits_processor(*args, **kargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/network/rit/lab/Lai_ReSecureAI/kiel/Unbiased_WM/unbiased_watermark/monkeypatch.py", line 23, in _get_logits_processor
    processors = original__get_logits_processor(*args, **kargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/network/rit/lab/Lai_ReSecureAI/kiel/Unbiased_WM/unbiased_watermark/monkeypatch.py", line 23, in _get_logits_processor
    processors = original__get_logits_processor(*args, **kargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 495 more times]
  File "/network/rit/lab/Lai_ReSecureAI/kiel/anaconda3/envs/unbias_wm/lib/python3.12/site-packages/transformers/generation/utils.py", line 873, in _get_logits_processor
    processors = self._merge_criteria_processor_list(processors, logits_processor)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded

Or if you can share monkeypatch.py, I would be really grateful for it. Thank you.

kirudang avatar Oct 11 '24 04:10 kirudang

Thanks for your questions. We will release the implementation of delta-reweight as soon as possible. Then you can use our code to run your experiment. 😊

panly2003 avatar Oct 11 '24 08:10 panly2003

Thank you Panly Please let me know when you've released the code by commenting here. Thank you and have a great weekend.

kirudang avatar Oct 13 '24 02:10 kirudang

We have implemented both δ-reweight and LLR score detection methods as described in the original paper. You can now select either "delta" or "gamma" reweighting by setting the appropriate type in config/Unbiased.json. Thank you for your valuable suggestion!

codelformat avatar Feb 27 '25 10:02 codelformat