Problems with hands-on labs on Deploying a Model for Inference at Production Scale course

The course material for Deploying a Model for Inference at Production Scale is outdated and does not work anymore with the models supplied by HF.
Tried to adapt the code to fix the model routing in HF, but there´s a dependency problem with python 3.8 which is too old for the new version of the HF library (via %pip install --upgrade transformers huggingface_hub)

If this is not solved, I would like a voucher back to get another course that I could finish properly.

import torch
from transformers import XLMRobertaForSequenceClassification, XLMRobertaTokenizer

from transformers import AutoTokenizer, AutoModelForSequenceClassification

R_tokenizer = AutoTokenizer.from_pretrained('joeddav/xlm-roberta-large-xnli')
# R_tokenizer = XLMRobertaTokenizer.from_pretrained('joeddav/xlm-roberta-large-xnli', token='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')
premise = "Jupiter's Biggest Moons Started as Tiny Grains of Hail"
hypothesis = 'This text is about space & cosmos'

input_ids = R_tokenizer.encode(premise, hypothesis, return_tensors='pt', 
                               max_length=256, padding='max_length')

mask = input_ids != 1
mask = mask.long()


class PyTorch_to_TorchScript(torch.nn.Module):
    def __init__(self):
        super(PyTorch_to_TorchScript, self).__init__()
        #self.model = XLMRobertaForSequenceClassification.from_pretrained('joeddav/xlm-roberta-large-xnli', token="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", return_dict=False)
        self.model = AutoModelForSequenceClassification.from_pretrained('joeddav/xlm-roberta-large-xnli')
    def forward(self, data, attention_mask=None):
        return self.model(data.cuda(), attention_mask.cuda())

pt_model = PyTorch_to_TorchScript().eval().cuda()
traced_script_module = torch.jit.trace(pt_model, (input_ids, mask))
traced_script_module.save('models/huggingface-model/1/model.pt')

outputs:

ImportError Traceback (most recent call last)
/opt/conda/lib/python3.8/site-packages/transformers/utils/import_utils.py in _get_module(self, module_name)
1777 try:
→ 1778 return importlib.import_module(“.” + module_name, self.name)
1779 except Exception as e:

/opt/conda/lib/python3.8/importlib/init.py in import_module(name, package)
126 level += 1
→ 127 return _bootstrap._gcd_import(name[level:], package, level)
128

/opt/conda/lib/python3.8/importlib/_bootstrap.py in _gcd_import(name, package, level)

/opt/conda/lib/python3.8/importlib/_bootstrap.py in find_and_load(name, import)

/opt/conda/lib/python3.8/importlib/_bootstrap.py in find_and_load_unlocked(name, import)

/opt/conda/lib/python3.8/importlib/_bootstrap.py in _load_unlocked(spec)

/opt/conda/lib/python3.8/importlib/_bootstrap_external.py in exec_module(self, module)

/opt/conda/lib/python3.8/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/opt/conda/lib/python3.8/site-packages/transformers/models/xlm_roberta/modeling_xlm_roberta.py in
42 )
—> 43 from …modeling_utils import PreTrainedModel
44 from …pytorch_utils import apply_chunking_to_forward, find_pruneable_heads_and_indices, prune_linear_layer

