SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2106.05744 · 2021

Pivotal Tuning for Latent-based Editing of Real Images

arXiv · PDF · Open in the Atlas

Code that ran

3 of 4 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 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; 1 no recorded run), measured 2026-11-22; 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/2106.05744.json · badge: /api/ran/2106.05744.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
danielroich/PTI canonical (classifier label)
classifier basis: census
1 ran · 1 no recorded run
cloneofsimo/lora extension (classifier label)
classifier basis: classifier_2025
2 ran · 0 no recorded run
FunctionStatusWhere it lives
get_delta Ran
ran on a synthesized input
danielroich/PTI/editings/ganspace.py
code served (permissive licence) · get_code("f13e021711aea982")
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 Tensor, ndim 1, dtype family float, shape (4,) as a later run recorded it. 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, ndim and shape 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

torch.manual_seed(0)

# The function expects:
# - pca: dict with keys 'mean', 'comp', 'std' (all tensors)
# - latent: tensor with shape that allows indexing [0] and reshaping to 1D
# - idx: integer index
# - strength: float or scalar

# Build pca dict with tensors
pca = {
    'mean': torch.randn(1, 4),      # shape (1, 4)
    'comp': torch.randn(3, 4),      # shape (3, 4) - components
    'std': torch.randn(3),          # shape (3,) - standard deviations
}

# Build latent tensor - needs to support [0] indexing and reshaping
latent = torch.randn(2, 4)  # batch of 2, dimension 4

# idx - index into components (must be < 3)
idx = 1

# strength - scalar value
strength = 0.5

