Skip to content

LM layer: per-module LM, config merging, retry/backoff #69

@darinkishore

Description

@darinkishore

Context

DSPy Python has a 3-level LM resolution cascade:

  1. Call-time parameter (predictor(q="...", lm=other_lm))
  2. Per-module (predict.lm = my_lm)
  3. Global (dspy.configure(lm=...))

Plus lm.copy(**overrides) for creating variant LMs, and dspy.context(lm=...) for thread-local temporary switching.

dspy-rs currently has global-only LM via GLOBAL_SETTINGS.lm. No per-module assignment, no config merging, no context-style overrides, and no retry/backoff on transient failures.

What's needed

Per-module LM

  • Predict<S> and Module should support an optional .lm field
  • Resolution order: call param > self.lm > GLOBAL_SETTINGS.lm

Config merging / copy

  • LM::copy() or similar to create variant LMs with overridden params
  • Equivalent of DSPy's Predict.config + call-time kwargs merge

Retry / backoff

  • Configurable num_retries on LM
  • Exponential backoff for transient errors (network, rate limit, 5xx)
  • Non-transient errors (4xx except 429) fail immediately
  • Currently one-shot: any transient failure is terminal

Context-local LM

  • Something like dspy::context(lm) for temporary overrides (task-local or scope-based)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions