Make changes on torch jit script after loading

Hi! I wonder if someone can make changes on jit code string parameter. Actually, I have received a trace file which contains cuda code, but I want to run this on cpu. So I wonder if I can change the code like that:

import torch
torch_script = torch.jit.load("somefile.ptc")
torch_script.code = torch_script.code.replace("cuda", "cpu")

This code produces the following error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "venv/lib/python3.9/site-packages/torch/jit/", line 590, in __setattr__
    return super(RecursiveScriptModule, self).__setattr__(attr, value)
  File "venv/lib/python3.9/site-packages/torch/jit/", line 310, in __setattr__
    return super(ScriptModule, self).__setattr__(attr, value)
  File "venv/lib/python3.9/site-packages/torch/nn/modules/", line 995, in __setattr__
    object.__setattr__(self, name, value)
AttributeError: can't set attribute

The purpose is to avoid rewriting the torch script code and export it again. Is that feasible? Thanks!