Product

Sunday, 7 May 2023

Can't import the encoder code for fine tuning GPT-2

 I'm trying to reproduce the example from this article: https://medium.com/@ngwaifoong92/beginners-guide-to-retrain-gpt-2-117m-to-generate-custom-text-content-8bb5363d8b7f

The example code is from the following repo: https://github.com/nshepperd/gpt-2

After installing the requirements and downloading the model, the following step is to train the model, for which this code has to be executed:

python encode.py lyric.txt lyric.npz

The issue here is that this requires to import the following modules:

import argparse
import numpy as np

import encoder
from load_dataset import load_dataset

Where encoder and load_dataset are on a child directory:

|--encode.py
 --src
   |--encoder.py
   |--load_dataset.py

This generates the following error:

ModuleNotFoundError: No module named 'encoder'

I tried creating the __init__.py files and importing them as

src.encoder and src.load_dataset but that those not work either.

In the medium post the author proposes to move the file encoder.py to src and execute the code from there, the issue there is that doing it breaks the relative path for the model too and although I handled that the issue with the paths keeps going for other files as well.

  1. Make an empty file named __init__.py inside the src folder.
  2. Import encoder as:from src import encoder
  3. encode.py

   none of that worked for me. however what i did was i installed python 3.6 because tensorflow is compatible with this version, I installed the following requirements :

h5py==3.1.0      
idna==2.10       
protobuf==3.13.0     
pywin32==228        
regex==2020.10.28 
requests==2.24.0     
tensorboard==2.3.0      
tensorflow==2.3.1      
tensorflow-estimator==2.3.0      
tqdm==4.51.0     
urllib3==1.25.11

updated the visual C++ for tensorflow https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads and run the encode.py and it worked.

This is not the 100% correct way to do this but to get around settign a pythonpath, you can copy the files into the src/ directory from the gpt-2/ directory.

So after you are in the gpt-2 directory you can run the following in your cmd line.

cp encode.py src\
cp train.py src\
cp models\ src\

If you do all of this then cd into src/ and run:

python filetoencode.txt filetoencode.npz

you should now have an encoded file and be able to move onto the next steps in the blog post.

Enjoy and have fun with the gpt-2 :)

I know this is a really old topic, but this worked for me: Change encode.py imports to

import src.encoder as encoder
from src.load_dataset import load_dataset

Then you can run

 py encode.py trainingfile.txt training.npz

No comments:

Post a Comment

Connect broadband

AI:List AI views on when for a naive kin after prolonged life suppression coercive behaviour by family members after demise of father with trauma for kin ocd formed after forced to do rituals, family tribal values honor specific activities, utmost religious activities occult witchcraft enforced to do by elder sibling his wife and mother thrice with great celibacy turned the kundalini activated after deep celibacy penance shouting physical Mental financial Extortion by sibling with toxic behaviours and the wife mother and then mockery suppression asking about who’re your worth backbiting among relatives sector toon negligence of intelligence intuitive behaviour- all religious psychological traps when not work and lead to loss of consciousness of kin trance state recovered by governance with technocrats using AI - kin was asked by mother that he’s to go the male should not be seen in house he’s many absurd thought forcefully in brain mind and outsiders already feel awkward of this kin unresponsive behaviour due to TBI PTSD ocd cvt and tell at workplace social gathering he’s to go and asked for sector toon extortion and mockery in various sense due to un practical behaviour negligence of body building due to neglect ion if essential food nutrition and stubbed suppressed in every sense in religious psychological traps by family members AI humanoid using various neural networks and LLMs for kin and required steps.

  List AI views on when for a naive kin after prolonged life suppression coercive behaviour by family members after demise of father with tr...