FFFF Standardize -force_f32 flag across examples by janpfeifer · Pull Request #82 · gomlx/go-huggingface · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
- Added native half-precision (`Float16` / `BFloat16`) support for unquantized half-precision GGUF models in `ggufDTypes()`, `loadStoreGGUF`, `loadSplitGGUFQKV`, and `CreateGoMLXModel`: preserves half-precision weights and split QKV tensors natively while configuring `tm.WithNormDType(normDType)` when GGUF normalization parameters are `Float32` (as in llama.cpp `F16`/`BF16` exports); quantized GGUFs continue to use `Float32` with `QuantGGML` weights.
- Added `Model.WithForceFloat32(force bool) *Model` and `Model.ForceFloat32() bool` to force `Float32` weights and execution (converting `Float16`/`BFloat16` tensors on load) for both GGUF and Safetensors models on backends without half-precision support.
- Promoted `Float16`/`BFloat16` hidden states and embeddings to `Float32` inside `normalizeEmbeddings` and `ApplySentencePooling` (`PoolingModeMeanTokens`) before squaring/reducing/`1e-12` epsilon clamping, casting back to the input dtype.
- `examples/msmarco/benchmark_embed`:
- Added `-force_f32` flag to force `Float32` execution via `Model.WithForceFloat32`.
- `examples/msmarco/benchmark_embed`, `examples/timestral`:
- Added `-force_f32` flag to `examples/msmarco/benchmark_embed` to force `Float32` weights and execution via `Model.WithForceFloat32`.
- Renamed `examples/timestral`'s `-force_float32` flag to `-force_f32` for consistency across examples.

- 2026/11/13:
- `tokenizers/bucket`, `examples/msmarco/benchmark_embed`:
Expand Down
6 changes: 3 additions & 3 deletions examples/msmarco/benchmark_embed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func main() {
klog.Fatalf("Failed to parse -set settings: %+v", err)
}

fmt.Printf("- Model %q, bucket %d, parallel embedders %d, dynamic shapes %t, warmup %t, shapes %t\n",
*flagModel, *flagBucketBudget, *flagParallelEmbedders, *flagDynamic, *flagWarmup, *flagShapes)
fmt.Printf("- Model %q, bucket %d, parallel embedders %d, dynamic shapes %t, warmup %t, shapes %t, force_f32 %t\n",
*flagModel, *flagBucketBudget, *flagParallelEmbedders, *flagDynamic, *flagWarmup, *flagShapes, *flagForceFloat32)
if len(paramsSet) > 0 {
fmt.Printf("- Modified settings:\n%s\n", commandline.SprintModifiedSettings(store, paramsSet))
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func main() {
return m, nil
})
if hfModel.IsGGUF() {
fmt.Printf("- GGUF file: %s (approx_gelu=%t, force_f32=%t)\n", hfModel.GGUFFile(), *flagApproxGelu, *flagForceFloat32)
fmt.Printf("- GGUF file: %s (approx_gelu=%t)\n", hfModel.GGUFFile(), *flagApproxGelu)
}

tokenizer := mustRunWithElapsedTime("Loading tokenizer", func() (tokenizers.Tokenizer, error) {
Expand Down
4 changes: 2 additions & 2 deletions examples/timestral/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
horizonSteps := flag.Int("horizon-steps", 864, "Number of horizon steps (default: 72 hours at 5-min intervals)")
backendConfig := flag.String("backend", "go", "GoMLX backend config")
useMMap := flag.Bool("mmap", safetensors.DefaultUseMMap(), "Use memory-mapped files (mmap) when loading weights")
forceFloat32 := flag.Bool("force_float32", false, "Force Float32 instead of Float64 for internal running statistics")
forceFloat32 := flag.Bool("force_f32", false, "Force Float32 instead of Float64 for internal running statistics")
runs := flag.Int("runs", 5, "Timed runs after the first (warm-up) one")
flag.Parse()

Expand Down Expand Up @@ -76,7 +76,7 @@ func main() {
store := mlmodel.NewStore()
must(tmModel.LoadStore(backend, store))

fmt.Printf("%s: context %d, horizon %d, %d quantiles, batch %d, backend %q, mmap %v, force_float32 %v, GOMAXPROCS %d\n",
fmt.Printf("%s: context %d, horizon %d, %d quantiles, batch %d, backend %q, mmap %v, force_f32 %v, GOMAXPROCS %d\n",
*modelID, *contextSteps, *horizonSteps, numQuantiles, batch, *backendConfig, tmModel.UseMMap(), tmModel.ForceFloat32(), runtime.GOMAXPROCS(0))

exec := must1(mlmodel.NewExec(backend, store, func(scope *mlmodel.Scope, x *graph.Node) *graph.Node {
Expand Down
2 changes: 1 addition & 1 deletion models/timestral/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ With `graph.CumMax` added (Section 3):

### 7.2. Float64 vs Float32 in Welford Causal Statistics (`scaler.go`)
- In Python's `compute_causal_statistics` and `advancing_block_frames`, Welford running sums (`cum_w`, `cum_x`, `m2`) are accumulated in `float64` (`dtypes.Float64`) to prevent catastrophic cancellation when a time series has a large constant offset (e.g. $10^6 \pm 1$) over $32,768$ steps, and then cast back to `dtypes.Float32`.
- Backends that do not support `dtypes.Float64` (such as Apple Metal / `mps`) are automatically detected by `Model`, which logs a warning and falls back to `dtypes.Float32` (with `float32Tiny = 2^-126` in `welfordCombine`). Callers can also explicitly set `tmModel.WithForceFloat32(true)` (or pass `-force_float32` in `./examples/timestral`) to force `Float32` statistics and silence the warning.
- Backends that do not support `dtypes.Float64` (such as Apple Metal / `mps`) are automatically detected by `Model`, which logs a warning and falls back to `dtypes.Float32` (with `float32Tiny = 2^-126` in `welfordCombine`). Callers can also explicitly set `tmModel.WithForceFloat32(true)` (or pass `-force_f32` in `./examples/timestral`) to force `Float32` statistics and silence the warning.
- In `advancing_block_frames`, the context patch moments are reduced per patch (`[R, L, P] -> [R, L]`), combined via `cumulativeWelford` ($\lceil \log_2 L \rceil$ steps over patch count $L$, e.g. 9 steps for $L = 378$), and then unrolled `for h := range nPred` (at most 32 iterations) to fold each predicted median patch into the Welford state.

### 7.3. Partial RoPE with Per-Row Anchored Positions (`layers.go`)
Expand Down
Loading
0