Comments (17)
I recently ran into this problem, and after reading the above comments resolved it by giving the absolute path to the folder instead of the relative one.
I'm not sure if this is a hugging face issue, or the cluster environment I'm working on, but I thought I would mention it here in case it helps anyone.
from setfit.
I still get this error:
peftmodelpath = "/notebooks/eva/model.bin"
model = PeftModelForCausalLM.from_pretrained(
model,
peftmodelpath,
cache_dir=peftmodelpath,
local_files_only=True,
model_head_file=None
)
HFValidationError: Repo id must be in the form 'repo_name' or 'namespace/repo_name': '/notebooks/eva/model.bin'. Use
repo_type argument if needed.
from setfit.
I get the same error. When I try to load a locally saved model:
from setfit import SetFitModel
model = SetFitModel.from_pretrained("/path/to/model-directory", local_files_only=True)
I get
HFValidationError: Repo id must be in the form 'repo_name' or 'namespace/repo_name': '/path/to/model-directory'. Use `repo_type` argument if needed.
I think this could be solved by changing these lines from
if os.path.isdir(model_id) and MODEL_HEAD_NAME in os.listdir(model_id):
model_head_file = os.path.join(model_id, MODEL_HEAD_NAME)
to something like
if os.path.isdir(model_id):
if MODEL_HEAD_NAME in os.listdir(model_id):
model_head_file = os.path.join(model_id, MODEL_HEAD_NAME)
else:
model_head_file = None
from setfit.
I saved a trained model on local path. I can't see anything wrong when loading the model using from_pretrained
with correct path.
This error appears when you try to load a model from a nonexistent local path which have more than 1 backslash \
with local_files_only=True
.
- if we pass a nonexistent path:
- if path is in the form 'repo_name' or 'namespace/repo_name':
ModelHubMixin.from_pretrained
will throwFileNotFoundError
. - else:
ModelHubMixin.from_pretrained
will throw aHFValidationError
because the path does not exist locally and is not in the expected hub form.
- if path is in the form 'repo_name' or 'namespace/repo_name':
- if we pass an existing local folder with no body: SentenceTransformer will throw an
OSError: /path/to/your/model does not appear to have a file named config.json
- if we pass an existing folder with a body and head: no issue in this case
- if we pass an existing folder with a body with no head:
SetFitModel._from_pretrained
throwsHFValidationError
not catched by try/except. Since the expected behaviour in SetFit_from_pretrained
classmethod is to initialise classification head with random weights when the MODEL_HEAD_NAME is not found, this can be considered as a bug.
@pdhall99 's suggestion looks fixing the issue and follows the same logic in the ModelHubMixin.from_pretrained
:
- if folder exists:
- if model head file exists =>
model_head_file = os.path.join(model_id, MODEL_HEAD_NAME)
elseNone
=> initialise classification head with random weights
- if model head file exists =>
- else: look for the model head in the hub using
hf_hub_download
.
from setfit.
@kryptec thank you so much, I tried your method and gave it the absolute path, and apparently, it works now!
from setfit.
In the Colab this happens if you mount drive. For some reason mounted path is not recognized. Instead, try having model in /content
. This should solve issue of missing path.
from setfit.
Hello,
I am trying to read the hf model directly from s3 on sagemaker studio. I am also getting same 'HFValidationError' error. I am putting my code below:
`from transformers import T5Tokenizer, T5ForConditionalGeneration
Specify the S3 URL to your model and tokenizer
model_url = "s3://bucketname/model/"
Load the model and tokenizer from S3
tokenizer = T5Tokenizer.from_pretrained(model_url)
model = T5ForConditionalGeneration.from_pretrained(model_url)
Now you can use the model and tokenizer for inference
input_text = "translate English to German: How old are you?"
input_ids = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True, max_length=512)
input_ids.to("cuda")
outputs = model.generate(input_ids)
print(tokenizer.decode(outputs[0]))`
I am able to see the model by running below code on sagemaker, so i am sure the path is correct.
`s3 = boto3.client('s3')
List all objects in the model folder from S3
s3_resource = boto3.resource('s3')
my_bucket = s3_resource.Bucket(bucket_name)
for object_summary in my_bucket.objects.filter(Prefix=''):
file_path = object_summary.key
file_name = os.path.basename(file_path)
if file_name:
print(file_name)`
Can you please help me? Thanks :)
from setfit.
Hey @jrivd can you provide a code snippet / Colab that reproduces the error? This will help debug what exactly is going on :)
from setfit.
Hi @lewtun, thanks for your response. You can see the error in action here: https://colab.research.google.com/drive/10t9QmQEe7BHIQQ8XUmw1B37vPFRfORDK?usp=sharing
Many thanks!
from setfit.
Many thanks for your comments, @pdhall99 and @Mouhanedg56! I'll go over them carefully
from setfit.
Hey @pdhall99 , was this issue finally resolved? I am trying to load the ST models offline but still get the repo_name' or 'namespace/repo_name' error when using full path . i can only load models offline in my environment
When the model file is located in same directory still unable to load as below.
model = SetFitModel.from_pretrained("./all-MiniLM-L6-v2",model_head_file=None,local_files_only=True). i tried with multiple arguments but getting the error Repo id must use alphanumeric chars or '-', '_', '.', '--' and '..' are forbidden, '-' and '.' cannot start Thks
from setfit.
Hi @sfernandes-gim, this change is not yet merged.
from setfit.
Hi folks, we've just released a new version that include fixes to some of the above issues. For those still having troubles, could you please comment below with a code snippet for debugging? Thanks!
from setfit.
Hi @lewtun , trying to load from my local directory but always gives below error.Also tried with local_files_only=True option .Please advise
model = SetFitModel.from_pretrained("./all-MiniLM-L6-v2")
Error
HFValidationError: Repo id must use alphanumeric chars or '-', '', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96: './all-MiniLM-L6-v2'._
Tried below
odel = SetFitModel.from_pretrained("./Output/all-MiniLM-L6-v2",local_files_only=True,use_differentiable_head=True, head_params={"out_features": num_classes})
Error
HFValidationError: Repo id must be in the form 'repo_name' or 'namespace/repo_name': './Output/all-MiniLM-L6-v2'. Use repo_type
argument if needed.
from setfit.
Thanks @lewtun this works fine with the latest release
from setfit.
I had the same issue in the local machine (not colab). I was using mounted drive (pure storage).
Creating a symlink to a folder (saving directory) to the working directory (where the training is going on) solved the issue for me.
ln -s existing_source_file optional_symbolic_link
from setfit.
In the Colab this happens if you mount drive. For some reason mounted path is not recognized. Instead, try having model in
/content
. This should solve issue of missing path.
Not working event loading model from /content. Have you solve this issue from your side ? @bojanbabic
from setfit.
Related Issues (20)
- Can we use Setfit just for finetuning ST Embedding model to create embeddings HOT 2
- MultiGPU support or better intergration for loading models HOT 1
- i found a typo in docs HOT 1
- Methodological error in zero cost, zero time, zero shot notebook HOT 2
- Usage of deprecated `evaluation_strategy` in TrainingArguments HOT 1
- Data validation when using differentiable_head
- Can you please add an example with early stopping based on classification loss?
- how to optimize setfit inference
- exception:enum PyPreTokenizerTypeWrapper, while loading the fine-tuned model for evaluation HOT 7
- Regarding expanding the label column
- Setfit can't doing model prediction after training for MultiClass Classification with hf Trainer HOT 1
- Item taxonomy generation
- The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
- Possibility to monitor head training?
- Model checkpoints saved during the training are unusable
- Example from quick start fails with 'TrainingArguments' object has no attribute 'eval_strategy' HOT 8
- Clarification on end_to_end vs trainer.train_embeddings HOT 1
- Savely save & load SetFitModel with custom differentiable head
- Multiclass Training Error HOT 1
- setfit example does not work HOT 1
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 setfit.