Skip to content

Commit

Permalink
128k=128,000, 4K=4096, Kibi / kilo
Browse files Browse the repository at this point in the history
  • Loading branch information
sxjeru committed Apr 28, 2024
1 parent feb96ba commit ff17c88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ import useMergeState from 'use-merge-value';

const exponent = (num: number) => Math.log2(num);
const getRealValue = (num: number) => Math.round(Math.pow(2, num));
const power1024 = (num: number) => Math.round(Math.pow(2, num) * 1024);

const isSmallScreen = typeof window !== 'undefined' ? window.innerWidth < 475 : false;

const marks: SliderSingleProps['marks'] = {
[exponent(1)]: '0',
[exponent(2)]: isSmallScreen ? '2' : '2K',
[exponent(2)]: isSmallScreen ? '2' : '2K', // 2 Kibi = 2048
[exponent(4)]: isSmallScreen ? '4' : '4K',
[exponent(8)]: isSmallScreen ? '8' : '8K',
[exponent(16)]: isSmallScreen ? '16' : '16K',
[exponent(32)]: isSmallScreen ? '32' : '32K',
[exponent(64)]: isSmallScreen ? '64' : '64K',
[exponent(128)]: isSmallScreen ? '128' : '128K',
[exponent(256)]: isSmallScreen ? '256' : '256K',
// [exponent(128)]: isSmallScreen ? '128' : '128K',
// [exponent(256)]: isSmallScreen ? '256' : '256K',
[exponent((128 / 1024) * 1000)]: ' ',
[exponent((200 / 1024) * 1000)]: isSmallScreen ? '200' : '200k', // 200,000
[exponent(1024)]: isSmallScreen ? '1024' : '1M',
};

Expand All @@ -38,18 +41,18 @@ const MaxTokenSlider = memo<MaxTokenSliderProps>(({ value, onChange, defaultValu
});

const [powValue, setPowValue] = useMergeState(0, {
defaultValue: exponent(typeof defaultValue === 'undefined' ? 0 : defaultValue / 1000),
defaultValue: exponent(typeof defaultValue === 'undefined' ? 0 : defaultValue / 1024),
value: exponent(typeof value === 'undefined' ? 0 : value / 1024),
});

const updateWithPowValue = (value: number) => {
setPowValue(value);

setTokens(getRealValue(value) === 1 ? 0 : getRealValue(value) * 1024);
setTokens(getRealValue(value) === 1 ? 0 : power1024(value));
};

const updateWithRealValue = (value: number) => {
setTokens(value);
setTokens(Math.round(value));

setPowValue(exponent(value / 1024));
};
Expand All @@ -62,17 +65,15 @@ const MaxTokenSlider = memo<MaxTokenSliderProps>(({ value, onChange, defaultValu
max={exponent(1024)}
min={0}
onChange={updateWithPowValue}
step={2}
step={null}
tooltip={{
formatter: (x) => {
if (typeof x === 'undefined') return;

if (x === 0) return t('llm.customModelCards.modelConfig.tokens.unlimited');

const value = getRealValue(x);

if (value < 1024) return value.toFixed(0) + 'K';

let value = getRealValue(x);
if (value < 125) return value.toFixed(0) + 'K';
else if (value < 1024) return ((value * 1024) / 1000).toFixed(0) + 'k';
return (value / 1024).toFixed(0) + 'M';
},
}}
Expand Down
8 changes: 6 additions & 2 deletions src/components/ModelSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ const useStyles = createStyles(({ css, token }) => ({
}));
const formatTokenNumber = (num: number): string => {
if (num === 0) return 'Inf';
if (num < 1000) return '1K';
const kiloToken = Math.floor(num / 1000);
if (num < 1024) return '1K';

let kiloToken = Math.floor(num / 1024);
if (num >= 128_000 && num < 1_024_000) {
kiloToken = Math.floor(num / 1000);
}
return kiloToken < 1000 ? `${kiloToken}K` : `${Math.floor(kiloToken / 1000)}M`;
};

Expand Down

0 comments on commit ff17c88

Please sign in to comment.