While the OpenAI detector has been useful in identifying content that is created by ChatGPT and other OpenAI-based models, as usage increases (especially by users here on Stack Exchange sites), it's been down more and more frequently.
After installing it locally per the project README, I receive the following error when attempting to run it from the repo directory using python -m detector.server ../gpt-2-models/detector-base.pt
:
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/ntd/src/gpt-2-output-dataset/detector/server.py", line 120, in <module>
fire.Fire(main)
File "/home/ntd/src/venv/openai-detector/lib/python3.10/site-packages/fire/core.py", line 141, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
File "/home/ntd/src/venv/openai-detector/lib/python3.10/site-packages/fire/core.py", line 475, in _Fire
component, remaining_args = _CallAndUpdateTrace(
File "/home/ntd/src/venv/openai-detector/lib/python3.10/site-packages/fire/core.py", line 691, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
File "/home/ntd/src/gpt-2-output-dataset/detector/server.py", line 89, in main
model.load_state_dict(data['model_state_dict'])
File "/home/ntd/src/venv/openai-detector/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1671, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for RobertaForSequenceClassification:
Missing key(s) in state_dict: "roberta.embeddings.position_ids".
Unexpected key(s) in state_dict: "roberta.pooler.dense.weight", "roberta.pooler.dense.bias".
I attempted to change transformers==2.9.1
per comments in this issue, but then pip install -r requirements.txt
fails as well.
The primary problem here seems to be resolved by using
transformers==2.5.1
for me (as opposed to 2.9.1), but I also needed the Rust compiler (andbuild-essential
) to build it. Most of this, at least starting with step 11, may be applicable to a non-WSL Ubuntu as well. However, there are also a few additional dependencies for CUDA (and I can't entirely be sure which, since I don't have a pure-Ubuntu GPU system on which to test).Here are the complete steps I used to install on Ubuntu 22.04 on WSL. Note that you can simplify it quite a bit, by either not setting up a special distribution for the detector, not setting up a Python
venv
, or even skipping both. Honestly, doing both is overkill in terms of "isolation", but the steps are all here depending how you want to handle it:Registered a new Ubuntu 22.04 WSL distribution with
ubuntu2204.exe
from PowerShell. None previously existed, for reasons you'll see below.Added username and password when requested.
Ran the normal, initial
sudo apt update && sudo apt upgrade -y
.Set the default username using
/etc/wsl.conf
per my answer here.Exited Ubuntu
wsl --shutdown
Created a directory for my "openai-detector" instance:
Copied the just-created Ubuntu 22.04 instance to a new distribution named
openai-detector
:Removed the
ubuntu-22.04
distribution since I can always create another one on demand when needed (as above). However, please only do this if you are sure that this is the one you just created and that there are no files that you need from it. This is an irreversible, destructible operation. I'm honestly a bit nervous every time I do it, since there's the chance I'll accidentally use the wrong distribution name. Just ... be careful:Started the new
openai-detector
distribution created above:Installed
rustup
andbuild-essential
:Set up virtual environment:
Clone the detector and download the model files:
Modify the requirements to use Transformers 2.5.1:
Change the
transformers
line to:Install requirements:
Run:
After initial installation, all that should be required in the future to start is:
A local copy of OpenAI Detector should be running on
localhost:8080
.