tiberiu44 commited on
Commit
e4c92af
·
verified ·
1 Parent(s): e14cd69

Upload folder using huggingface_hub

Browse files
modeling_borg.py CHANGED
@@ -15,7 +15,10 @@ class BorgHFModel(PreTrainedModel):
15
 
16
  def __init__(self, config: BorgHFConfig):
17
  super().__init__(config)
18
- self.register_buffer("_pipeline_marker", torch.zeros(1))
 
 
 
19
  self.post_init()
20
 
21
  def forward(self, *args: Any, **kwargs: Any):
 
15
 
16
  def __init__(self, config: BorgHFConfig):
17
  super().__init__(config)
18
+ self.register_parameter(
19
+ "_pipeline_marker",
20
+ torch.nn.Parameter(torch.zeros(1), requires_grad=False),
21
+ )
22
  self.post_init()
23
 
24
  def forward(self, *args: Any, **kwargs: Any):
pipeline.py CHANGED
@@ -115,11 +115,13 @@ def _repository_path(model) -> Path:
115
  def _runtime_device(config, device) -> Any:
116
  import torch
117
 
118
- if device is not None:
119
- if isinstance(device, int):
120
- config.device = "cpu" if device < 0 else f"cuda:{device}"
121
- else:
122
- config.device = str(device)
 
 
123
  return torch.device(config.resolve_device())
124
 
125
 
 
115
  def _runtime_device(config, device) -> Any:
116
  import torch
117
 
118
+ if device is None:
119
+ # Checkpoints can record the training device; default to local hardware at inference.
120
+ config.device = "auto"
121
+ elif isinstance(device, int):
122
+ config.device = "cpu" if device < 0 else f"cuda:{device}"
123
+ else:
124
+ config.device = str(device)
125
  return torch.device(config.resolve_device())
126
 
127
 
src/pipeline/hf/modeling_borg.py CHANGED
@@ -15,7 +15,10 @@ class BorgHFModel(PreTrainedModel):
15
 
16
  def __init__(self, config: BorgHFConfig):
17
  super().__init__(config)
18
- self.register_buffer("_pipeline_marker", torch.zeros(1))
 
 
 
19
  self.post_init()
20
 
21
  def forward(self, *args: Any, **kwargs: Any):
 
15
 
16
  def __init__(self, config: BorgHFConfig):
17
  super().__init__(config)
18
+ self.register_parameter(
19
+ "_pipeline_marker",
20
+ torch.nn.Parameter(torch.zeros(1), requires_grad=False),
21
+ )
22
  self.post_init()
23
 
24
  def forward(self, *args: Any, **kwargs: Any):
src/pipeline/hf/pipeline.py CHANGED
@@ -115,11 +115,13 @@ def _repository_path(model) -> Path:
115
  def _runtime_device(config, device) -> Any:
116
  import torch
117
 
118
- if device is not None:
119
- if isinstance(device, int):
120
- config.device = "cpu" if device < 0 else f"cuda:{device}"
121
- else:
122
- config.device = str(device)
 
 
123
  return torch.device(config.resolve_device())
124
 
125
 
 
115
  def _runtime_device(config, device) -> Any:
116
  import torch
117
 
118
+ if device is None:
119
+ # Checkpoints can record the training device; default to local hardware at inference.
120
+ config.device = "auto"
121
+ elif isinstance(device, int):
122
+ config.device = "cpu" if device < 0 else f"cuda:{device}"
123
+ else:
124
+ config.device = str(device)
125
  return torch.device(config.resolve_device())
126
 
127