Skip to content

Float precision changes when loading JSON function-call data through datasets / pandas #10216

Description

@firefighter-eric

Checklist

  • I have searched existing issues, and this is a new bug report.

Bug Description

Hi ms-swift team,

I found a float precision issue when loading function-call training data.

The original JSONL contains values like:

{"value": 0.7}

but after ms-swift loads the data through datasets / pandas, it may become:

{"value": 0.7000000000000001}

This is problematic for Function Call SFT because the model learns the exact token sequence, so these two representations are different training targets.

It seems that the JSON data is parsed into floating-point values by pandas and then serialized again, introducing floating-point artifacts.

It would be helpful if function-call arguments could preserve their original JSON representation, or avoid unnecessary float conversion during dataset loading.

Thanks!

How to Reproduce

Prepare a Function Call training sample where the assistant calls a tool with a float argument:

{
  "messages": [
    {
      "role": "user",
      "content": "Set the zoom level to 0.7."
    },
    {
      "role": "assistant",
      "tool_calls": [
        {
          "type": "function",
          "function": {
            "name": "set_zoom",
            "arguments": "{\"zoom\": 0.7}"
          }
        }
      ]
    }
  ]
}

After loading the dataset with ms-swift, the assistant tool-call argument may become:

{
  "arguments": "{\"zoom\": 0.7000000000000001}"
}

检查清单

  • 我已经搜索过现有的 issues,确认这是一个新的 bug report。

Bug 描述

你好,ms-swift 团队,

我发现 Function Call 训练数据在加载过程中存在浮点精度变化的问题。

原始 JSONL 中的数据例如:

{"value": 0.7}

但 ms-swift 通过 datasets / pandas 加载后,可能会变成:

{"value": 0.7000000000000001}

这对于 Function Call SFT 会有影响,因为模型学习的是精确的 Token 序列,这两种表示实际上是不同的训练目标。

目前看起来是 JSON 数据经过 pandas 转换成浮点数后,再重新序列化时引入了浮点误差。

希望 Function Call arguments 能尽量保留原始 JSON 表示,或者避免数据加载阶段不必要的浮点类型转换。

谢谢!

如何复现

准备一条 Function Call 训练数据,其中 assistant 调用 Tool,并包含浮点参数:

{
  "messages": [
    {
      "role": "user",
      "content": "将变焦设置为 0.7。"
    },
    {
      "role": "assistant",
      "tool_calls": [
        {
          "type": "function",
          "function": {
            "name": "set_zoom",
            "arguments": "{\"zoom\": 0.7}"
          }
        }
      ]
    }
  ]
}

使用 ms-swift 加载数据后,assistant 的 Tool Call 参数可能变成:

{
  "arguments": "{\"zoom\": 0.7000000000000001}"
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions