Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aligning logits with labels through two shifts? #6

Open
Xlun opened this issue Mar 7, 2024 · 0 comments
Open

Aligning logits with labels through two shifts? #6

Xlun opened this issue Mar 7, 2024 · 0 comments

Comments

@Xlun
Copy link

Xlun commented Mar 7, 2024

在 main.py中数据准备时:

def collate_fn(examples, device):
    token_ids = torch.tensor(
        [example['token_ids'] for example in examples], device=device)
    return **{'input_ids': token_ids[:, :-1], 'labels': token_ids[:, 1:]}**

def train_chunk(.......):
..........
batch = collate_fn(
            examples=examples[i:i+per_device_batch_size], device=fabric.device)
input_ids, labels = batch['input_ids'], batch['labels']

在 modeling_llama.py 中loss计算时:

class LlamaForCausalLM(LlamaPreTrainedModel):
....................
        if labels is not None:
            # Shift so that tokens < n predict n
            **shift_logits = logits[..., :-1, :].contiguous()
            shift_labels = labels[..., 1:].contiguous()**

为什么在模型数据sample输入时进行了预测和真实值之间的位移对齐,在模型中loss计算时还进行了一次位移对齐?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant