LegoFlow

BlocksTrainerUsage

Configuration Guide

Trainer config controls data selection, conversion, model choice, training hyperparameters, infrastructure, and experiment logging. Most runs only need a few runtime_info.input fields. Leave meta_info, repository pins, environment paths, and output declarations alone unless you are changing the block contract itself.

Common fields

AreaEdit whenMain fields
Data sourceYou train from Hugging Face LF data, local LF data, or raw Harbor jobs.source.type, hf_hub_url, lf_path, job_dir
ModelYou switch the base model or local checkpoint.model.model_name_or_path, trust_remote_code
Training scaleYou tune context length, samples, batch size, learning rate, or epochs.training.cutoff_len, max_samples, learning_rate, num_train_epochs
InfrastructureYou move between one GPU and a multi-GPU node.infrastructure.n_gpus_per_node, training.deepspeed
Remote machineYou want training to run on a GPU server instead of the current host.meta_info.resources.ip, user, pwd, directory
Experiment trackingYou want W&B or Hugging Face access.experiment.*, credentials.*

An example reference

Start with the released LF dataset and the default Qwen3.5 base model. This is the simplest path because Trainer can skip Harbor trajectory conversion and go straight to LLaMA-Factory SFT.

blocks/trainer/config.yaml
runtime_info:  input:    source:      type: hf_lf      hf_hub_url: Lego-X/samples_for_llama_factory_sft      hf_file_name: jierun_glm52_openswe_mirror_score4_proto_oh_sdk_512_for_qwen3_5.json      hf_split: train    conversion:      max_instances: 0      data_name: glm52_openswe_mirror_score4_proto_oh_sdk_512_qwen3_5    model:      model_name_or_path: Qwen/Qwen3.5-35B-A3B-Base      trust_remote_code: true    training:      stage: sft      finetuning_type: full      template: qwen3_5      cutoff_len: 131072      max_samples: 1000000      output_dir: qwen3_5_35b_a3b_base_glm52_openswe_mirror_score4_proto_oh_sdk_512_gbs64pbs1acc8_lr5e-5_epo3      per_device_train_batch_size: 1      gradient_accumulation_steps: 8      learning_rate: 5.0e-5      num_train_epochs: 3.0      bf16: true      flash_attn: fa2    infrastructure:      n_gpus_per_node: 8

Use /trainer:check after editing. It checks data paths, model settings, conversion dependencies, GPU configuration, credentials, and training output paths before /trainer:run starts a costly job.

Configuration breakdown

Remote execution

Trainer runs locally by default, but training often belongs on a GPU server. Configure meta_info.resources when the block skill should log into a remote machine and run the Trainer workflow there.

blocks/trainer/config.yaml
meta_info:  resources:    ip: 203.0.113.20              # local = current machine; otherwise SSH target    user: ubuntu               # add this field if your remote setup needs it    pwd: null                  # prefer SSH keys or your private secret channel    directory: /home/ubuntu/LegoFlow/blocks/trainer    public_storage: null

The remote directory should point at the Trainer block checkout on the GPU server. Keep runtime_info.input.infrastructure.n_gpus_per_node aligned with that server, not with your laptop.

Data source

Trainer can read data in three modes. Choose exactly one source type for the run.

  • From a Hugging Face LF dataset:
blocks/trainer/config.yaml
runtime_info:  input:    source:      type: hf_lf      hf_hub_url: Lego-X/samples_for_llama_factory_sft      hf_file_name: jierun_glm52_openswe_mirror_score4_proto_oh_sdk_512_for_qwen3_5.json      hf_split: train
  • From a local LF file produced by Tracer:
blocks/trainer/config.yaml
runtime_info:  input:    source:      type: local_lf      lf_path: ../tracer/artifacts/sft_data/<job>/lf.json
  • From a raw Harbor job directory:
blocks/trainer/config.yaml
runtime_info:  input:    source:      type: harbor_job      scaffold: openhands-sdk      job_dir: ../tracer/artifacts/jobs/<job>    conversion:      max_instances: 0      exclude_repos_file: scripts/excluded_repos.txt      data_name: my_converted_dataset

Use local_lf when Tracer has already converted trajectories. Use harbor_job only when Trainer should run conversion itself.

Model and Template

The model and template must agree. For Qwen3.5, keep the current qwen3_5 template and long context settings.

blocks/trainer/config.yaml
runtime_info:  input:    model:      model_name_or_path: Qwen/Qwen3.5-35B-A3B-Base      trust_remote_code: true    training:      template: qwen3_5      cutoff_len: 131072      rope_scaling: null

Smoke run

Use a small sample cap and a separate output directory when checking a new data source or training node.

blocks/trainer/config.yaml
runtime_info:  input:    training:      max_samples: 32      output_dir: smoke-qwen3_5-sft      per_device_train_batch_size: 1      gradient_accumulation_steps: 1      num_train_epochs: 1.0      save_steps: 20    infrastructure:      n_gpus_per_node: 1

Production training

For production, keep the output directory unique and match the GPU count to the node.

blocks/trainer/config.yaml
runtime_info:  input:    training:      max_samples: 1000000      per_device_train_batch_size: 1      gradient_accumulation_steps: 8      learning_rate: 5.0e-5      num_train_epochs: 3.0      save_steps: 200      bf16: true      flash_attn: fa2    infrastructure:      n_gpus_per_node: 8

Handoff with neighboring blocks

Trainer usually receives converted LF data from Tracer and produces a checkpoint that Evaluator can serve and benchmark.

Receive Tracer data

The most common handoff is local_lf: Tracer writes artifacts/sft_data/<job>/lf.json, and Trainer reads that file directly.

blocks/trainer/config.yaml
runtime_info:  input:    source:      type: local_lf      lf_path: ../tracer/artifacts/sft_data/<job>/lf.json

If you want Trainer to consume raw Harbor jobs instead, keep the dependency contract and set source.type: harbor_job.

blocks/trainer/config.yaml
meta_info:  dependencies:    from:      source.job_dir:        from: tracer.output.raw_trajectories_dir        when: {source.type: harbor_job}runtime_info:  input:    source:      type: harbor_job      scaffold: openhands-sdk      job_dir: ../tracer/artifacts/jobs/<job>

Produce Evaluator checkpoints

After training, use the final checkpoint path as Evaluator's local model input.

blocks/evaluator/config.yaml
runtime_info:  input:    local_model_serving:      model_path: ../trainer/artifacts/<training-output-dir>      model_name: Qwen3.5-35B-A3B

Field reference

FieldRequired?DefaultWhen to change
source.typeYeshf_lfChoose hf_lf, local_lf, or harbor_job for the current run.
source.hf_hub_urlFor hf_lfreleased datasetChange when training from another Hub dataset.
source.hf_file_nameFor file-based hf_lfreleased JSONChange when the dataset repo contains multiple LF files.
source.lf_pathFor local_lfTracer LF pathPoint to a real lf.json from Tracer.
source.job_dirFor harbor_jobTracer jobs pathPoint to a real Harbor job directory.
source.scaffoldFor harbor_jobopenhands-sdkMust match the scaffold that produced the trajectories.
conversion.max_instancesNo0Use a positive number for subsampling; 0 means all samples.
conversion.data_nameYesreleased dataset nameChange for each converted dataset profile.
model.model_name_or_pathYesQwen/Qwen3.5-35B-A3B-BaseChange the base model or local checkpoint.
training.templateYesqwen3_5Must match the model family.
training.cutoff_lenYes131072Lower for memory checks; keep long for long trajectories.
training.output_dirYesrun nameChange for every important run to avoid overwriting outputs.
training.learning_rateYes5.0e-5Tune for new data/model settings.
infrastructure.n_gpus_per_nodeYes8Must match the training node.
credentials.*No""Prefer $HF_TOKEN and $WANDB_API_KEY; never commit secrets.
meta_info.resources.ipNolocalSet a host/IP when Trainer should run on a remote GPU server.
meta_info.resources.userFor remoteadd if neededSSH user for the remote server.
meta_info.resources.directoryFor remotenullTrainer block working directory on the remote server.
meta_info.resources.public_storageNonullOptional public artifact location for dashboards or sharing.

Complete config.yaml

Use this as the complete reference after you understand the few fields above.

blocks/trainer/config.yaml
meta_info:  name: trainer  label: "Trainer"  description: Trainer block — SFT training pipeline for SWE-bench coding models. Converts raw agent trajectories from multiple scaffolds into LLaMA-Factory sharegpt format, then trains models via LLaMA-Factory + DeepSpeed (ZeRO-3).  parent: legoflow  blocks: {}  dependencies:    from:      source.job_dir:        from: tracer.output.raw_trajectories_dir        when: {source.type: harbor_job}    to: {}   # nothing currently declares a dependency on trainer's outputs  resources:    ip: local    pwd: null    directory: null    public_storage: null  repositories:    llama_factory:      url: https://github.com/LegoX/LLaMA-Factory.git      branch: main      commit: 6e23fa19f485d86d0e5666ce3a9fdfdebb43c050      path: repos/LLaMA-Factory      readonly: true    swe_data_process:      url: https://github.com/LegoX/swe_data_process.git      branch: main      commit: dda92c581a0c0eaba74bb469d92ddda767e5f1b3      path: repos/swe_data_process      readonly: true  environment:    sft_uv: artifacts/env/lf    python_version: "3.12"    packages:      - repos/LLaMA-Factory      - repos/swe_data_processruntime_info:  input:     source:      type: hf_lf                 # harbor_job | hf_lf | local_lf      scaffold: openhands-sdk     # harbor_job only: openhands-sdk | claude-code | open-code | terminus2      job_dir: ../tracer/artifacts/jobs/<job>  # harbor_job only: replace <job> with a real Tracer job      hf_hub_url: "Lego-X/samples_for_llama_factory_sft"      hf_file_name: "jierun_glm52_openswe_mirror_score4_proto_oh_sdk_512_for_qwen3_5.json"  # empty = full dataset config      hf_subset: ""               # ignored when hf_file_name is set      hf_split: "train"      lf_path: ../tracer/artifacts/sft_data/<job>/lf.json  # local_lf only: replace <job> with a converted Tracer job    conversion:                   # harbor_job only; for hf_lf/local_lf just data_name + max_instances apply      max_instances: 0            # 0 = all samples; >0 = random subsample via num_samples      exclude_repos_file: scripts/excluded_repos.txt      data_name: "glm52_openswe_mirror_score4_proto_oh_sdk_512_qwen3_5"    dataset:      name: ""                    # auto-derived from conversion.data_name    model:      model_name_or_path: Qwen/Qwen3.5-35B-A3B-Base      trust_remote_code: true    training:      stage: sft      finetuning_type: full      deepspeed: scripts/deepspeed/ds_z3_config.json      template: qwen3_5      cutoff_len: 131072      rope_scaling: null          # Qwen3.5 supports 128K natively      max_samples: 1000000      preprocessing_num_workers: 16      dataloader_num_workers: 4      output_dir: "qwen3_5_35b_a3b_base_glm52_openswe_mirror_score4_proto_oh_sdk_512_gbs64pbs1acc8_lr5e-5_epo3"      logging_steps: 1      save_strategy: steps      save_steps: 200      overwrite_output_dir: false # explicit env override required to replace an existing run      save_only_model: true      resume_from_checkpoint: null      per_device_train_batch_size: 1      gradient_accumulation_steps: 8      learning_rate: 5.0e-5      weight_decay: 0.01      max_grad_norm: 1.0      num_train_epochs: 3.0      lr_scheduler_type: cosine      warmup_ratio: 0.1      bf16: true      ddp_timeout: 180000000      enable_liger_kernel: true      use_unsloth_gc: true      flash_attn: fa2    infrastructure:      n_gpus_per_node: 8    experiment:      run_name: ""                # "" = auto-derived      wandb_mode: offline      wandb_run_id: ""            # "" = auto-assigned    credentials:      wandb_api_key: ""           # via $WANDB_API_KEY      hf_token: ""                # via $HF_TOKEN; needed only for private hf_lf datasets  output:    checkpoint_path:      description: Path to the latest trained model checkpoint      value: null    artifacts:      train_results: null      train_loss_plot: null      training_log: null    training_curves:      description: WandB run id with loss, learning rate, and token metrics      value: null    training_metrics:      description: Final training metrics from LLaMA-Factory      value: null

On this page