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6a
e7abd9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
import React, { useState } from "react";
import {
  Box,
  Paper,
  Typography,
  TextField,
  Button,
  Stack,
  Grid,
  CircularProgress,
  Alert,
} from "@mui/material";
import RocketLaunchIcon from "@mui/icons-material/RocketLaunch";
import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline";
import { alpha } from "@mui/material/styles";
import InfoIconWithTooltip from "../../../../components/shared/InfoIconWithTooltip";
import AuthContainer from "../../../../components/shared/AuthContainer";

const HELP_TEXTS = {
  modelName: (
    <Box sx={{ p: 1 }}>
      <Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 0.5 }}>
        Model Name on Hugging Face Hub
      </Typography>
      <Typography variant="body2" sx={{ opacity: 0.9, lineHeight: 1.4 }}>
        Your model must be public and loadable with AutoClasses without
        trust_remote_code. The model should be in Safetensors format for better
        safety and loading performance. Example: mistralai/Mistral-7B-v0.1
      </Typography>
    </Box>
  ),
  revision: (
    <Box sx={{ p: 1 }}>
      <Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 0.5 }}>
        Model Revision
      </Typography>
      <Typography variant="body2" sx={{ opacity: 0.9, lineHeight: 1.4 }}>
        Git branch, tag or commit hash. The evaluation will be strictly tied to
        this specific commit to ensure consistency. Make sure this version is
        stable and contains all necessary files.
      </Typography>
    </Box>
  ),
  modelType: (
    <Box sx={{ p: 1 }}>
      <Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 0.5 }}>
        Model Category
      </Typography>
      <Typography variant="body2" sx={{ opacity: 0.9, lineHeight: 1.4 }}>
        🟢 Pretrained: Base models trained on text using masked modeling 🟩
        Continuously Pretrained: Extended training on additional corpus 🔶
        Fine-tuned: Domain-specific optimization 💬 Chat: Models using RLHF,
        DPO, or IFT for conversation 🤝 Merge: Combined weights without
        additional training 🌸 Multimodal: Handles multiple input types
      </Typography>
    </Box>
  ),
  baseModel: (
    <Box sx={{ p: 1 }}>
      <Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 0.5 }}>
        Base Model Reference
      </Typography>
      <Typography variant="body2" sx={{ opacity: 0.9, lineHeight: 1.4 }}>
        Required for delta weights or adapters. This information is used to
        identify the original model and calculate the total parameter count by
        combining base model and adapter/delta parameters.
      </Typography>
    </Box>
  ),
  precision: (
    <Box sx={{ p: 1 }}>
      <Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 0.5 }}>
        Model Precision
      </Typography>
      <Typography variant="body2" sx={{ opacity: 0.9, lineHeight: 1.4 }}>
        Size limits vary by precision: • FP16/BF16: up to 100B parameters •
        8-bit: up to 280B parameters (2x) • 4-bit: up to 560B parameters (4x)
        Choose carefully as incorrect precision can cause evaluation errors.
      </Typography>
    </Box>
  ),
  weightsType: (
    <Box sx={{ p: 1 }}>
      <Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 0.5 }}>
        Weights Format
      </Typography>
      <Typography variant="body2" sx={{ opacity: 0.9, lineHeight: 1.4 }}>
        Original: Complete model weights in safetensors format Delta: Weight
        differences from base model (requires base model for size calculation)
        Adapter: Lightweight fine-tuning layers (requires base model for size
        calculation)
      </Typography>
    </Box>
  ),
  chatTemplate: (
    <Box sx={{ p: 1 }}>
      <Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 0.5 }}>
        Chat Template Support
      </Typography>
      <Typography variant="body2" sx={{ opacity: 0.9, lineHeight: 1.4 }}>
        Activates automatically for chat models. It uses the standardized
        Hugging Face chat template for consistent prompt formatting during
        evaluation. Required for models using RLHF, DPO, or instruction
        fine-tuning.
      </Typography>
    </Box>
  ),
};

function ModelSubmissionForm({ user, isAuthenticated }) {
  const [formData, setFormData] = useState({
    modelName: "",
    revision: "main",
    modelType: "fine-tuned",
    isChatModel: false,
    useChatTemplate: false,
    precision: "float16",
    weightsType: "Original",
    baseModel: "",
  });
  const [error, setError] = useState(null);
  const [submitting, setSubmitting] = useState(false);
  const [success, setSuccess] = useState(false);
  const [submittedData, setSubmittedData] = useState(null);

  const handleChange = (event) => {
    const { name, value, checked } = event.target;
    setFormData((prev) => ({
      ...prev,
      [name]: event.target.type === "checkbox" ? checked : value,
    }));
  };

  const handleSubmit = async (e) => {
    e.preventDefault();
    setError(null);
    setSubmitting(true);

    try {
      const response = await fetch("/api/models/submit", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          model_id: formData.modelName,
          revision: formData.revision,
          precision: formData.precision,
          weight_type: formData.weightsType,
          base_model: formData.baseModel,
          use_chat_template: formData.useChatTemplate,
          user_id: user.username,
        }),
      });

      if (!response.ok) {
        const error = await response.json();
        throw new Error(error.detail || "Failed to submit model");
      }

      setSubmittedData(formData);
      setSuccess(true);
    } catch (error) {
      setError(error.message);
    } finally {
      setSubmitting(false);
    }
  };

  if (success && submittedData) {
    return (
      <Paper
        variant="outlined"
        sx={(theme) => ({
          p: 6,
          mb: 3,
          bgcolor: alpha(theme.palette.success.main, 0.05),
          borderColor: alpha(theme.palette.success.main, 0.2),
        })}
      >
        <Stack spacing={3}>
          <Stack direction="row" spacing={2} alignItems="center">
            <CheckCircleOutlineIcon color="success" sx={{ fontSize: 28 }} />
            <Typography
              variant="h5"
              sx={{ fontWeight: 600, color: "success.800" }}
            >
              Model submitted successfully!
            </Typography>
          </Stack>

          <Typography variant="body1">
            Your model <strong>{submittedData.modelName}</strong> has been added
            to the evaluation queue.
          </Typography>

          <Typography variant="body2" color="text.secondary">
            An automatic upvote has been added to your model to help with
            prioritization.
          </Typography>

          <Stack direction="row" spacing={2}>
            <Button
              variant="outlined"
              size="large"
              onClick={() => {
                setSuccess(false);
                setSubmittedData(null);
                setFormData({
                  modelName: "",
                  revision: "main",
                  modelType: "fine-tuned",
                  isChatModel: false,
                  useChatTemplate: false,
                  precision: "float16",
                  weightsType: "Original",
                  baseModel: "",
                });
              }}
            >
              Submit another model
            </Button>
          </Stack>
        </Stack>
      </Paper>
    );
  }

  return (
    <>
      {error && (
        <Alert severity="error" sx={{ mb: 2 }}>
          {error}
        </Alert>
      )}
      <AuthContainer actionText="submit a model" />
      {isAuthenticated && (
        <Paper
          elevation={0}
          component="form"
          onSubmit={handleSubmit}
          sx={{
            p: 0,
            border: "1px solid",
            borderColor: "grey.300",
            mb: 3,
            overflow: "hidden",
          }}
        >
          {/* Header */}
          <Box
            sx={{
              px: 3,
              py: 2,
              borderBottom: "1px solid",
              borderColor: (theme) =>
                theme.palette.mode === "dark"
                  ? alpha(theme.palette.divider, 0.1)
                  : "grey.200",
              bgcolor: (theme) =>
                theme.palette.mode === "dark"
                  ? alpha(theme.palette.background.paper, 0.5)
                  : "grey.50",
            }}
          >
            <Typography
              variant="h6"
              sx={{ fontWeight: 600, color: "text.primary" }}
            >
              Model Submission Form
            </Typography>
          </Box>

          {/* Form Content */}
          <Box sx={{ p: 3 }}>
            <Grid container spacing={3}>
              {/* Model Information */}
              <Grid item xs={12}>
                <Stack direction="row" spacing={1} alignItems="center">
                  <Typography variant="h6">Model Information</Typography>
                  <InfoIconWithTooltip tooltip={HELP_TEXTS.modelName} />
                </Stack>
              </Grid>

              <Grid item xs={12} sm={8}>
                <TextField
                  required
                  fullWidth
                  name="modelName"
                  label="Model Name"
                  placeholder="organization/model-name"
                  value={formData.modelName}
                  onChange={handleChange}
                  helperText="Example: meta-llama/Llama-3.2-1B"
                  InputProps={{
                    endAdornment: (
                      <InfoIconWithTooltip tooltip={HELP_TEXTS.modelName} />
                    ),
                  }}
                />
              </Grid>

              <Grid item xs={12} sm={4}>
                <TextField
                  fullWidth
                  name="revision"
                  label="Revision commit"
                  value={formData.revision}
                  onChange={handleChange}
                  helperText="Default: main"
                  InputProps={{
                    endAdornment: (
                      <InfoIconWithTooltip tooltip={HELP_TEXTS.revision} />
                    ),
                  }}
                />
              </Grid>

              {/* Model Configuration */}
              {/*<Grid item xs={12}>
                <Stack direction="row" spacing={1} alignItems="center">
                  <Typography variant="h6">Model Configuration</Typography>
                </Stack>
              </Grid>

              <Grid item xs={12} sm={6}>
                <FormControl fullWidth>
                  <InputLabel>Model Type</InputLabel>
                  <Select
                    name="modelType"
                    value={formData.modelType}
                    onChange={handleChange}
                    label="Model Type"
                    endAdornment={
                      <InfoIconWithTooltip
                        tooltip={HELP_TEXTS.modelType}
                        sx={{ mr: 2 }}
                      />
                    }
                  >
                    {modelTypeOptions.map((type) => (
                      <MenuItem key={type.value} value={type.value}>
                        {type.label}
                      </MenuItem>
                    ))}
                  </Select>
                </FormControl>
              </Grid>*/}


              {/*<Grid item xs={12} sm={6}>
                <Stack
                  direction="row"
                  spacing={2}
                  alignItems="center"
                  sx={{ height: "100%" }}
                >
                  <FormControlLabel
                    control={
                      <Switch
                        name="useChatTemplate"
                        checked={formData.useChatTemplate}
                        onChange={handleChange}
                      />
                    }
                    label="Use Chat Template"
                  />
                  <InfoIconWithTooltip tooltip={HELP_TEXTS.chatTemplate} />
                </Stack>
              </Grid>*/}

              {/*
              <Grid item xs={12} sm={6}>
                <FormControl fullWidth>
                  <InputLabel>Precision</InputLabel>
                  <Select
                    name="precision"
                    value={formData.precision}
                    onChange={handleChange}
                    label="Precision"
                    endAdornment={
                      <InfoIconWithTooltip
                        tooltip={HELP_TEXTS.precision}
                        sx={{ mr: 2 }}
                      />
                    }
                  >
                    {SUBMISSION_PRECISIONS.map((option) => (
                      <MenuItem key={option.value} value={option.value}>
                        {option.label}
                      </MenuItem>
                    ))}
                  </Select>
                </FormControl>
              </Grid>

              <Grid item xs={12} sm={6}>
                <FormControl fullWidth>
                  <InputLabel>Weights Type</InputLabel>
                  <Select
                    name="weightsType"
                    value={formData.weightsType}
                    onChange={handleChange}
                    label="Weights Type"
                    endAdornment={
                      <InfoIconWithTooltip
                        tooltip={HELP_TEXTS.weightsType}
                        sx={{ mr: 2 }}
                      />
                    }
                  >
                    {WEIGHT_TYPES.map((type) => (
                      <MenuItem key={type.value} value={type.value}>
                        {type.label}
                      </MenuItem>
                    ))}
                  </Select>
                </FormControl>
              </Grid>

              {formData.weightsType !== "Original" && (
                <Grid item xs={12}>
                  <TextField
                    fullWidth
                    required={
                      formData.weightsType === "Delta" ||
                      formData.weightsType === "Adapter"
                    }
                    name="baseModel"
                    label="Base Model"
                    value={formData.baseModel}
                    onChange={handleChange}
                    InputProps={{
                      endAdornment: (
                        <InfoIconWithTooltip tooltip={HELP_TEXTS.baseModel} />
                      ),
                    }}
                  />
                </Grid>
              )}
*/}

              {/* Submit Button */}
              <Grid item xs={12}>
                <Box
                  sx={{
                    display: "flex",
                    justifyContent: "space-between",
                    alignItems: "center",
                    mt: 2,
                  }}
                >
                  <Typography variant="body2" color="text.secondary">
                    All fields marked with * are required
                  </Typography>
                  <Button
                    type="submit"
                    variant="contained"
                    disabled={submitting}
                    endIcon={submitting ? null : <RocketLaunchIcon />}
                    sx={{
                      minWidth: 120,
                      position: "relative",
                    }}
                  >
                    {submitting ? (
                      <CircularProgress size={24} color="inherit" />
                    ) : (
                      "Submit"
                    )}
                  </Button>
                </Box>
              </Grid>
            </Grid>
          </Box>
        </Paper>
      )}
    </>
  );
}

export default ModelSubmissionForm;