TensorTonic
Study Plans
Study Plan
Extrapolate Data-Mixture Scaling Curves
Scaling LawsLanguage ModelsProbability and Statistics
Hard

Compare named training-data mixtures by fitting a scaling curve to each row of observed sizes and losses:

Lk(D)=Ek+AkD−αk.L_k(D)=E_k+A_kD^{-\alpha_k}.Lk​(D)=Ek​+Ak​D−αk​.

Here, kkk identifies a mixture, DDD is its data size, Lk(D)L_k(D)Lk​(D) is predicted loss, EkE_kEk​ is the loss floor, AkA_kAk​ is a positive coefficient, and αk\alpha_kαk​ is a positive decay exponent. For each candidate floor below every observed loss in that row, the fit is unweighted least squares in natural-log space:

log⁡(Lk,i−Ek)=ak+bklog⁡Dk,i.\log(L_{k,i}-E_k)=a_k+b_k\log D_{k,i}.log(Lk,i​−Ek​)=ak​+bk​logDk,i​.

Index iii identifies an observation; Dk,iD_{k,i}Dk,i​ and Lk,iL_{k,i}Lk,i​ are its size and loss. The fitted intercept is ak=log⁡Aka_k=\log A_kak​=logAk​ and slope is bk=−αkb_k=-\alpha_kbk​=−αk​. Among fits with positive finite coefficient and exponent, select the smallest root mean squared error on the original loss scale, keeping the first candidate on ties. The mixture with the lowest prediction at target_size wins; ties favor the earlier mixture.

Return a Python dictionary with fits, a mixture-ordered list of dictionaries containing name (string) and floor, coefficient, exponent, rmse (Python floats); target_predictions, a float64 PyTorch tensor of shape (number of mixtures,) on the input device; winning_mixture, its name; and winning_index, its zero-based Python integer index.

Loading visualization...

Examples

Input: mixture_names = ["balanced","code"], data_sizes = [[1,4,16],[1,4,16]], losses = [[5,3,2],[6.5,3.5,2]], target_size = 64, floor_candidates = [0.5,1]

Output: {"fits":[{"name":"balanced","floor":1,"coefficient":4,"exponent":0.5,"rmse":0},{"name":"code","floor":0.5,"coefficient":6,"exponent":0.5,"rmse":0}],"target_predictions":[1.5,1.25],"winning_mixture":"code","winning_index":1}

Explanation: The code mixture begins with higher observed loss but its fitted curve extrapolates below the balanced curve at size 64.

Input: mixture_names = ["first","second"], data_sizes = [[1,4,16],[1,4,16]], losses = [[3,2,1.5],[3,2,1.5]], target_size = 64, floor_candidates = [1]

Output: {"fits":[{"name":"first","floor":1,"coefficient":2,"exponent":0.5,"rmse":0},{"name":"second","floor":1,"coefficient":2,"exponent":0.5,"rmse":0}],"target_predictions":[1.25,1.25],"winning_mixture":"first","winning_index":0}

Input: mixture_names = ["web","books","code"], data_sizes = [[1,4,16],[1,4,16],[1,4,16]], losses = [[4,2.5,1.75],[5,3,2],[3,1.75,1.125]], target_size = 64, floor_candidates = [0.5,1]

Output: {"fits":[{"name":"web","floor":1,"coefficient":3,"exponent":0.5,"rmse":0},{"name":"books","floor":1,"coefficient":4,"exponent":0.5,"rmse":0},{"name":"code","floor":0.5,"coefficient":2.5,"exponent":0.5,"rmse":0}],"target_predictions":[1.375,1.5,0.8125],"winning_mixture":"code","winning_index":2}

Hint 1

torch.linalg.lstsq solves a least-squares system.

Hint 2

torch.argmin returns the first index when minimum values tie.

Hint 3

enumerate keeps each mixture name aligned with its tensor row.

Requirements

  • Use PyTorch float64 arithmetic for fitting and prediction.
  • Preserve mixture order and the stated tie rules.
  • Do not modify inputs.

Constraints

  • mixture_names is a nonempty Python list of unique strings.
  • data_sizes and losses are float64 PyTorch tensors of shape (number of mixtures, observations), with at least three observations per mixture.
  • Each row has unique positive sizes and at least one eligible fit with positive finite coefficient and exponent.
  • target_size is a positive Python number; floor_candidates is a nonempty one-dimensional float64 PyTorch tensor.
  • All tensor inputs are finite, share a device, and may be noncontiguous.
Try Similar Problems
Fit a Data Power Law with a Noise FloorHardRecover an IsoFLOP Compute-Optimal FrontierHardEstimate Critical Batch SizeEasyFit Learning-Rate and Batch-Size ScalingHardDiagnose muP Width InvariantsMediumDecode Attention with a KV CacheHardTop-k MoE Router with Load StatisticsHardFit Elo Ratings from Pairwise VotesHardN-gram Language ModelMediumText Generation SamplingMediumLanguage ModelingMediumImplement Temperature, Top-k, and Top-p SamplingMedium

Accepts: array

Accepts: array

Accepts: array

Accepts: number

Accepts: array

