THU-BPM / MarkLLM

MarkLLM: An Open-Source Toolkit for LLM Watermarking.(EMNLP 2024 Demo)
https://aclanthology.org/2024.emnlp-demo.7/
Apache License 2.0
284 stars 29 forks source link

Unbiased Watermark #24

Open kirudang opened 1 month ago

kirudang commented 1 month 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 1 month 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 1 month 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 month 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. 😊

kirudang commented 1 month ago

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