/opt/conda/lib/python3.8/site-packages/transformers/modeling_utils.py in
47 from .integrations import PeftAdapterMixin, deepspeed_config, is_deepspeed_zero3_enabled
—> 48 from .loss.loss_utils import LOSS_MAPPING
49 from .pytorch_utils import ( # noqa: F401

/opt/conda/lib/python3.8/site-packages/transformers/loss/loss_utils.py in
18
—> 19 from .loss_deformable_detr import DeformableDetrForObjectDetectionLoss, DeformableDetrForSegmentationLoss
20 from .loss_for_object_detection import ForObjectDetectionLoss, ForSegmentationLoss

/opt/conda/lib/python3.8/site-packages/transformers/loss/loss_deformable_detr.py in
3
----> 4 from ..image_transforms import center_to_corners_format
5 from ..utils import is_scipy_available

/opt/conda/lib/python3.8/site-packages/transformers/image_transforms.py in
21
—> 22 from .image_utils import (
23 ChannelDimension,

/opt/conda/lib/python3.8/site-packages/transformers/image_utils.py in
57 if is_torchvision_available():
—> 58 from torchvision.transforms import InterpolationMode
59

ImportError: cannot import name ‘InterpolationMode’ from ‘torchvision.transforms’ (/opt/conda/lib/python3.8/site-packages/torchvision/transforms/init.py)

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last)
in
1 import torch
----> 2 from transformers import XLMRobertaForSequenceClassification, XLMRobertaTokenizer
3
4 from transformers import AutoTokenizer, AutoModelForSequenceClassification
5

/opt/conda/lib/python3.8/importlib/_bootstrap.py in handle_fromlist(module, fromlist, import, recursive)

/opt/conda/lib/python3.8/site-packages/transformers/utils/import_utils.py in getattr(self, name)
1765 elif name in self._class_to_module.keys():
1766 module = self._get_module(self._class_to_module[name])
→ 1767 value = getattr(module, name)
1768 elif name in self._modules:
1769 value = self._get_module(name)

/opt/conda/lib/python3.8/site-packages/transformers/utils/import_utils.py in getattr(self, name)
1764 value = Placeholder
1765 elif name in self._class_to_module.keys():
→ 1766 module = self._get_module(self._class_to_module[name])
1767 value = getattr(module, name)
1768 elif name in self._modules:

/opt/conda/lib/python3.8/site-packages/transformers/utils/import_utils.py in _get_module(self, module_name)
1778 return importlib.import_module(“.” + module_name, self.name)
1779 except Exception as e:
→ 1780 raise RuntimeError(
1781 f"Failed to import {self.name}.{module_name} because of the following error (look up to see its"
1782 f" traceback):\n{e}"

RuntimeError: Failed to import transformers.models.xlm_roberta.modeling_xlm_roberta because of the following error (look up to see its traceback):
cannot import name ‘InterpolationMode’ from ‘torchvision.transforms’ (/opt/conda/lib/python3.8/site-packages/torchvision/transforms/init.py)

Let me ask someone in our DLI Labs and see what they say. Are you saying the course as it was written, is actually broken, or you were trying to modify the code to your own needs?

Yes. The issue was the routing to HF model database, transformers lib is know to deprecated quite often, and the version for the python runtime, which is also old, does not allow new routing functions, as I tried to modify to solve. One workaround to is update python version of the runtime, to make it compatible to the new lib, as the error that’s shown is about this incompatibility.

FYI, the code written is in the HF website, I am following the usage HF in the model website, click “Use this model” button to see.

Ok thanks, we are investigating and will update if needed. Thanks for your patience.

Hi. Any news about the issue? I´ve been asked to complete the training in a time frame by my company, and if it´s not possible, let me know, so I can change the course and receive the credits used for it in another.

Let me get an update for you asap. Sorry for the delay.

Our folks in DLI have identified the error and are working on it. In the meantime we want to issue you a refund voucher. Can you DM me with your email address so we can get you that voucher?

Thanks!
Eric

Hi Eric,

Sorry for the delay, the inbox is still half full lol.
Regarding the voucher you can send to my personal email, leonhardrocha@gmail.com. I am taking courses using that account because it’s easier to take the courses without overtime at work.

You may have noticed that I just finished the course on Generative Diffusion Models that I bought for myself using lenhardrocha@gmail.com.account, and would like to ask for reimbursement to be paid by my company. How can I get the receipt for that?. I would appreciate your help in this matter if possible.

Regards,

Leonardo

It didn’t email you a reciept? You should have received an email with that reimbursement code.

Hi,

Thank you for sending the promo code; I have successfully received it.

Regarding the reimbursement details, I apologize, but I seem to be having trouble locating the information in my emails. Would it be possible for you to kindly resend the reimbursement instructions or provide them again?

I apologize for any inconvenience this may cause.

Thank you for your understanding and assistance.

Best regards,

Leo

I’ve asked, I’ll let you know what I find out

It should have come to your email , if not, you’ll need to send an email to dli-help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.