You must run your code first.

Extrapolate Data-Mixture Scaling Curves

Scaling LawsLanguage ModelsProbability and Statistics
Hard

Compare named training-data mixtures by fitting a scaling curve to each row of observed sizes and losses:

Lk(D)=Ek+AkD−αk.L_k(D)=E_k+A_kD^{-\alpha_k}.Lk​(D)=Ek​+Ak​D−αk​.

Here, kkk identifies a mixture, DDD is its data size, Lk(D)L_k(D)Lk​(D) is predicted loss, EkE_kEk​ is the loss floor, AkA_kAk​ is a positive coefficient, and αk\alpha_kαk​ is a positive decay exponent. For each candidate floor below every observed loss in that row, the fit is unweighted least squares in natural-log space:

log⁡(Lk,i−Ek)=ak+bklog⁡Dk,i.\log(L_{k,i}-E_k)=a_k+b_k\log D_{k,i}.log(Lk,i​−Ek​)=ak​+bk​logDk,i​.

Index iii identifies an observation; Dk,iD_{k,i}Dk,i​ and Lk,iL_{k,i}Lk,i​ are its size and loss. The fitted intercept is ak=log⁡Aka_k=\log A_kak​=logAk​ and slope is bk=−αkb_k=-\alpha_kbk​=−αk​. Among fits with positive finite coefficient and exponent, select the smallest root mean squared error on the original loss scale, keeping the first candidate on ties. The mixture with the lowest prediction at target_size wins; ties favor the earlier mixture.

Return a Python dictionary with fits, a mixture-ordered list of dictionaries containing name (string) and floor, coefficient, exponent, rmse (Python floats); target_predictions, a float64 PyTorch tensor of shape (number of mixtures,) on the input device; winning_mixture, its name; and winning_index, its zero-based Python integer index.

Loading visualization...

Examples

Input: mixture_names = ["balanced","code"], data_sizes = [[1,4,16],[1,4,16]], losses = [[5,3,2],[6.5,3.5,2]], target_size = 64, floor_candidates = [0.5,1]

Output: {"fits":[{"name":"balanced","floor":1,"coefficient":4,"exponent":0.5,"rmse":0},{"name":"code","floor":0.5,"coefficient":6,"exponent":0.5,"rmse":0}],"target_predictions":[1.5,1.25],"winning_mixture":"code","winning_index":1}

Explanation: The code mixture begins with higher observed loss but its fitted curve extrapolates below the balanced curve at size 64.

Input: mixture_names = ["first","second"], data_sizes = [[1,4,16],[1,4,16]], losses = [[3,2,1.5],[3,2,1.5]], target_size = 64, floor_candidates = [1]

Output: {"fits":[{"name":"first","floor":1,"coefficient":2,"exponent":0.5,"rmse":0},{"name":"second","floor":1,"coefficient":2,"exponent":0.5,"rmse":0}],"target_predictions":[1.25,1.25],"winning_mixture":"first","winning_index":0}

Input: mixture_names = ["web","books","code"], data_sizes = [[1,4,16],[1,4,16],[1,4,16]], losses = [[4,2.5,1.75],[5,3,2],[3,1.75,1.125]], target_size = 64, floor_candidates = [0.5,1]

Output: {"fits":[{"name":"web","floor":1,"coefficient":3,"exponent":0.5,"rmse":0},{"name":"books","floor":1,"coefficient":4,"exponent":0.5,"rmse":0},{"name":"code","floor":0.5,"coefficient":2.5,"exponent":0.5,"rmse":0}],"target_predictions":[1.375,1.5,0.8125],"winning_mixture":"code","winning_index":2}

Hint 1

torch.linalg.lstsq solves a least-squares system.

Hint 2

torch.argmin returns the first index when minimum values tie.

Hint 3

enumerate keeps each mixture name aligned with its tensor row.

Requirements

  • Use PyTorch float64 arithmetic for fitting and prediction.
  • Preserve mixture order and the stated tie rules.
  • Do not modify inputs.

Constraints

  • mixture_names is a nonempty Python list of unique strings.
  • data_sizes and losses are float64 PyTorch tensors of shape (number of mixtures, observations), with at least three observations per mixture.
  • Each row has unique positive sizes and at least one eligible fit with positive finite coefficient and exponent.
  • target_size is a positive Python number; floor_candidates is a nonempty one-dimensional float64 PyTorch tensor.
  • All tensor inputs are finite, share a device, and may be noncontiguous.
Try Similar Problems
Fit a Data Power Law with a Noise FloorHardRecover an IsoFLOP Compute-Optimal FrontierHardEstimate Critical Batch SizeEasyFit Learning-Rate and Batch-Size ScalingHardDiagnose muP Width InvariantsMediumDecode Attention with a KV CacheHardTop-k MoE Router with Load StatisticsHardFit Elo Ratings from Pairwise VotesHardN-gram Language ModelMediumText Generation SamplingMediumLanguage ModelingMediumImplement Temperature, Top-k, and Top-p SamplingMedium

Accepts: array

Accepts: array

Accepts: array

Accepts: number

Accepts: array

You must run your code first.