Run this model with HF Jobs
Run m3/onnx-base on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/m3/onnx-base. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/m3/onnx-base on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use m3/onnx-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use m3/onnx-base with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("m3/onnx-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
chore: add dummpy model
Browse filesFiles changed (3)
- .gitignore+1
- model.onnxDeleted-3
- src/empty.py → src/dummy.pyRenamed+30-39
1./custom_model12./custom_model.idea
123version https://git-lfs.github.com/spec/v1oid sha256:b3a7a3939f0d8c3ba7d20dd08fc5caf88da2477a64a4d083bbff7bac346935b1size 25112345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505110 unmodified lines626364656667686970717273747576777879808182838485868788899091from transformers import PretrainedConfig, PreTrainedModel, AutoConfig, AutoModelfrom transformers.pipelines import PIPELINE_REGISTRYfrom huggingface_hub import hf_hub_downloadimport onnxruntime as ortimport torchimport os# 1. register AutoConfigclass ONNXBaseConfig(PretrainedConfig):model_type = 'onnx-base'AutoConfig.register('onnx-base', ONNXBaseConfig)# 2. register AutoModelclass ONNXBaseModel(PreTrainedModel):config_class = ONNXBaseConfigdef __init__(self, config):super().__init__(config)def forward(self, input=None, **kwargs):return {}@classmethoddef from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):config = AutoConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)return cls(config)@propertydef device(self):device = 'cuda' if torch.cuda.is_available() else 'cpu'return torch.device(device)AutoModel.register(ONNXBaseConfig, ONNXBaseModel)# 2. register Pipelinefrom transformers.pipelines import Pipelineclass ONNXBasePipeline(Pipeline):def __init__(self, model, **kwargs):super().__init__(model=model, **kwargs)self.device_id = kwargs['device']model_path = hf_hub_download(repo_id='m3/onnx-base', filename='model.onnx', local_files_only=True)self.session = ort.InferenceSession(model_path)def __call__(self,10 unmodified linesreturn {'input': input}def _forward(self, model_input):input = model_input['input']['inputs']outs = self.session.run(None, {'input': input})return inputdef postprocess(self, model_outputs):return model_outputsPIPELINE_REGISTRY.register_pipeline(task='onnx-base',pipeline_class=ONNXBasePipeline,pt_model=ONNXBaseModel,default={"pt": ("m3/onnx-base", "a5e4e8f")},)# 4. show how to usefrom transformers import pipelinecfg = ONNXBaseConfig(model_path='model.onnx',id2label={0: 'label_0', 1: 'label_1'},label2id={0: 'label_1', 1: 'label_0'})pipe = pipeline(task='onnx-base',batch_size=10,device='cuda',)12345678910111213141516171819202122232425262728293031323334353637383940414243444510 unmodified lines565758596061626364656667686970717273747576777879808182from transformers import PretrainedConfig, PreTrainedModel, AutoConfig, AutoModelfrom transformers.pipelines import PIPELINE_REGISTRYfrom huggingface_hub import hf_hub_downloadimport torchimport os# 1. create auto configclass DummyConfig(PretrainedConfig):model_type = 'dummy'# 2. create modelclass DummyModel(PreTrainedModel):config_class = DummyConfigdef __init__(self, model: str, model_path: str):is_local = os.path.isdir(model)if is_local:base_path = modelmodel_path = os.path.join(base_path, model_path)else:model_path = hf_hub_download(repo_id=model, filename=model_path)base_path = os.path.dirname(model_path)config = DummyConfig(base_path=base_path, model_path=model_path)super().__init__(config)def forward(self, input=None, **kwargs):return {}@propertydef device(self):device = 'cuda' if torch.cuda.is_available() else 'cpu'return torch.device(device)# 2. register Pipelinefrom transformers.pipelines import Pipelineclass DummyPipeline(Pipeline):def __init__(self, model, **kwargs):super().__init__(model=model, **kwargs)self.device_id = kwargs['device']self.model_path = self.model.config.model_pathself.base_path = self.model.config.base_pathdef __call__(self,10 unmodified linesreturn {'input': input}def _forward(self, model_input):return {'data': 'dummy','device_id': self.device_id,'base_path': self.base_path,'model_path': self.model_path}def postprocess(self, model_outputs):return model_outputsPIPELINE_REGISTRY.register_pipeline(task='dummy-task',pipeline_class=DummyPipeline,pt_model=DummyModel,)# 4. show how to usefrom transformers import pipelinepipe = pipeline(model=DummyModel("Ultralytics/YOLOv8", 'yolov8m.pt'),task='dummy-task',batch_size=10,device='cuda',)
.gitignore+1
model.onnxDeleted-3
src/empty.py → src/dummy.pyRenamed+30-39