Views
No views yet
1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4model_checkpoint = "apple/ane-distilbert-base-uncased-finetuned-sst-2-english"
5tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
6model = AutoModelForSequenceClassification.from_pretrained(
7 model_checkpoint, trust_remote_code=True, return_dict=False,
8)
9
10inputs = tokenizer(
11 ["The Neural Engine is really fast"],
12 return_tensors="pt",
13 max_length=128,
14 padding="max_length",
15)
16
17with torch.no_grad():
18 outputs = model(**inputs)1import coremltools as ct
2
3mlmodel = ct.models.MLModel("DistilBERT_fp16.mlpackage")
4
5inputs = tokenizer(
6 ["The Neural Engine is really fast"],
7 return_tensors="np",
8 max_length=128,
9 padding="max_length",
10)
11
12outputs_coreml = mlmodel.predict({
13 "input_ids": inputs["input_ids"].astype(np.int32),
14 "attention_mask": inputs["attention_mask"].astype(np.int32),
15})