-
Notifications
You must be signed in to change notification settings - Fork 892
Expand file tree
/
Copy pathinputs.py
More file actions
50 lines (42 loc) · 1.28 KB
/
Copy pathinputs.py
File metadata and controls
50 lines (42 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from typing import TYPE_CHECKING
import torch
from .pack import PackedTensors
if TYPE_CHECKING:
from .. import dev, types
class TrainInputs(PackedTensors):
"""Training inputs with config attached."""
config: "types.TrainConfig"
_config: "dev.TrainConfig"
return_new_logprobs: bool
def create_train_inputs(
packed_tensors: PackedTensors,
offset: int,
config: "types.TrainConfig",
_config: "dev.TrainConfig",
warmup: bool,
) -> TrainInputs:
"""Create TrainInputs for a single batch offset."""
return TrainInputs(
**{
k: (
v[offset : offset + 1, :1024]
if warmup and v.dim() > 1
else v[offset : offset + 1]
)
for k, v in packed_tensors.items()
if isinstance(v, torch.Tensor)
},
pixel_values=(
[None] if warmup else packed_tensors["pixel_values"][offset : offset + 1]
),
image_grid_thw=(
[None] if warmup else packed_tensors["image_grid_thw"][offset : offset + 1]
),
config=(
config.model_copy(update={"lr": 1e-9, "beta": 0.0, "kl_coef": 0.0})
if warmup
else config
),
_config=_config,
return_new_logprobs=False,
)