Git Product home page Git Product logo

Comments (3)

920232796 avatar 920232796 commented on August 27, 2024 1

预训练模型是其他仓库开源的,比如(https://github.com/Morizeyao/GPT2-Chinese),模型代码跟FlagAI的实现可能不同,因此FlagAI加载的时候需要进行转换。
当您训练好模型以后,因为这时候模型代码是FlagAI的,权重跟模型是对应的, 因此不需要转换,直接加载即可。

from flagai.

920232796 avatar 920232796 commented on August 27, 2024

您好,load_weights只能在加载预训练模型时使用,进行一些权重的转换以达到适配的目的。

您训练好模型后,可以直接用torch相关的方法加载即可。

跟您展示的代码基本一致:

def load_weights(model, checkpoint_path): 
    checkpoint = torch.load(checkpoint_path, map_location=torch.device("cpu")) 
    if "module" in checkpoint: 
        # ddp 
        checkpoint = checkpoint["module"] 
    model.load_state_dict(checkpoint, strict=False)

from flagai.

svjack avatar svjack commented on August 27, 2024

您好,load_weights只能在加载预训练模型时使用,进行一些权重的转换以达到适配的目的。

您训练好模型后,可以直接用torch相关的方法加载即可。

跟您展示的代码基本一致:

def load_weights(model, checkpoint_path): 
    checkpoint = torch.load(checkpoint_path, map_location=torch.device("cpu")) 
    if "module" in checkpoint: 
        # ddp 
        checkpoint = checkpoint["module"] 
    model.load_state_dict(checkpoint, strict=False)

预训练模型的训练方法能开源一下吗?

from flagai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.