Comments (9)
@pradeepdev-1995 In general, yes, a local path should work. The model archive needs to contain an allennlp config.json
and a weights.th
file. Additionally, if your model code is changed, it should be imported with the correct registered name, which is referenced in the config file.
I'll be happy to assist further if you run into errors with this.
from allennlp.
Thank you @AkshitaB
But one doubt where can I see the weights.th and config.json file of allennlp for this
from allennlp.
If you download the model archive tar file at model_url
and unzip it, you will see the relevant files.
from allennlp.
@AkshitaB
Okay. So the actual model config.json
contains the model_name like this in 3 places
And you are suggesting that after quantization there should be these 2 files( config.json
and weights.th
) in the quantized model folder. Along with that config.json should contain the model_name value as a new quantized model path
Is it so?
from allennlp.
@pradeepdev-1995 Yes. Essentially, your final model needs to be in a format that's readable by allennlp. For further details regarding config files and serialization, you can read the section on configuration files here: https://guide.allennlp.org/training-and-prediction#2 .
from allennlp.
@AkshitaB
As you mentioned I have quantized the nreimers/mMiniLMv2-L12-H384-distilled-from-XLMR-Large
model using dynamic quantization and kept new weigths.th
file in the folder named quantized as you see here
FYI: I removed the new config.json
file getting after the quantization because it conflicts with the allennlp format config.json
file. Only weights were only taken after quantization. (Will it cause any issues?)
Also changed the model_name to the quantized model folder local path at 3 places in the allennlp config.json file as below
Then execute the below code
from allennlp.predictors.predictor import Predictor
model_url = '/home/Downloads/quantized'
predictor = Predictor.from_path(model_url)
text = "Eva and Martha didn't want their friend Jenny \
to feel lonely so they invited her to the party."
prediction = predictor.predict(document=text)
print(prediction['clusters'])
print(predictor.coref_resolved(text))
But it shows the following error
FileNotFoundError: file /tmp/tmpj8o6jszw/config.json not found
from allennlp.
@pradeepdev-1995 Your new model needs to be a registered name; an allennlp Model class object. That is what the Predictor
will require.
So, something like:
from allennlp.model import Model
@Model.register("new-model-name")
class NewModelClass(Model):
<create/load quantized version of model>
Then, in your config, you can specify the model name as "new-model-name".
Also see this guide chapter for more details on the config file.
from allennlp.
Hi,
With my quantized model, I have tried the following:
model_url = r"custom_model/model"
predictor = Predictor.from_path(model_url)
model_url points to directory including Vocabulary, config, meta files(3 of them before quantizing) and new quantized weights.
Unfortunately, I ran into a RuntimeError as follows:
raise RuntimeError(
RuntimeError: Error loading state dict for CoreferenceResolver
Missing keys: []
Unexpected keys: ['embeddings.position_ids', 'embeddings.word_embeddings.weight', ...
Could you please help me resolve this issue with quantized model?
Do I need to change any config parameters in config.json to support my quantized model(Please note that my model name remains the same after quantization, hence the quantized model is not registered)
from allennlp.
I had tried registering my quantized model as below:
@Model.register("quantized_model")
class QuantizedModel(Model):
def __init__(self):
super().__init__(serialization_dir="custom_model/model")
Also changed the model key in original config.json
"model": {
"type": "quantized_model"
},
Now, when I try running
model_url = r"custom_model/model"
predictor = Predictor.from_path(model_url)
got TypeError: __init__() missing 1 required positional argument: 'vocab'
Is the model registration correct? Are there any additional params required for registration and in config.json. Please mention
from allennlp.
Related Issues (20)
- The DataLoader Needs to Handle Dirty Examples. HOT 8
- error message occuied โzipfile.BadZipFile: File is not a zip fileโ HOT 3
- AllenNLP biased towards BERT HOT 12
- will update to support latest pytorch? HOT 9
- Rich 12.1.0 has been yanked, but has been pinned in `requirements.txt` HOT 1
- Incompatibile packages HOT 2
- Unclear how to use text2sql model HOT 5
- Can't load models with .zip extension HOT 2
- AllenNLP-Light! ๐ ๐ HOT 2
- Is it possible to load my own quantized model from local HOT 3
- Questions about start training from checkpoint using --recover HOT 1
- SRL BERT performing poorly for german dataset HOT 1
- Remove upper bounds for requirements HOT 1
- Alternative semantic role labeling model HOT 3
- AutoTokenizer config error when load clipmodel HOT 2
- When 'instances_per_epoch' is set up in the class MultiTaskDataLoader, the function __len__ in it will return a wrong answer. HOT 1
- New version with upper bounds on dependencies removed HOT 2
- Incomplete model_state_epoch files HOT 1
- allennlp.common.checks.ConfigurationError: key "token_embedders" is required at location "model.text_field_embedder." HOT 3
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 allennlp.