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

请问如何计算qwen2-vl的loss? #2403

Closed
waltonfuture opened this issue Nov 7, 2024 · 6 comments
Closed

请问如何计算qwen2-vl的loss? #2403

waltonfuture opened this issue Nov 7, 2024 · 6 comments

Comments

@waltonfuture
Copy link

def get_mm(img, inst, processor):
    messages = [
        {
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "image": img,
                },
                {"type": "text", "text": inst},
            ],
        }
    ]

    # Preparation for inference
    text = processor.apply_chat_template(
        messages, tokenize=False, add_generation_prompt=True
    )
    # '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<|vision_start|><|image_pad|><|vision_end|>Describe this image.<|im_end|>\n<|im_start|>assistant\n'
    image_inputs, video_inputs = process_vision_info(messages)
    inputs = processor(
        text=[text],
        images=image_inputs,
        videos=video_inputs,
        padding=True,
        return_tensors="pt",
    )
    inputs = inputs.to("cuda")

    outputs = model(**inputs, labels=inputs["input_ids"])
    return outputs.loss.item()

我设计这个函数计算loss,发现loss值特别大(大概在16-18左右),请问应该怎么修正成正确的计算方式呢?

@Jintao-Huang
Copy link
Collaborator

#2361

please use ms-swift==2.5.2 or use transformers<4.46

@waltonfuture
Copy link
Author

您好!我用了transformers=4.45.2和ms-swift==2.5.2,依然出现loss特别大的问题

@Jintao-Huang
Copy link
Collaborator

用swift sft跑呗, swift只会对response, eos, history中的response部分计算损失

@waltonfuture
Copy link
Author

谢谢!我想只统计loss,纯推理,不对模型做sft,请问该怎么操作呢

@waltonfuture
Copy link
Author

我把代码改了下,已解决问题。感谢回复!

@munian08
Copy link

我把代码改了下,已解决问题。感谢回复!

请问能分享一下是怎么修改的吗 谢谢!

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

3 participants