SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2505.11541 · ACL · 2025

MorphMark: Flexible Adaptive Watermarking for Large Language Models

Baoyuan Wu, Yujiu Yang, Zongqi Wang, Tianle Gu

arXiv · PDF · Open in the Atlas

Code that ran

3 of 6 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (3 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 0 failures of our instrument; 3 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2505.11541.json · badge: /api/ran/2505.11541.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
thu-bpm/markllm marked official in Papers with Code
Papers with Code archive
3 ran · 3 no recorded run
FunctionStatusWhere it lives
BaseWatermark Ran
ran on a synthesized input · constructed an object; no result was computed
thu-bpm/markllm/watermark/morphmark/morphmark.py
code served (permissive licence) · get_code("a81fb7c8ec5d72f5")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, BaseWatermark: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from typing import Union

# Set seed for reproducibility
torch.manual_seed(0)

# Create a minimal mock model
class MockModel(nn.Module):
    def __init__(self, vocab_size=100, hidden_dim=4):
        super().__init__()
        self.vocab_size = vocab_size
        self.hidden_dim = hidden_dim
        self.embedding = nn.Embedding(vocab_size, hidden_dim)
        self.linear = nn.Linear(hidden_dim, vocab_size)
    
    def forward(self, input_ids, *args, **kwargs):
        x = self.embedding(input_ids)
        logits = self.linear(x)
        return logits
    
    def generate(self, input_ids, attention_mask=None, max_length=20, **kwargs):
        # Simple mock generate that returns input_ids repeated
        batch_size = input_ids.shape[0]
        return torch.cat([input_ids, torch.randint(0, self.vocab_size, (batch_size, 5))], dim=1)

# Create a minimal mock tokenizer
class MockTokenizer:
    def __init__(self, vocab_size=100):
        self.vocab_size = vocab_size
        self.pad_token_id = 0
        self.eos_token_id = 1
    
    def __len__(self):
        return self.vocab_size
    
    def __call__(self, text, return_tensors=None, add_special_tokens=True, *args, **kwargs):
        # Mock tokenization
        input_ids = torch.randint(2, self.vocab_size, (1, 8))
        attention_mask = torch.ones_like(input_ids)
        return {
            'input_ids': input_ids,
            'attention_mask': attention_mask
        }
    
    def batch_decode(self, token_ids, skip_special_tokens=True):
        return ["This is a mock generated text output."]

# Create mock TransformersConfig
model = MockModel(vocab_size=100, hidden_dim=4)
tokenizer = MockTokenizer(vocab_size=100)

transformers_config = type('TransformersConfig', (), {
    'model': model,
    'tokenizer': tokenizer,
    'vocab_size': 100,
    'device': 'cpu',
    'gen_kwargs': {'max_length': 20}
})()

# Create mock BaseConfig subclass for algorithm_config parameter
class MockAlgorithmConfig(type('BaseConfig', (), {
    'algorithm_name': 'mock_algorithm'
})):
    def __init__(self, algorithm_config_path=None, transformers_config=None, *args, **kwargs):
        self.config_dict = {'param1': 0.5, 'param2': 10}
        self.generation_model = transformers_config.model
        self.generation_tokenizer = transformers_config.tokenizer
        self.vocab_size = transformers_config.vocab_size
        self.device = transformers_config.device
        self.gen_kwargs = transformers_config.gen_kwargs
        self.transformers_config = transformers_config
    
    def initialize_parameters(self):
        pass
    
    @property
    def algorithm_name(self):
        return 'mock_algorithm'

# Create an instance of the mock config
algorithm_config = MockAlgorithmConfig(
    algorithm_config_path=None,
    transformers_config=transformers_config
)

# Define ARGS mapping all parameters of BaseWatermark.__init__
ARGS = {
    'algorithm_config': algorithm_config,
    'transformers_config': transformers_config
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type BaseWatermark — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a BaseWatermark output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
MorphMarkConfig Ran
ran on a synthesized input · constructed an object; no result was computed
thu-bpm/markllm/watermark/morphmark/morphmark.py
code served (permissive licence) · get_code("71ba009328036e00")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, MorphMarkConfig: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import json
import tempfile
import os

# Define a minimal tokenizer stand-in
class MinimalTokenizer:
    def __init__(self, vocab_size=1000):
        self._vocab_size = vocab_size
    
    def __len__(self):
        return self._vocab_size
    
    def encode(self, text):
        return [1, 2, 3]
    
    def decode(self, ids):
        return "decoded text"

# Define a minimal model stand-in
class MinimalModel(nn.Module):
    def __init__(self, vocab_size=1000, hidden_dim=4):
        super().__init__()
        self.embedding = nn.Embedding(vocab_size, hidden_dim)
        self.linear = nn.Linear(hidden_dim, vocab_size)
    
    def forward(self, input_ids):
        x = self.embedding(input_ids)
        return self.linear(x)

# Define TransformersConfig
class TransformersConfig:
    def __init__(self, model, tokenizer, vocab_size=None, device='cpu', *args, **kwargs):
        self.device = device
        self.model = model
        self.tokenizer = tokenizer
        self.vocab_size = len(tokenizer) if vocab_size is None else vocab_size
        self.gen_kwargs = {}
        self.gen_kwargs.update(kwargs)

# Create a temporary config file for MorphMark
temp_dir = tempfile.mkdtemp()
config_dir = os.path.join(temp_dir, 'config')
os.makedirs(config_dir, exist_ok=True)

morphmark_config = {
    'gamma': 0.5,
    'type': 'linear',
    'k_linear': 10,
    'k_exp': 5,
    'k_log': 3,
    'p_0': 0.1,
    'ewd': True,
    'delta_ewd': 0.01,
    'hash_key': 12345,
    'z_threshold': 2.0,
    'prefix_length': 50,
    'f_scheme': 'simple',
    'window_scheme': 'sliding'
}

config_path = os.path.join(config_dir, 'MorphMark.json')
with open(config_path, 'w') as f:
    json.dump(morphmark_config, f)

# Create instances
torch.manual_seed(0)
model = MinimalModel(vocab_size=1000, hidden_dim=4)
tokenizer = MinimalTokenizer(vocab_size=1000)
transformers_config = TransformersConfig(
    model=model,
    tokenizer=tokenizer,
    vocab_size=1000,
    device='cpu'
)

# Define ARGS dictionary with all parameters for MorphMarkConfig
ARGS = {
    'algorithm_config_path': config_path,
    'transformers_config': transformers_config
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MorphMarkConfig — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MorphMarkConfig output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
MorphMarkLogitsProcessor Ran
ran on a synthesized input · constructed an object; no result was computed
thu-bpm/markllm/watermark/morphmark/morphmark.py
code served (permissive licence) · get_code("cc781703afcc6ba9")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, MorphMarkLogitsProcessor: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np
from transformers import LogitsProcessor, LogitsProcessorList
from unittest.mock import Mock

torch.manual_seed(0)

# Create a minimal tokenizer stand-in
class MinimalTokenizer:
    def __init__(self, vocab_size=256):
        self.vocab_size = vocab_size
    
    def __len__(self):
        return self.vocab_size

# Create a minimal model stand-in
class MinimalModel(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = torch.nn.Linear(10, 10)
    
    def forward(self, input_ids, **kwargs):
        return Mock(logits=torch.randn(2, 10, 256))

# Create TransformersConfig
tokenizer = MinimalTokenizer(vocab_size=256)
model = MinimalModel()
transformers_config = Mock(
    model=model,
    tokenizer=tokenizer,
    vocab_size=256,
    device='cpu',
    gen_kwargs={}
)

# Create a minimal config dict for MorphMark
config_dict = {
    'gamma': 0.5,
    'type': 'linear',
    'k_linear': 2,
    'k_exp': 2,
    'k_log': 2,
    'p_0': 0.5,
    'ewd': False,
    'delta_ewd': 1.0,
    'hash_key': 42,
    'z_threshold': 2.0,
    'prefix_length': 1,
    'f_scheme': 'time',
    'window_scheme': 'left'
}

# Create MorphMarkConfig
morphmark_config = Mock(
    config_dict=config_dict,
    generation_model=model,
    generation_tokenizer=tokenizer,
    vocab_size=256,
    device='cpu',
    gen_kwargs={},
    transformers_config=transformers_config,
    gamma=0.5,
    type='linear',
    k_linear=2,
    k_exp=2,
    k_log=2,
    p_0=0.5,
    ewd=False,
    delta=1.0,
    hash_key=42,
    z_threshold=2.0,
    prefix_length=1,
    f_scheme='time',
    window_scheme='left'
)

# Create MorphMarkUtils-like object with required methods/attributes
morphmark_utils = Mock()
morphmark_utils.config = morphmark_config
morphmark_utils.rng = torch.Generator(device='cpu')
morphmark_utils.rng.manual_seed(42)
morphmark_utils.prf = torch.randperm(256, device='cpu', generator=morphmark_utils.rng)

# Mock the _get_greenlist_ids method
def mock_get_greenlist_ids(input_ids):
    batch_size = input_ids.shape[0] if len(input_ids.shape) > 1 else 1
    return [torch.randint(0, 50, (50,), device='cpu') for _ in range(batch_size)]

morphmark_utils._get_greenlist_ids = mock_get_greenlist_ids

# Create sample input
input_ids = torch.randint(0, 256, (2, 8), dtype=torch.long, device='cpu')
scores = torch.randn(2, 256, device='cpu')

ARGS = {
    'config': morphmark_config,
    'utils': morphmark_utils,
    'input_ids': input_ids,
    'scores': scores
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MorphMarkLogitsProcessor — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MorphMarkLogitsProcessor output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
BaseConfig Not yet run
unverified (harvested, no recorded run)
thu-bpm/markllm/watermark/morphmark/morphmark.py
code served (permissive licence) · get_code("8dc8fc456112ecd8")
How it ran

no invocation recorded.

MorphMark Not yet run
unverified (harvested, no recorded run)
thu-bpm/markllm/watermark/morphmark/morphmark.py
code served (permissive licence) · get_code("0db293ccd5882577")
How it ran

no invocation recorded.

MorphMarkUtils Not yet run
unverified (harvested, no recorded run)
thu-bpm/markllm/watermark/morphmark/morphmark.py
code served (permissive licence) · get_code("60742f92ea6ca774")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 0 later) and 4 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
BaseConfig
brick of this paper's assembly: helper
1 other paper
1 dated earlier · 1 only as an assembly brick
2403.13485 (2024-03)
An Entropy-based Text Watermarking Detection Method
BaseWatermark
brick of this paper's assembly: helper
1 other paper
1 dated earlier · 1 only as an assembly brick
2403.13485 (2024-03)
An Entropy-based Text Watermarking Detection Method

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Watermarking by altering token sampling probabilities based on red-green list is a promising method for tracing the origin of text generated by large language models (LLMs). However, existing watermark methods often struggle with a fundamental dilemma: improving watermark effectiveness (the detectability of the watermark) often comes at the cost of reduced text quality. This trade-off limits their practical application. To address this challenge, we first formalize the problem within a multiobjective trade-off analysis framework. Within this framework, we identify a key factor that influences the dilemma. Unlike existing methods, where watermark strength is typically treated as a fixed hyperparameter, our theoretical insights lead to the development of MorphMark-a method that adaptively adjusts the watermark strength in response to changes in the identified factor, thereby achieving an effective resolution of the dilemma. In addition, MorphMark also prioritizes flexibility since it is an modelagnostic and model-free watermark method, thereby offering a practical solution for realworld deployment, particularly in light of the rapid evolution of AI models. Extensive experiments demonstrate that MorphMark achieves a superior resolution of the effectiveness-quality dilemma, while also offering greater flexibility and time and space efficiency.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2505.11541")
get_code_for_paper("2505.11541")
have("2505.11541")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2505.11541.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2505.11541.svg)](https://syntology.ai/paper/2505.11541)

Connect an agent — have() is free.