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

GPT2 on flask #198

Closed
GodSaveTheDucks opened this issue Apr 17, 2020 · 3 comments
Closed

GPT2 on flask #198

GodSaveTheDucks opened this issue Apr 17, 2020 · 3 comments

Comments

@GodSaveTheDucks
Copy link

Hi, I'm trying to load a fine-tuned model on my flask application which takes input from a text field and generates an output. I was wondering what is the best way to make the model load faster since the text generation takes around 10-15 seconds.
I have my function -

`
model_name = os.getcwd() + "/checkpoint/run1/"

 @app.route('/startWriting/',methods=['GET','POST'])

def startWriting():  

    tf.reset_default_graph()  

    sess.close()  

    sess = gpt2.start_tf_sess()  

    data = request.form.get('text')  

    gpt2.load_gpt2(sess, model_name=fine_tuned_model)  

    extend_text(data,seas)  

`

and in extend text, (the text generator function, I have)

`
def extend_text(text,Sess):

print ("function in extend_text")
 
return gpt2.generate(sess,

      run_name='run1',

      length=25,

      temperature=0.4,

      prefix=text,

      nsamples=1,

      batch_size=1,

      return_as_list=True)[0]`

I tried loading gpt2.load_gpt2(sess, model_name=fine_tuned_model) globally but I got an error ValueError: Tensor Tensor("Placeholder:0", shape=(1, ?), dtype=int32) is not an element of this graph.

@minimaxir
Copy link
Owner

Unfortunately there isn't a good solution aside from doing a refresh every n generations (see gpt-2-cloud-run for how this is implemented in Starlette, which will be the same as Flask: https://github.com/minimaxir/gpt-2-cloud-run)

It's an underlying issue with the model architecture which will be addressed in another package I will make.

@TheButlah
Copy link

I'm not sure I understand this - what is the underlying cause of the issue?

@NeonWizard
Copy link

See this PR for a possible solution: #272

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

No branches or pull requests

4 participants