mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
Force return_tuple=True to handle transformers breaking change of output format. (#4599)
This commit is contained in:
parent
ea87c0d028
commit
ace41b8064
3 changed files with 8 additions and 1 deletions
|
|
@ -126,6 +126,8 @@ def main():
|
|||
model_class = MODEL_CLASSES[args.model_class][0]
|
||||
|
||||
config = AutoConfig.from_pretrained(args.model_name, torchscript=args.torchscript, cache_dir=cache_dir)
|
||||
if hasattr(config, 'return_tuple'):
|
||||
config.return_tuple = True
|
||||
model = model_class.from_pretrained(args.model_name, config=config, cache_dir=cache_dir)
|
||||
|
||||
# This scirpt does not support float16 for PyTorch.
|
||||
|
|
|
|||
|
|
@ -111,7 +111,10 @@ def main():
|
|||
assert not args.use_gpu, "quantization only supports CPU"
|
||||
|
||||
model_class = MODEL_CLASSES[args.model_class][0]
|
||||
model = model_class.from_pretrained(args.model_name_or_path, cache_dir=cache_dir)
|
||||
config = AutoConfig.from_pretrained(args.model_name_or_path, cache_dir=cache_dir)
|
||||
if hasattr(config, 'return_tuple'):
|
||||
config.return_tuple = True
|
||||
model = model_class.from_pretrained(args.model_name_or_path, config=config, cache_dir=cache_dir)
|
||||
|
||||
device = torch.device("cuda:0" if args.use_gpu else "cpu")
|
||||
model.eval().to(device)
|
||||
|
|
|
|||
|
|
@ -167,6 +167,8 @@ def export_onnx_model(model_name, opset_version, use_external_data_format, model
|
|||
use_gpu, precision, optimize_onnx, validate_onnx, use_raw_attention_mask, overwrite,
|
||||
model_fusion_statistics):
|
||||
config = AutoConfig.from_pretrained(model_name, cache_dir=cache_dir)
|
||||
if hasattr(config, 'return_tuple'):
|
||||
config.return_tuple = True
|
||||
model = load_pretrained_model(model_name, config=config, cache_dir=cache_dir)
|
||||
model.cpu()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue