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
prop:Help:StartUp #159
Comments
Hello, For a model available online, I'd recommend using use rust_bert::pipelines::common::ModelType;
use rust_bert::pipelines::text_generation::{TextGenerationConfig, TextGenerationModel};
use rust_bert::resources::{RemoteResource, Resource};
fn main() -> anyhow::Result<()> {
// Set-up model
let custom_gpt2_model = Resource::Remote(RemoteResource::new(
"https://huggingface.co/remotejob/tweetsGPT2fi_v1/resolve/main/rust_model.ot",
"tweetsGPT2fi_v1/model",
));
let custom_gpt2_vocab = Resource::Remote(RemoteResource::new(
"https://huggingface.co/remotejob/tweetsGPT2fi_v1/resolve/main/vocab.json",
"tweetsGPT2fi_v1/vocab",
));
let custom_gpt2_merges = Resource::Remote(RemoteResource::new(
"https://huggingface.co/remotejob/tweetsGPT2fi_v1/resolve/main/merges.txt",
"tweetsGPT2fi_v1/merges",
));
let custom_gpt2_config = Resource::Remote(RemoteResource::new(
"https://huggingface.co/remotejob/tweetsGPT2fi_v1/resolve/main/config.json",
"tweetsGPT2fi_v1/config",
));
let generate_config = TextGenerationConfig {
model_resource: custom_gpt2_model,
vocab_resource: custom_gpt2_vocab,
merges_resource: custom_gpt2_merges,
config_resource: custom_gpt2_config,
model_type: ModelType::GPT2,
max_length: 64,
do_sample: true,
num_beams: 5,
temperature: 1.1,
num_return_sequences: 3,
..Default::default()
};
let model = TextGenerationModel::new(generate_config)?;
let input_context = "Hello";
let output = model.generate(&[input_context], None);
for sentence in output {
println!("{:?}", sentence);
}
Ok(())
} I tried running this example and unforntuately the tokenizer raises an exception because it expects an unknown token that is aligned with the standard GPT2 token You would need to add |
My tentative resolve issue:
It's OK working
I substitute the original model by my model. Error: Tch tensor error: Internal torch error: [enforce fail at inline_container.cc:110] . file in archive is not in a subdirectory: transformer.wte.weight.npy PS: Python version working by the way! |
Hello @remotejob , The vocabulary is now fine. I tried loading the weights and could reproduce the error. I realized the latest version of the utilities script was performing an optimization of the model size that was not compatible with the GPT2 implementation. I just pushed some changes to master (#160) that allow leveraging this optimization, or turn these optimizations off. Could you please pull the latest version of master and try converting the Rust weights again? You have 2 options to do so:
I ran the conversion on my end and the model is running:
|
Unfortunately python path/to/convert_model.py pytorch_model.bin autopep8 1.4.4 Python 3.7.0 |
My solution:
Python 3.6.8 instead of Python 3.7.0 ?certifi 2021.5.30
|
Awesome! I was trying to reproduce the issue, and I had no problem with the following environment:
Glad it now works out! |
It's my first approach to RUST. So as I said I am new to RUST. I am appreciating for some hints related to making the program more productive. Thanks. |
Hello @remotejob , The speed-up that can be expected from the Rust implementation depends on the use case. For text generation using GPT2, I did notice significant performance improvement (especially if top-k/p sampling is enabled). I have published some benchmarks available at https://guillaume-be.github.io/2020-11-21/generation_benchmarks where I was observing around 2x speed improvement on the Rust version compared to Python for GPT2 generation. A few questions/comments that may be useful:
unsafe {
torch_sys::dummy_cuda_dependency();
} in your code and add to your dependencies: [dependencies]
torch-sys = "0.4.1" |
Question:
|
Hello @remotejob , DistilGPT2 is supported and uses the same architecture / |
Yes, I tested on https://huggingface.co/remotejob/tweetsDISTILGPT2fi_v1. It's work a little better, size is matter. But pytorch_model.bin smaller rust_model.ot. Unfortunately in my case looks like the python version works more productive. I don't see a particular improvement. I am waiting for a new release. Probably flag --skip_embeddings help. Maybe parameters matter:
|
Hello, The generation parameters can be changed in the let generate_config = TextGenerationConfig {
model_resource: custom_gpt2_model,
vocab_resource: custom_gpt2_vocab,
merges_resource: custom_gpt2_merges,
config_resource: custom_gpt2_config,
model_type: ModelType::GPT2,
max_length: 100,
top_k: 50,
top_p: 0.95,
do_sample: true,
num_beams: 1,
no_repeat_ngram_size: 2,
num_return_sequences: 225,
..Default::default()
};
let model = TextGenerationModel::new(generate_config)?; Note that setting 225 for The next release will slightly reduce the model size and memory footprint, but will have no impact on the computation speed. |
I have a simple GPT2 model on
https://huggingface.co/remotejob/tweetsGPT2fi_v1/tree/main
rust_model.ot uploaded
Pls. give me some idea for a startup.
my python version working correctly
from transformers import AutoModelWithLMHead, AutoTokenizer, pipeline
model = AutoModelWithLMHead.from_pretrained("remotejob/tweetsGPT2fi_v1")
tokenizer = AutoTokenizer.from_pretrained("remotejob/tweetsGPT2fi_v1")
generator= pipeline('text-generation', model=model, tokenizer=tokenizer)
res = generator("Kuka sei")
print(res)
The text was updated successfully, but these errors were encountered: