Add new model: Kimi2-6#45630
Conversation
|
Oke, I think the model part looks same as the custom code, though I didn't test it. Also we need to check what is the exact chat template format and how to add Kimi team might reply on Monday, coming back then |
vasqu
left a comment
There was a problem hiding this comment.
Some initial comments from my side, I wanted to focus on things that we could simplify - mainly the RoPE I think.
I know it's WIP in a way so don't mind comments you already want to address yourself
| if image_processor_type is None: | ||
| try: | ||
| if not isinstance(config, PreTrainedConfig): | ||
| config = AutoConfig.from_pretrained( | ||
| pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs | ||
| ) | ||
|
|
||
| image_processor_type = getattr(config, "image_processor_type", None) | ||
| if hasattr(config, "auto_map") and "AutoImageProcessor" in config.auto_map: | ||
| image_processor_auto_map = config.auto_map["AutoImageProcessor"] | ||
| except ValueError: | ||
| # Config loading failed (unrecognized model_type, invalid config, etc.) | ||
| # Continue to fallback logic below (AutoTokenizer, AutoImageProcessor, etc.) | ||
| pass | ||
|
|
||
| # Derive base_class_name from image_processor_type | ||
| is_legacy_fast = False | ||
| base_class_name = None | ||
| if image_processor_type is not None: | ||
| is_legacy_fast = image_processor_type.endswith("Fast") | ||
| base_class_name = image_processor_type[:-4] if is_legacy_fast else image_processor_type | ||
|
|
||
| backend = _resolve_backend(backend_kwarg, use_fast, base_class_name) | ||
|
|
||
| image_processor_class = None | ||
| if base_class_name is not None: | ||
| image_processor_class = _load_backend_class(base_class_name, backend, is_legacy_fast) | ||
|
|
||
| # Handle remote code | ||
| has_remote_code = image_processor_auto_map is not None | ||
| has_local_code = image_processor_class is not None or type(config) in IMAGE_PROCESSOR_MAPPING | ||
| explicit_local_code = has_local_code and not ( | ||
| image_processor_class or _load_class_with_fallback(IMAGE_PROCESSOR_MAPPING[type(config)], backend) | ||
| ).__module__.startswith("transformers.") | ||
| if has_remote_code: | ||
| class_ref = _resolve_auto_map_class_ref(image_processor_auto_map, backend) | ||
| upstream_repo = class_ref.split("--")[0] if "--" in class_ref else None | ||
| trust_remote_code = resolve_trust_remote_code( |
There was a problem hiding this comment.
copied from processing_auto.pt btw. The idea is to infer local class name if possible from config, even if we found a remote code
The remote code will still be loaded with higher prio if users pass trust_remote_code, so nothing should break
| @requires( | ||
| backends=[ | ||
| "torch", | ||
| ] | ||
| ) |
There was a problem hiding this comment.
because it requires torch :)
The repo consistency isn't happy and tries to import it with no-torch env, then it raises error
There was a problem hiding this comment.
oke, maybe this folder is supposed to be non-torch. I see FP conversions are in root/integrations/
|
run-slow: kimi_k25 |
|
This comment contains models: ["models/kimi_k25"] |
| outputs = [] | ||
| running_length = 0 | ||
| for t, h, w in grid_thw.tolist(): | ||
| # Get the current sequence | ||
| seq = hidden_states[running_length : running_length + t * h * w] | ||
| # Reshape along self.merge_kernel_size and concat to the last dimension | ||
| new_height, new_width = h // kernel_height, w // kernel_width | ||
| reshaped_seq = seq.view(t, new_height, kernel_height, new_width, kernel_width, hidden_dim) | ||
| reshaped_seq = reshaped_seq.transpose(2, 3).mean(dim=0) # temporal pooling | ||
| padded_seq = reshaped_seq.reshape(new_height * new_width, kernel_height * kernel_width, -1) | ||
| outputs.append(padded_seq) | ||
| running_length += t * h * w | ||
|
|
||
| return torch.cat(outputs, dim=0) |
There was a problem hiding this comment.
can you please use the compile/export friendly vision_utils here 🙏
There was a problem hiding this comment.
there is no utility to permute and pooling each image, no?
Co-authored-by: Anton Vlasjuk <[email protected]>
|
run-slow: kimi_k25 |
|
run-slow: kimi_k25 |
1 similar comment
|
run-slow: kimi_k25 |
|
This comment contains models: ["models/kimi_k25"] |
CI ResultsCommit Info
Model CI Report❌ 4 new failed tests from this PR 😭
|
This reverts commit 5952534.
There was a problem hiding this comment.
Looks like it was not reverted?
There was a problem hiding this comment.
yeah, weird, it didn't get reverted
CI recapDashboard: View test results in Grafana |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: auto, kimi_k25 |
What does this PR do?
The moonshot team is not very active and haven't yet replied, so I kept all the
model_typenaming to match the remote code. That allows us to load a model with local code. There are still a few problems such as tokenizer needing conversion and jinja chat template being non-consistent thoughThey have saved a tiktoken tokeninzer and tbh I am not sure if we can convert it, and nudge them to update. So as a workaround we convert from tiktoken at load-time
Tested with below script but uses a smaller/dummy model. Logits and eager generation are equivalent with official implementation.