Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] Review theme colors #131

Merged
merged 44 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
921bec0
chore: update onSecondaryContainer color - add shadow color,
a-ghorbani Dec 7, 2024
1411c73
chore: update SwipeableRow style
a-ghorbani Dec 7, 2024
c95f84d
chore: clean up SidebarContent code
a-ghorbani Dec 7, 2024
8b4c935
chore: add inverseSecondary to theme color
a-ghorbani Dec 7, 2024
943f86c
chore: update mem usage stat plot color (use red)
a-ghorbani Dec 7, 2024
db718d3
chore: update ModelNotLoadedMessage action color
a-ghorbani Dec 7, 2024
77a3f72
chore: update pleaseLoadModel text
a-ghorbani Dec 7, 2024
c0a1b52
chore: replace empty message text with pocketpal's icon
a-ghorbani Dec 7, 2024
5dd8daf
chore: add divider component
a-ghorbani Dec 8, 2024
d9fe1b6
chore: refactor the style of models screen
a-ghorbani Dec 8, 2024
680be2b
feat: group models by ready to use and available to download (when un…
a-ghorbani Dec 8, 2024
60ea57c
feat: add description to Available to download group in models screen
a-ghorbani Dec 8, 2024
7c9001a
feat: refactoring generation/model settings ui - incomplete
a-ghorbani Dec 8, 2024
c687611
chore: add chevron to settings button
a-ghorbani Dec 8, 2024
4dab483
chore: adjust model settings view actions buttons
a-ghorbani Dec 8, 2024
49571c3
chore: refactor model settings styles
a-ghorbani Dec 8, 2024
e6d376f
chore: update generation settings style
a-ghorbani Dec 8, 2024
598e94f
chore: update generation settings' style
a-ghorbani Dec 8, 2024
21859c8
fix: correct ref forwarding for TextInput
a-ghorbani Dec 9, 2024
c487315
chore: update ChatTemplatePicker style
a-ghorbani Dec 9, 2024
30313cc
chore: update chat template picker style
a-ghorbani Dec 9, 2024
402e378
feat: model and generation settings are changed only if saved
a-ghorbani Dec 9, 2024
68ad1bf
chore: update TextInput to support error messages
a-ghorbani Dec 9, 2024
010b5ee
feat: add completion settings validation
a-ghorbani Dec 9, 2024
70fb91c
fix: use textSeconday for dateHeader in the chat bubble
a-ghorbani Dec 9, 2024
9b09138
chore: refactor completion settings
a-ghorbani Dec 9, 2024
f70eeb9
chore: remove n_probs from the ui
a-ghorbani Dec 9, 2024
7236aa7
chore: update completion settings desc
a-ghorbani Dec 9, 2024
c95fb1b
fix: increase temp max value
a-ghorbani Dec 9, 2024
4f8d0b4
chore: update tests
a-ghorbani Dec 10, 2024
af859b4
chore: add scrollable param to dialog
a-ghorbani Dec 10, 2024
49c3732
chore: use scrollable in modelcard re settings dialog
a-ghorbani Dec 10, 2024
a38b94a
fix: adjust heights for the chat template picker
a-ghorbani Dec 10, 2024
c24ac66
fix: align settings button chevron in android devices
a-ghorbani Dec 10, 2024
c04b8c1
fix: dialog keyboard avoiding: only adjust if input is actually cover…
a-ghorbani Dec 10, 2024
873d08a
fix: dialog: apply bottom for keyboard avoding to the content
a-ghorbani Dec 10, 2024
a975878
fix: make settings modal also keyboard avoiding
a-ghorbani Dec 10, 2024
ee182f6
fix: make chat template dialog keyboard avoiding
a-ghorbani Dec 10, 2024
1fd8ac1
fix: moveScrollToDown in models screen is no longer needed
a-ghorbani Dec 10, 2024
fd9aa5a
chore: add inverseTextSecondary to the theme
a-ghorbani Dec 10, 2024
7e412a7
chore: update settings screen theme
a-ghorbani Dec 10, 2024
57e374c
chore: skip "opens and closes the template dialog" as it fails in ci
a-ghorbani Dec 10, 2024
da266fd
fix: update background and surface for dark mode
a-ghorbani Dec 10, 2024
e7022c3
chore: update background and surface for the dark mode
a-ghorbani Dec 10, 2024
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
Prev Previous commit
Next Next commit
chore: refactor completion settings
  • Loading branch information
a-ghorbani committed Dec 9, 2024
commit 9b09138961149a5694f84a05002cd5817c2dc6e5
6 changes: 6 additions & 0 deletions src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ interface CustomDialogProps {
style?: ViewStyle;
contentStyle?: ViewStyle;
scrollable?: boolean;
dismissableBackButton?: boolean;
dismissable?: boolean;
}

export const Dialog: React.FC<CustomDialogProps> = ({
Expand All @@ -32,13 +34,17 @@ export const Dialog: React.FC<CustomDialogProps> = ({
actions = [],
style,
contentStyle,
dismissableBackButton = true,
dismissable = true,
}) => {
const theme = useTheme();
const styles = createStyles(theme);

return (
<Portal>
<PaperDialog
dismissableBackButton={dismissableBackButton}
dismissable={dismissable}
visible={visible}
onDismiss={onDismiss}
style={[styles.dialog, style]}>
Expand Down
272 changes: 83 additions & 189 deletions src/screens/ModelsScreen/CompletionSettings/CompletionSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,23 @@ import {useTheme} from '../../../hooks';

import {createStyles} from './styles';

import {L10nContext} from '../../../utils';
import {
MODEL_VALIDATION_RULES,
COMPLETION_PARAMS_METADATA,
validateNumericField,
} from '../../../utils/validation';
} from '../../../utils/modelSettings';

interface Props {
settings: CompletionParams;
onChange: (name: string, value: any) => void;
}

const PARAMETER_DESCRIPTIONS = {
n_predict: 'Maximum number of tokens to generate',
temperature: 'Controls randomness (higher = more creative)',
top_k: 'Limits token selection to K most likely options',
top_p: 'Cumulative probability threshold for token selection',
min_p: 'Minimum token probability relative to best token',
xtc_threshold: 'Minimum probability for token consideration',
xtc_probability: 'Probability of token removal at start',
typical_p: 'Controls locally typical sampling',
penalty_last_n: 'Number of tokens to check for repetition',
penalty_repeat: 'Penalizes token sequence repetition',
penalty_freq: 'Penalizes frequent token usage',
penalty_present: 'Penalizes token presence in context',
mirostat: 'Advanced sampling mode for stable output',
mirostat_tau: 'Target complexity for Mirostat',
mirostat_eta: 'Learning rate for Mirostat',
penalize_nl: 'Apply repeat penalty to newlines',
seed: 'Random seed for reproducible output',
n_probs: 'Return top token probabilities',
stop: 'Sequences that end generation',
};

export const CompletionSettings: React.FC<Props> = ({settings, onChange}) => {
const [localSliderValues, setLocalSliderValues] = useState({});
const [newStopWord, setNewStopWord] = useState('');
const theme = useTheme();
const styles = createStyles(theme);
const l10n = React.useContext(L10nContext);

// Reset local values when settings change
useEffect(() => {
Expand All @@ -58,26 +38,18 @@ export const CompletionSettings: React.FC<Props> = ({settings, onChange}) => {
onChange(name, value);
};

const renderSlider = ({
name,
min,
max,
step = 0.01,
label,
}: {
name: string;
min: number;
max: number;
step?: number;
label?: string;
}) => (
const renderSlider = ({name, step = 0.01}: {name: string; step?: number}) => (
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>{label ?? name}</Text>
<Text style={styles.description}>{PARAMETER_DESCRIPTIONS[name]}</Text>
<Text variant="labelSmall" style={styles.settingLabel}>
{name.toUpperCase().replace('_', ' ')}
</Text>
<Text style={styles.description}>
{l10n[COMPLETION_PARAMS_METADATA[name]?.descriptionKey]}
</Text>
<Slider
style={styles.slider}
minimumValue={min}
maximumValue={max}
minimumValue={COMPLETION_PARAMS_METADATA[name]?.validation.min}
maximumValue={COMPLETION_PARAMS_METADATA[name]?.validation.max}
step={step}
value={localSliderValues[name] ?? settings[name]}
onValueChange={value => {
Expand All @@ -99,49 +71,41 @@ export const CompletionSettings: React.FC<Props> = ({settings, onChange}) => {
</View>
);

const renderIntegerInput = ({
name,
label,
}: {
name: string;
label?: string;
}) => {
const rule = MODEL_VALIDATION_RULES[name];
if (!rule) {
console.warn(`No validation rule found for ${name}`);
const renderIntegerInput = ({name}: {name: keyof CompletionParams}) => {
const metadata = COMPLETION_PARAMS_METADATA[name];
if (!metadata) {
return null;
}

const value = settings[name].toString();
const isValid = validateNumericField(value, rule);
const value = settings[name]?.toString() ?? '';
const validation = validateNumericField(value, metadata.validation);

return (
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>{label ?? name}</Text>
<Text style={styles.description}>{PARAMETER_DESCRIPTIONS[name]}</Text>
<Text variant="labelSmall" style={styles.settingLabel}>
{name.toUpperCase().replace('_', ' ')}
</Text>
<Text style={styles.description}>{l10n[metadata.descriptionKey]}</Text>
<TextInput
value={value}
onChangeText={_value => {
onChange(name, _value);
}}
onChangeText={_value => onChange(name, _value)}
keyboardType="numeric"
error={!isValid}
helperText={
!isValid
? `Value must be between ${rule.min} and ${rule.max}`
: undefined
}
testID={`${name}-input`}
error={!validation.isValid}
helperText={validation.errorMessage}
/>
</View>
);
};

const renderSwitch = (name: string, label?: string) => (
const renderSwitch = (name: string) => (
<View style={[styles.settingItem, styles.row]}>
<View>
<Text style={styles.settingLabel}>{label ?? name}</Text>
<Text style={styles.description}>{PARAMETER_DESCRIPTIONS[name]}</Text>
<Text variant="labelSmall" style={styles.settingLabel}>
{name.toUpperCase().replace('_', ' ')}
</Text>
<Text style={styles.description}>
{l10n[COMPLETION_PARAMS_METADATA[name]?.descriptionKey]}
</Text>
</View>
<Switch
value={settings[name]}
Expand All @@ -154,7 +118,9 @@ export const CompletionSettings: React.FC<Props> = ({settings, onChange}) => {
const renderStopWords = () => (
<View style={styles.settingItem}>
<View style={styles.stopLabel}>
<Text style={styles.settingLabel}>stop</Text>
<Text variant="labelSmall" style={styles.settingLabel}>
STOP WORDS
</Text>
</View>

{/* Display existing stop words as chips */}
Expand Down Expand Up @@ -192,134 +158,62 @@ export const CompletionSettings: React.FC<Props> = ({settings, onChange}) => {
</View>
);

const renderMirostatSelector = () => (
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>Mirostat</Text>
<Text style={styles.description}>{PARAMETER_DESCRIPTIONS.mirostat}</Text>
<SegmentedButtons
value={(settings.mirostat ?? 0).toString()}
onValueChange={value => onChange('mirostat', parseInt(value, 10))}
density="high"
buttons={[
{
value: '0',
label: 'Off',
},
{
value: '1',
label: 'v1',
},
{
value: '2',
label: 'v2',
},
]}
style={styles.segmentedButtons}
/>
</View>
);
const renderMirostatSelector = () => {
const descriptionKey = COMPLETION_PARAMS_METADATA.mirostat?.descriptionKey;
const description = descriptionKey ? l10n[descriptionKey] : '';

return (
<View style={styles.settingItem}>
<Text style={styles.settingLabel}>Mirostat</Text>
{description && <Text style={styles.description}>{description}</Text>}
<SegmentedButtons
value={(settings.mirostat ?? 0).toString()}
onValueChange={value => onChange('mirostat', parseInt(value, 10))}
density="high"
buttons={[
{
value: '0',
label: 'Off',
},
{
value: '1',
label: 'v1',
},
{
value: '2',
label: 'v2',
},
]}
style={styles.segmentedButtons}
/>
</View>
);
};

return (
<View>
{renderIntegerInput({
name: 'n_predict',
label: 'N-Predict',
})}
{renderSlider({
name: 'temperature',
min: MODEL_VALIDATION_RULES.temperature.min,
max: MODEL_VALIDATION_RULES.temperature.max,
label: 'Temperature',
})}
{renderSlider({
name: 'top_k',
min: MODEL_VALIDATION_RULES.top_k.min,
max: MODEL_VALIDATION_RULES.top_k.max,
step: 1,
label: 'Top-K',
})}
{renderSlider({
name: 'top_p',
min: MODEL_VALIDATION_RULES.top_p.min,
max: MODEL_VALIDATION_RULES.top_p.max,
label: 'Top-P',
})}
{renderSlider({
name: 'min_p',
min: MODEL_VALIDATION_RULES.min_p.min,
max: MODEL_VALIDATION_RULES.min_p.max,
label: 'Min-P',
})}
{renderSlider({
name: 'xtc_threshold',
min: MODEL_VALIDATION_RULES.xtc_threshold.min,
max: MODEL_VALIDATION_RULES.xtc_threshold.max,
label: 'XTC Threshold',
})}
{renderSlider({
name: 'xtc_probability',
min: MODEL_VALIDATION_RULES.xtc_probability.min,
max: MODEL_VALIDATION_RULES.xtc_probability.max,
label: 'XTC Probability',
})}
{renderSlider({
name: 'typical_p',
min: MODEL_VALIDATION_RULES.typical_p.min,
max: MODEL_VALIDATION_RULES.typical_p.max,
label: 'Typical P',
})}
{renderSlider({
name: 'penalty_last_n',
min: MODEL_VALIDATION_RULES.penalty_last_n.min,
max: MODEL_VALIDATION_RULES.penalty_last_n.max,
step: 1,
label: 'Penalty Last N',
})}
{renderSlider({
name: 'penalty_repeat',
min: MODEL_VALIDATION_RULES.penalty_repeat.min,
max: MODEL_VALIDATION_RULES.penalty_repeat.max,
label: 'Penalty Repeat',
})}
{renderSlider({
name: 'penalty_freq',
min: MODEL_VALIDATION_RULES.penalty_freq.min,
max: MODEL_VALIDATION_RULES.penalty_freq.max,
label: 'Penalty Freq',
})}
{renderSlider({
name: 'penalty_present',
min: MODEL_VALIDATION_RULES.penalty_present.min,
max: MODEL_VALIDATION_RULES.penalty_present.max,
label: 'Penalty Present',
})}
{renderIntegerInput({name: 'n_predict'})}
{renderSlider({name: 'temperature'})}
{renderSlider({name: 'top_k', step: 1})}
{renderSlider({name: 'top_p'})}
{renderSlider({name: 'min_p'})}
{renderSlider({name: 'xtc_threshold'})}
{renderSlider({name: 'xtc_probability'})}
{renderSlider({name: 'typical_p'})}
{renderSlider({name: 'penalty_last_n', step: 1})}
{renderSlider({name: 'penalty_repeat'})}
{renderSlider({name: 'penalty_freq'})}
{renderSlider({name: 'penalty_present'})}
{renderMirostatSelector()}
{(settings.mirostat ?? 0) > 0 && (
<>
{renderSlider({
name: 'mirostat_tau',
min: MODEL_VALIDATION_RULES.mirostat_tau.min,
max: MODEL_VALIDATION_RULES.mirostat_tau.max,
step: 1,
label: 'Mirostat Tau',
})}
{renderSlider({
name: 'mirostat_eta',
min: MODEL_VALIDATION_RULES.mirostat_eta.min,
max: MODEL_VALIDATION_RULES.mirostat_eta.max,
label: 'Mirostat Eta',
})}
{renderSlider({name: 'mirostat_tau', step: 1})}
{renderSlider({name: 'mirostat_eta'})}
</>
)}
{renderSwitch('penalize_nl', 'Penalize NL')}
{renderIntegerInput({
name: 'seed',
label: 'Seed',
})}
{renderIntegerInput({
name: 'n_probs',
label: 'N-Probs',
})}
{renderSwitch('penalize_nl')}
{renderIntegerInput({name: 'seed'})}
{renderIntegerInput({name: 'n_probs'})}
{renderStopWords()}
</View>
);
Expand Down
2 changes: 0 additions & 2 deletions src/screens/ModelsScreen/CompletionSettings/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export const createStyles = (theme: Theme) =>
paddingHorizontal: 4,
},
settingLabel: {
fontSize: 14,
fontWeight: 'bold',
marginBottom: 2,
},
settingValue: {
Expand Down
Loading
Loading