-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add batching to magnet * readme
- Loading branch information
Showing
7 changed files
with
302 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from "react"; | ||
import { Progress } from "./Progress"; | ||
|
||
export const HyperParameters = < | ||
T extends { | ||
iterations: number; | ||
splitByLines: boolean; | ||
} | ||
>({ | ||
params, | ||
setParams, | ||
progress, | ||
progressMax, | ||
isInterrupted: interrupted, | ||
interrupt, | ||
}: { | ||
params: T; | ||
setParams: React.Dispatch<React.SetStateAction<T>>; | ||
progress: number; | ||
progressMax: number; | ||
isInterrupted: boolean; | ||
interrupt: () => void; | ||
}) => ( | ||
<div className="flex flex-col gap-y-2 border border-gray-300 p-2 rounded"> | ||
<label className="text-sm">Hyperparameters:</label> | ||
<div className="flex gap-x-2 items-center"> | ||
<label className="text-sm">Iterations:</label> | ||
<input | ||
type="number" | ||
name="iterations" | ||
value={params.iterations} | ||
onChange={(event) => { | ||
setParams({ | ||
...params, | ||
iterations: Number(event.target.value), | ||
}); | ||
}} | ||
className="border border-gray-300 p-2 rounded" | ||
min="1" | ||
max="10" | ||
step="1" | ||
/> | ||
</div> | ||
<div className="flex gap-x-2 items-center"> | ||
<div className="text-sm">Each line as a separate prompt:</div> | ||
<input | ||
type="checkbox" | ||
name="splitByLines" | ||
checked={params.splitByLines} | ||
onChange={(event) => { | ||
setParams({ | ||
...params, | ||
splitByLines: event.target.checked, | ||
}); | ||
}} | ||
className="border border-gray-300 p-2 rounded" | ||
/> | ||
</div> | ||
<Progress progress={progress} progressMax={progressMax} /> | ||
<button className="border border-gray-300 p-2 rounded" onClick={interrupt}> | ||
{interrupted ? "Interrupted..." : "Interrupt"} | ||
</button> | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
|
||
export const Progress = ({ | ||
progress, | ||
progressMax, | ||
}: { | ||
progress: number; | ||
progressMax: number; | ||
}) => ( | ||
<div className="flex gap-x-2 items-center"> | ||
<label className="text-sm">Progress:</label> | ||
<progress | ||
value={progress} | ||
max={progressMax} | ||
className="[&::-webkit-progress-bar]:rounded [&::-webkit-progress-value]:rounded [&::-webkit-progress-bar]:bg-slate-300 [&::-webkit-progress-value]:bg-orange-400 [&::-moz-progress-bar]:bg-orange-400 [&::-webkit-progress-value]:transition-all [&::-webkit-progress-value]:duration-200" | ||
/> | ||
{progress}/{progressMax} | ||
</div> | ||
); | ||
|
||
export const manageProgress = async ( | ||
callback: (args: { incrementProgress: () => void }) => Promise<void>, | ||
max: number, | ||
setProgress: React.Dispatch< | ||
React.SetStateAction<{ current: number; max: number }> | ||
> | ||
) => { | ||
setProgress({ current: 0, max }); | ||
await callback({ | ||
incrementProgress: () => | ||
setProgress(({ current, max }) => ({ | ||
current: current + 1, | ||
max, | ||
})), | ||
}); | ||
setProgress({ current: 0, max: 0 }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const extractTexts = ( | ||
text: string, | ||
params: { iterations?: number; splitByLines: any } | ||
) => (params.splitByLines ? text.split("\n") : [text]); | ||
|
||
export const incrementNonRandomSeed = (seed: number, iteration: number) => | ||
seed === -1 ? -1 : seed + iteration; | ||
|
||
export const getMax = (texts: string[], iterations: number) => | ||
texts.length * iterations; | ||
|
||
export const initialHyperParams = { | ||
iterations: 1, | ||
splitByLines: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useRef } from "react"; | ||
|
||
export const useInterrupt = () => { | ||
const interrupted = useRef(false); | ||
|
||
const resetInterrupt = (callback: () => Promise<void>) => async () => { | ||
interrupted.current = false; | ||
await callback(); | ||
interrupted.current = false; | ||
}; | ||
|
||
const interrupt = () => (interrupted.current = true); | ||
|
||
return { interrupted, resetInterrupt, interrupt }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.