THU-BPM / MarkLLM

MarkLLM: An Open-Source Toolkit for LLM Watermarking.(EMNLP 2024 Demo)
https://arxiv.org/pdf/2405.10051
Apache License 2.0
260 stars 23 forks source link

Unbiased Watermark #24

Open kirudang opened 6 hours ago

kirudang commented 6 hours ago

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

panly2003 commented 5 hours ago

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. 😊

kirudang commented 5 hours ago

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.

panly2003 commented 1 hour ago

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. 😊