Skip to content

Commit e7422bd

Browse files
committed
fix(dataset): align validation rules with platform data format spec
- Support content array format [{text/image/video}] alongside legacy string - Add tool role support with tool_calls structure and tool_call_id validation - Add thinking tag placement check (only in last assistant message) - Add OpenAI migration guards: warn on unsupported name/weight fields - Add loss_weight range validation (0.0–1.0) - Fix size limits: SFT/DPO 200MB, CPT 300MB, media ZIP 2GB - Enforce data.jsonl at ZIP root (reject nested wrapping folders) - Add ZIP filename constraints: charset [a-zA-Z0-9_-], length ≤120, uniqueness - Add .tif to accepted image extensions - Add DPO_LAST_MSG_NOT_USER warning when messages don't end with user role - CPT profile now uses dedicated 300MB cap instead of shared default - Expand unit tests from 19 to 45 covering all new validation paths
1 parent 9749a11 commit e7422bd

11 files changed

Lines changed: 918 additions & 69 deletions

File tree

packages/commands/src/commands/dataset/upload.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
parseDatasetSchemaFlag,
66
formatIssue,
77
MAX_DATASET_BYTES,
8+
MAX_CPT_BYTES,
89
MAX_MEDIA_ZIP_BYTES,
910
BailianError,
1011
ExitCode,
@@ -16,7 +17,7 @@ const UPLOAD_FLAGS = {
1617
file: {
1718
type: "string",
1819
valueHint: "<path>",
19-
description: "Local dataset file (.jsonl or .zip; ≤300MB text, ≤1GB image)",
20+
description: "Local dataset file (.jsonl or .zip; ≤200MB SFT/DPO, ≤300MB CPT, ≤2GB media zip)",
2021
required: true,
2122
},
2223
purpose: {
@@ -57,13 +58,14 @@ export default defineCommand({
5758
],
5859
notes: [
5960
"Supports .jsonl (text) and .zip (audio/image archives with a data.jsonl",
60-
"manifest). Five record schemas are recognized: chatml = {messages:[...]}",
61+
"manifest). Six record schemas are recognized: chatml = {messages:[...]}",
6162
'(SFT); dpo = {messages:[...], chosen, rejected}; cpt = {text:"..."}',
6263
'(continual pre-training, raw text); tts = {wav_fn:"train/xxx.wav",',
6364
'text:"..."} (audio fine-tuning); image = {img_path:"..."} (image',
64-
"generation). With no --schema, a record carrying wav_fn is validated as",
65-
"TTS, img_path as image, chosen/rejected as DPO, text (no messages) as CPT,",
66-
"otherwise ChatML. Upload cap: 300MB text, 1GB image. Upload uses the",
65+
"generation); video = {first_frame_path:...} (video generation). With no",
66+
"--schema, a record carrying wav_fn is validated as TTS, img_path as image,",
67+
"chosen/rejected as DPO, text (no messages) as CPT, otherwise ChatML.",
68+
"Upload cap: 200MB SFT/DPO text, 300MB CPT, 2GB media zip. Upload uses the",
6769
"OpenAI-compatible /compatible-mode/v1/files endpoint so the purpose tag is",
6870
"persisted (the DashScope-native /api/v1/files drops it).",
6971
],
@@ -72,11 +74,15 @@ export default defineCommand({
7274
const filePath = flags.file;
7375
const purpose = flags.purpose || "fine-tune";
7476
const schema = parseDatasetSchemaFlag(flags.schema);
75-
// Image and video schemas allow larger ZIPs (1 GB vs 300 MB for text).
77+
// Size caps differ per training type: SFT/DPO 200MB, CPT 300MB, media ZIP 2GB.
7678
const isMediaSchema = schema === "image" || schema === "video";
79+
const maxBytes = isMediaSchema
80+
? MAX_MEDIA_ZIP_BYTES
81+
: schema === "cpt"
82+
? MAX_CPT_BYTES
83+
: MAX_DATASET_BYTES;
7784

7885
if (!flags.noValidate) {
79-
const maxBytes = isMediaSchema ? MAX_MEDIA_ZIP_BYTES : MAX_DATASET_BYTES;
8086
const result = await validateDataset(filePath, {
8187
fullValidate: flags.fullValidate,
8288
schema,
@@ -116,7 +122,7 @@ export default defineCommand({
116122
action: "dataset.upload",
117123
file: filePath,
118124
purpose,
119-
max_bytes: isMediaSchema ? MAX_MEDIA_ZIP_BYTES : MAX_DATASET_BYTES,
125+
max_bytes: maxBytes,
120126
validate: !flags.noValidate,
121127
schema: schema ?? "auto",
122128
},

packages/core/src/dataset/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {
77
registerValidator,
88
listSupportedFormats,
99
MAX_DATASET_BYTES,
10+
MAX_CPT_BYTES,
1011
MAX_MEDIA_ZIP_BYTES,
1112
parseDatasetSchemaFlag,
1213
formatIssue,

packages/core/src/dataset/validate/common.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@ import { ExitCode } from "../../errors/codes.ts";
1212
import type { DatasetSchema, ValidationIssue, ValidationStats } from "./types.ts";
1313

1414
/**
15-
* The platform caps dataset uploads at 300MB per file. `bl dataset upload`
16-
* enforces this client-side so users learn early. Update if the platform
17-
* raises the cap or differentiates per-purpose limits.
15+
* The platform caps SFT/DPO text dataset uploads at 200MB per file.
16+
* `bl dataset upload` enforces this client-side so users learn early.
17+
* CPT uses 300MB (see MAX_CPT_BYTES); API general upload is also 300MB.
1818
*/
19-
export const MAX_DATASET_BYTES = 300 * 1024 * 1024;
19+
export const MAX_DATASET_BYTES = 200 * 1024 * 1024;
2020

2121
/**
22-
* Image / video ZIP size cap — 1 GB per the platform docs (vs 300 MB for
23-
* text / audio). Used by `bl dataset upload` for media schemas and by the
24-
* `sft-lora` training profile for image / video validation.
22+
* CPT text dataset size cap — 300 MB per the platform docs.
23+
* CPT requires at least 50M tokens; larger files are expected.
2524
*/
26-
export const MAX_MEDIA_ZIP_BYTES = 1024 * 1024 * 1024;
25+
export const MAX_CPT_BYTES = 300 * 1024 * 1024;
26+
27+
/**
28+
* Image / video ZIP size cap — 2 GB per the platform docs. Used by
29+
* `bl dataset upload` for media schemas and by the `sft-lora` training
30+
* profile for image / video validation.
31+
*/
32+
export const MAX_MEDIA_ZIP_BYTES = 2 * 1024 * 1024 * 1024;
2733

2834
export interface PreflightResult {
2935
bytes: number;

packages/core/src/dataset/validate/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ export {
44
registerValidator,
55
listSupportedFormats,
66
} from "./registry.ts";
7-
export { MAX_DATASET_BYTES, MAX_MEDIA_ZIP_BYTES, parseDatasetSchemaFlag } from "./common.ts";
7+
export {
8+
MAX_DATASET_BYTES,
9+
MAX_CPT_BYTES,
10+
MAX_MEDIA_ZIP_BYTES,
11+
parseDatasetSchemaFlag,
12+
} from "./common.ts";
813
export { formatIssue } from "./format.ts";
914
export type {
1015
ValidatorSpec,

0 commit comments

Comments
 (0)