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

error while runing score.sh in aishell #241

Open
lfgogogo opened this issue Jan 5, 2021 · 4 comments
Open

error while runing score.sh in aishell #241

lfgogogo opened this issue Jan 5, 2021 · 4 comments

Comments

@lfgogogo
Copy link

lfgogogo commented Jan 5, 2021

error message:./score.sh:line 64: 841Segmentation fault (core dumped) CUDA_VISIBLE_DEVICES=${gpu} ${NEURALSP_ROOT}/neural_sp/bin/asr/eval.py......
When i ran score.sh,it crashed without giving exact error.
How to solve it?

@lfgogogo
Copy link
Author

lfgogogo commented Jan 5, 2021

I quantize the model using pytorch 1.3,it seems to be successful.When i run score.sh using pytorch 1.3,it gives the error message above,maybe someting wrong happen in the dataload stage.Then i run score.sh using pytorch 1.0.1,it gives the following error message:
AttributeError:can't get attribute '_rebuild_qtensor' ,rise from neuralsp/bin/train_utils.py,exactly by the torch.load() in load_checkpoint().

@hirofumi0810
Copy link
Owner

@lfgogogo Quantization is one of the milestones in this framework. Could you please consider sending a PR?
Also, what kind of model did you try to evaluate?

@lfgogogo
Copy link
Author

lfgogogo commented Jan 6, 2021

Of course.I am not sure about the kind you say. I quantize the model.epoch-25 and the model-avg10 using pytorch1.3 has the quantization module,when i use the quantized model to evaluate,it gives errors above.
Besides,i also use package distiller v0.3.2 to quantize the model.epoch-25,this raises an error:Unexpected key(s) in state_dict.I will make a PR soon.

@lfgogogo
Copy link
Author

lfgogogo commented Jan 6, 2021

I can't login in github on the pycharm,so i can't pull request now,sorry for that.
Here is how i quantize the model.
`
from neural_sp.bin.train_utils import (
load_checkpoint
)
from neural_sp.models.seq2seq.speech2text import Speech2Text
import torch
from neural_sp.bin.args_asr import parse_args_eval
from distiller.quantization.range_linear import PostTrainLinearQuantizer
import distiller.apputils as apputils
from neural_sp.trainers.lr_scheduler import LRScheduler
from neural_sp.trainers.optimizer import set_optimizer

argv=[]
args, ,= parse_args_eval(argv)
model = Speech2Text(args, 'modelpath')
load_checkpoint('modelpath', model)

#1、using pytorch1.3
quantized_model=torch.quantization.quantize_dynamic(model, {torch.nn.Linear}, dtype=torch.qint8)

quantized_model_path='a path'
optimizer = set_optimizer(model, args.optimizer, args.lr, args.weight_decay)
is_transformer = 'former' in args.enc_type or 'former' in args.dec_type
scheduler = LRScheduler(optimizer, args.lr,
decay_type=args.lr_decay_type,
decay_start_epoch=args.lr_decay_start_epoch,
decay_rate=args.lr_decay_rate,
decay_patient_n_epochs=args.lr_decay_patient_n_epochs,
early_stop_patient_n_epochs=args.early_stop_patient_n_epochs,
lower_better=args.metric not in ['accuracy', 'bleu'],
warmup_start_lr=args.warmup_start_lr,
warmup_n_steps=args.warmup_n_steps,
peak_lr=0.05 / (getattr(args, 'transformer_enc_d_model', 0) **
0.5) if 'conformer' in args.enc_type else 1e6,
model_size=getattr(args, 'transformer_enc_d_model',
getattr(args, 'transformer_dec_d_model', 0)),
factor=args.lr_factor,
noam=args.optimizer == 'noam',
save_checkpoints_topk=10 if is_transformer else 1)
scheduler.save_checkpoint(quantized_model, quantized_model_path, remove_old=False)
#model.module.state_dict()->model.state_dict()

#2、using distiller
model = model.cuda()
model.eval()

quantizer = PostTrainLinearQuantizer(model)

quantizer.prepare_model()

apputils.save_checkpoint(0, 'model', model, optimizer=None,
name='quantized_model_name',
dir='quantized_model_path')
`

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

No branches or pull requests

2 participants