ARGS = {
    'pca': pca,
    'latent': latent,
    'idx': idx,
    'strength': strength,
}
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 Tensor, ndim 1, dtype family float, shape (4,) — shape (4,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
inpainting_dataloader Ran
ran on a synthesized input
cloneofsimo/lora/lora_diffusion/cli_lora_pti.py
code served (permissive licence) · get_code("d793962f13865771")
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 DataLoader. The image it ran in was 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 torch.utils.data import Dataset

torch.manual_seed(0)

# Create a minimal tokenizer that has the required interface
class MinimalTokenizer:
    def __init__(self):
        self.model_max_length = 77
    
    def pad(self, token_dict, padding=None, max_length=None, return_tensors=None):
        input_ids = token_dict['input_ids']
        # Pad sequences to max_length
        padded_ids = []
        for ids in input_ids:
            if len(ids) < max_length:
                ids = ids + [0] * (max_length - len(ids))
            else:
                ids = ids[:max_length]
            padded_ids.append(ids)
        
        result_dict = {'input_ids': torch.tensor(padded_ids)}
        # Return object with input_ids attribute
        class PadResult:
            pass
        pad_result = PadResult()
        pad_result.input_ids = torch.tensor(padded_ids)
        return pad_result

# Create a minimal VAE (not actually used in collate_fn but passed as arg)
class MinimalVAE(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)

# Create a minimal text encoder (not actually used in collate_fn but passed as arg)
class MinimalTextEncoder(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)

# Create a minimal dataset
class InpaintingDataset(Dataset):
    def __init__(self, num_samples=2):
        self.num_samples = num_samples
    
    def __len__(self):
        return self.num_samples
    
    def __getitem__(self, idx):
        # Return example dict with required keys
        example = {
            'instance_prompt_ids': [101, 2054, 2003, 102],  # tokenized text
            'instance_images': torch.randn(3, 4, 4),  # 3 channels, 4x4 image
            'instance_masks': torch.ones(1, 4, 4),    # 1 channel mask
            'instance_masked_images': torch.randn(3, 4, 4),  # 3 channels, 4x4 image
        }
        return example

# Construct arguments
train_dataset = InpaintingDataset(num_samples=2)
train_batch_size = 2
tokenizer = MinimalTokenizer()
vae = MinimalVAE()
text_encoder = MinimalTextEncoder()

ARGS = {
    'train_dataset': train_dataset,
    'train_batch_size': train_batch_size,
    'tokenizer': tokenizer,
    'vae': vae,
    'text_encoder': text_encoder,
}
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 DataLoader — a DataLoader output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a DataLoader 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
text2img_dataloader Ran
ran on a synthesized input
cloneofsimo/lora/lora_diffusion/cli_lora_pti.py
code served (permissive licence) · get_code("aa63f591fb2e9bd7")
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 DataLoader. The image it ran in was 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 torch.utils.data import Dataset

torch.manual_seed(0)

# Mock VAE model
class MockVAE(nn.Module):
    def __init__(self):
        super().__init__()
        self.device = torch.device('cpu')
        self.dtype = torch.float32
        self.linear = nn.Linear(4, 4)
    
    def encode(self, x):
        # Returns an object with latent_dist that has a sample() method
        class LatentDist:
            def sample(self):
                return torch.randn(1, 4, 4, 4)
        return type('obj', (object,), {'latent_dist': LatentDist()})()

# Mock Text Encoder
class MockTextEncoder(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)

# Mock Tokenizer
class MockTokenizer:
    def __init__(self):
        self.model_max_length = 77
    
    def pad(self, input_dict, padding=None, max_length=None, return_tensors=None):
        input_ids = input_dict['input_ids']
        # Pad each sequence to max_length
        padded = []
        for ids in input_ids:
            if len(ids) < max_length:
                ids = ids + [0] * (max_length - len(ids))
            else:
                ids = ids[:max_length]
            padded.append(ids)
        padded_tensor = torch.tensor(padded)
        return type('obj', (object,), {'input_ids': padded_tensor})()

# Mock Dataset
class MockDataset(Dataset):
    def __init__(self, size=2):
        self.size = size
    
    def __len__(self):
        return self.size
    
    def __getitem__(self, idx):
        return {
            'instance_prompt_ids': [1, 2, 3],
            'instance_images': torch.randn(3, 4, 4),  # 3 channels, 4x4 image
            'mask': torch.randn(4, 4)
        }

vae = MockVAE()
text_encoder = MockTextEncoder()
tokenizer = MockTokenizer()
train_dataset = MockDataset(size=2)
train_batch_size = 2

ARGS = {
    'train_dataset': train_dataset,
    'train_batch_size': train_batch_size,
    'tokenizer': tokenizer,
    'vae': vae,
    'text_encoder': text_encoder,
    'cached_latents': False,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type DataLoader — a DataLoader output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a DataLoader 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
edit Not yet run
unverified (harvested, no recorded run)
danielroich/PTI/editings/ganspace.py
code served (permissive licence) · get_code("5aecdc0de1cf3f53")
How it ran

no invocation recorded.

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 distinct functions with an identity, 2 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 2 later) and 2 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
inpainting_dataloader 2 other papers
2 later
2310.04687 (2023-10)
Targeted Attack Improves Protection against Unauthorized Diffusion Customization
2402.02347 (2024-02)
Riemannian Preconditioned LoRA for Fine-Tuning Foundation Models
text2img_dataloader 2 other papers
2 later
2310.04687 (2023-10)
Targeted Attack Improves Protection against Unauthorized Diffusion Customization
2402.02347 (2024-02)
Riemannian Preconditioned LoRA for Fine-Tuning Foundation Models

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

Repositories linked to this paper

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

Abstract

Recently, a surge of advanced facial editing techniques have been proposed that leverage the generative power of a pre-trained StyleGAN. To successfully edit an image this way, one must first project (or invert) the image into the pre-trained generator's domain. As it turns out, however, StyleGAN's latent space induces an inherent tradeoff between distortion and editability, i.e. between maintaining the original appearance and convincingly altering some of its attributes. Practically, this means it is still challenging to apply ID-preserving facial latent-space editing to faces which are out of the generator's domain. In this paper, we present an approach to bridge this gap. Our technique slightly alters the generator, so that an out-of-domain image is faithfully mapped into an in-domain latent code. The key idea is pivotal tuning - a brief training process that preserves the editing quality of an in-domain latent region, while changing its portrayed identity and appearance. In Pivotal Tuning Inversion (PTI), an initial inverted latent code serves as a pivot, around which the generator is fined-tuned. At the same time, a regularization term keeps nearby identities intact, to locally contain the effect. This surgical training process ends up altering appearance features that represent mostly identity, without affecting editing capabilities. We validate our technique through inversion and editing metrics, and show preferable scores to state-of-the-art methods. We further qualitatively demonstrate our technique by applying advanced edits (such as pose, age, or expression) to numerous images of well-known and recognizable identities. Finally, we demonstrate resilience to harder cases, including heavy make-up, elaborate hairstyles and/or headwear, which otherwise could not have been successfully inverted and edited by state-of-the-art methods.

For agents

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

get_harvested_code_for_paper("2106.05744")
get_code_for_paper("2106.05744")
have("2106.05744")

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

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

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

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

Connect an agent — have() is free.