mirror of
https://github.com/guillaume-be/rust-bert.git
synced 2024-09-11 12:55:34 +03:00
* Fixed Clippy warnings
* Revert "Shallow clone optimization (#243)"
This reverts commit ba584653bc
.
* updated dependencies
* tryouts
* GPT2 tryouts
* WIP GPT2
* input mapping
* Cache storage
* Initial GPT2 prototype
* Initial ONNX Config and decoder implementation
* ONNXDecoder first draft
* Use Decoders in example
* Automated tch-ort conversion, decoder implementation
* ONNXCausalDecoder implementation
* Refactored _get_var_store to be optional, added get_device to gen trait
* updated example
* Added decoder_start_token_id to ConfigOption
* Addition of ONNXModelConfig, make max_position_embeddigs optional
* Addition of forward pass function for ONNXModel
* Working ONNX causal decoder
* Simplify tensor conversion
* refactor translation to facilitate ONNX integration
* Implementation of ONNXEncoder
* Implementation of ONNXConditionalGenerator
* working ONNXCausalGenerator
* - Reworked model resources type for pipelines and generators
* Aligned ONNXConditionalGenerator with other generators to use GenerateConfig for creation
* Moved force_token_id_generation to common utils function, fixed tests, Translation implementation
* generalized forced_bos and forced_eos tokens generation
* Aligned the `encode_prompt_text` method across language models
* Fix prompt encoding for causal generation
* Fix prompt encoding for causal generation
* Support for ONNX models for SequenceClassification
* Support for ONNX models for TokenClassification
* Support for ONNX models for POS and NER pipelines
* Support for ONNX models for ZeroShotClassification pipeline
* Support for ONNX models for QuestionAnswering pipeline
* Support for ONNX models for MaskedLM pipeline
* Added token_type_ids , updated layer cache i/o parsing for ONNX pipelines
* Support for ONNX models for TextGenerationPipeline, updated examples for remote resources
* Remove ONNX zero-shot classification example (lack of correct pretrained model)
* Addition of tests for ONNX pipelines support
* Made onnx feature optional
* Fix device lookup with onnx feature enabled
* Updates from main branch
* Flexible tokenizer creation for M2M100 (NLLB support), make NLLB test optional du to their size
* Fixed Clippy warnings
* Addition of documentation for ONNX
* Added documentation for ONNX support
* upcoming tch 1.12 fixes
* Fix merge conflicts
* Fix merge conflicts (2)
* Add download libtorch feature to ONNX tests
* Add download-onnx feature
* attempt to enable onnx download
* add remote resources feature
* onnx download
* pin ort version
* Update ort version
64 lines
2.3 KiB
Rust
64 lines
2.3 KiB
Rust
use rust_bert::m2m_100::{M2M100SourceLanguages, M2M100TargetLanguages};
|
|
use tch::Device;
|
|
|
|
use rust_bert::pipelines::common::{ModelResource, ModelType, ONNXModelResources};
|
|
use rust_bert::pipelines::translation::{Language, TranslationConfig, TranslationModel};
|
|
use rust_bert::resources::RemoteResource;
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
let translation_model = TranslationModel::new(TranslationConfig::new(
|
|
ModelType::M2M100,
|
|
ModelResource::ONNX(ONNXModelResources {
|
|
encoder_resource: Some(Box::new(RemoteResource::new(
|
|
"https://huggingface.co/optimum/m2m100_418M/resolve/main/encoder_model.onnx",
|
|
"onnx-m2m100_418M",
|
|
))),
|
|
decoder_resource: Some(Box::new(RemoteResource::new(
|
|
"https://huggingface.co/optimum/m2m100_418M/resolve/main/decoder_model.onnx",
|
|
"onnx-m2m100_418M",
|
|
))),
|
|
decoder_with_past_resource: Some(Box::new(RemoteResource::new(
|
|
"https://huggingface.co/optimum/m2m100_418M/resolve/main/decoder_with_past_model.onnx",
|
|
"onnx-m2m100_418M",
|
|
))),
|
|
}),
|
|
RemoteResource::new(
|
|
"https://huggingface.co/optimum/m2m100_418M/resolve/main/config.json",
|
|
"onnx-m2m100_418M",
|
|
),
|
|
RemoteResource::new(
|
|
"https://huggingface.co/optimum/m2m100_418M/resolve/main/vocab.json",
|
|
"onnx-m2m100_418M",
|
|
),
|
|
Some(RemoteResource::new(
|
|
"https://huggingface.co/optimum/m2m100_418M/resolve/main/sentencepiece.bpe.model",
|
|
"onnx-m2m100_418M",
|
|
)),
|
|
M2M100SourceLanguages::M2M100_418M,
|
|
M2M100TargetLanguages::M2M100_418M,
|
|
Device::cuda_if_available(),
|
|
))?;
|
|
|
|
let source_sentence = "This sentence will be translated in multiple languages.";
|
|
|
|
let mut outputs = Vec::new();
|
|
outputs.extend(translation_model.translate(
|
|
&[source_sentence],
|
|
Language::English,
|
|
Language::French,
|
|
)?);
|
|
outputs.extend(translation_model.translate(
|
|
&[source_sentence],
|
|
Language::English,
|
|
Language::Spanish,
|
|
)?);
|
|
outputs.extend(translation_model.translate(
|
|
&[source_sentence],
|
|
Language::English,
|
|
Language::Hindi,
|
|
)?);
|
|
|
|
println!("{:?}", outputs);
|
|
Ok(())
|
|
}
|