[Python] How to get the code of the hugging face models?

Discussão em 'Python' iniciado por Stack, Junho 7, 2025.

  1. Stack

    Stack Membro Participativo

    There is a simple way to download a model from hugging face,

    # Load model directly
    from transformers import AutoTokenizer, AutoModel

    tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
    model = AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")


    use it, train it and even replace the layers as long as they take the same input (shapes) and give the same output.

    Since it is based on pytorch (in this case), you get a nice view of the layers once you print it out, but you don't know the forward methods and other methods used in pytorchs model class.

    Is there a way to get the entire model in a .py file (as a nn.Module) class like it must have been initially used for training (and the weights e.g. as a .pt file)?

    Continue reading...

Compartilhe esta Página