Comments (7)
First, run:
import gpt_2_simple as gpt2
gpt2.download_gpt2(model_name='345M')
Then:
!mkdir -p checkpoint/
!cp -r models/345M checkpoint/run1
Finally:
import gpt_2_simple as gpt2
sess = gpt2.start_tf_sess()
gpt2.load_gpt2(sess)
gpt2.generate(sess)
from gpt-2-simple.
With version 0.6, you should be able to directly run:
import gpt_2_simple as gpt2
model_name='774M'
gpt2.download_gpt2(model_name=model_name)
sess = gpt2.start_tf_sess()
gpt2.load_gpt2(sess, model_name=model_name)
gpt2.generate(sess, model_name=model_name)
from gpt-2-simple.
True. It seems that there is a bit of redundancy w.r.t. parameters being loaded by both load_gpt2
and generate
. However, by looking at the code, the generate
function seems to require the model name to be able to encode the prefix. Paging @minimaxir, because he knows better than me.
def load_gpt2(sess,
[...]
multi_gpu=False):
"""Loads the model checkpoint or existing model into a TensorFlow session
for repeated predictions.
"""
[...]
hparams = model.default_hparams()
with open(os.path.join(checkpoint_path, 'hparams.json')) as f:
hparams.override_from_dict(json.load(f))
[...]
def generate(sess,
[...]
include_prefix=True):
"""Generates text from a model loaded into memory.
Adapted from:
https://github.com/openai/gpt-2/blob/master/src/interactive_conditional_samples.py
"""
[...]
enc = encoder.get_encoder(checkpoint_path)
hparams = model.default_hparams()
with open(os.path.join(checkpoint_path, 'hparams.json')) as f:
hparams.override_from_dict(json.load(f))
if prefix:
context = tf.compat.v1.placeholder(tf.int32, [batch_size, None])
context_tokens = enc.encode(prefix)
[...]
from gpt-2-simple.
I'm confused @woctezuma . Why do you have to indicate model_name
to the generate
method? Shouldn't gpt2
contain the parameters once you load it in your penultimate line?
from gpt-2-simple.
from gpt-2-simple.
The redundancy is confusing. What happens if I load a checkpoint trained on 124M for load_gpt2(), and load 124M without any fine-tuning for generate()?
from gpt-2-simple.
Yeah this seems weird to me too because if @woctezuma is right, then you hypothetically could use different checkpoints of the same model and not have any errors thrown. We'll see if @minimaxir can shed some light.
from gpt-2-simple.
Related Issues (20)
- README Tutorial fails HOT 1
- Newbie issue HOT 3
- How to load pretrained model in a new notebook without retraining? HOT 1
- (not an issue) training 124m model works perfectly on 3060
- Converting generated data to not tokenized default version
- gpt HOT 1
- Thank you for making this repo.
- Results of finetuned model is different in Google Colab and on local machine HOT 1
- Simple question HOT 1
- Response generated in console, but can't retrieve it? HOT 2
- Can you force the framework to use CPU?
- Can you include code for this to handle GPT-Neo-125M HOT 1
- any way to clear up vram after running the model
- Resource exhausted error during training
- How to use the same trained model with C++ and make questions to it?
- gpt
- doesnt work HOT 1
- ValueError: Can't load save_path when it is None.
- how to run only generation on windows pls
- GPT-2 implementation problem
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gpt-2-simple.