Skip to content

Am I loading my trained models correctly? #9

Answered by sugarme
luxiant asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @luxiant ,

The error means there was either an issue mapping named tensors from your model and your weights or the gotch/pickle can not handle some pickled weights.

I often print out Python and Go variable names to compare.

import torch
from kobert.pytorch_kobert import get_pytorch_kobert_model

model, vocab  = get_pytorch_kobert_model()
for key, value in model.state_dict().items():
    print(f"{key} - {value.shape}")

Also, you can print out your Python pickled weight names and shapes from Go by using gotch/pickle (if it can handle it) as following:

err := pickle.LoadInfo(modelFile)
if err != nil {
    log.Fatal(err)
}
device := gotch.CPU
vs := nn.NewVarStore(device)
path := vs.Root()
m…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@luxiant
Comment options

Comment options

You must be logged in to vote
1 reply
@luxiant
Comment options

Answer selected by luxiant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants