feat : 数据流水拼接策略支持 position_ids 预计算
- OutputConfig.position_ids_mode 三种模式控制边界策略 - pipeline._flush() 按配置生成扁平 position_ids 数组 - SFTDataset 在 __getitem__ 中返回 position_ids - SFTStrategy 将 position_ids 传入 model.forward()
This commit is contained in:
@@ -180,14 +180,15 @@ class SFTStrategy(BaseStrategy):
|
||||
|
||||
def compute_loss(self, batch: Dict[str, Tensor]) -> Tensor:
|
||||
batch = move_to_device(batch, self.device)
|
||||
input_ids, target_ids, loss_mask = (
|
||||
input_ids, target_ids, position_ids, loss_mask = (
|
||||
batch["input_ids"],
|
||||
batch["target_ids"],
|
||||
batch["position_ids"],
|
||||
batch["loss_mask"],
|
||||
)
|
||||
|
||||
ignore_index = -100
|
||||
logits = self.model(input_ids=input_ids)["logits"]
|
||||
logits = self.model(input_ids=input_ids, position_ids=position_ids)["logits"]
|
||||
target_ids = target_ids.masked_fill(loss_mask == 0, ignore_index)
|
||||
|
||||
loss = F.cross_entropy(
|
||||
|
||||
Reference in New Issue
Block a user