Instructions to use hf-internal-testing/remote_code_model_with_dots with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hf-internal-testing/remote_code_model_with_dots with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="hf-internal-testing/remote_code_model_with_dots", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/remote_code_model_with_dots", trust_remote_code=True) model = AutoModel.from_pretrained("hf-internal-testing/remote_code_model_with_dots", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 898 Bytes
6055811 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | """
Custom model with relative import to demonstrate the bug.
"""
from transformers import PreTrainedModel
from transformers.modeling_outputs import BaseModelOutput
import torch
import torch.nn as nn
# This relative import should cause the bug when the folder has a dot in the name
from .another_module import custom_function
class CustomModel(PreTrainedModel):
def __init__(self, config):
super().__init__(config)
self.embeddings = nn.Embedding(config.vocab_size, config.hidden_size)
self.layer = nn.Linear(config.hidden_size, config.hidden_size)
def forward(self, input_ids=None, **kwargs):
embeddings = self.embeddings(input_ids)
# Use the function from the relative import
output = custom_function(embeddings)
hidden_states = self.layer(output)
return BaseModelOutput(last_hidden_state=hidden_states)
|