@@ -340,6 +340,7 @@ def from_hf(
340340 target_dtype : torch .dtype = torch .float16 ,
341341 mmap_path : str | None = None ,
342342 num_layers : int | None = None ,
343+ disable_embedding_quantization : bool = False ,
343344 ) -> T :
344345 """Load model from HuggingFace model hub.
345346
@@ -353,6 +354,9 @@ def from_hf(
353354 num_layers: Optional number of transformer layers. When set, only layers
354355 0..num_layers-1 are loaded and the config is truncated.
355356 Useful for fast smoke tests.
357+ disable_embedding_quantization: iOS only. When True, the
358+ embedding table is not quantized to int8.
359+ Ignored for macOS model classes.
356360
357361 Returns:
358362 Instance of the model class loaded with HuggingFace weights
@@ -370,8 +374,12 @@ def from_hf(
370374 hf_model .config , max_context_length , num_layers = num_layers
371375 )
372376
373- # Create our model instance and load the state dict
374- model = cls (config , model_device = "meta" )
377+ # Create our model instance and load the state dict.
378+ # disable_embedding_quantization is only accepted by the iOS base class.
379+ init_kwargs : dict = {"config" : config , "model_device" : "meta" }
380+ if issubclass (cls , BaseForCausalLMForiOS ):
381+ init_kwargs ["disable_embedding_quantization" ] = disable_embedding_quantization
382+ model = cls (** init_kwargs )
375383 model .to (dtype = target_dtype )
376384 state_dict = hf_model .state_dict ()
377385 if not isinstance (state_dict , collections .abc .MutableMapping ):
@@ -414,6 +422,7 @@ def from_hf_memory_efficient(
414422 num_layers : int | None = None ,
415423 hf_config_attr : str | None = None ,
416424 hf_state_dict_prefix : str = "" ,
425+ disable_embedding_quantization : bool = False ,
417426 ) -> T :
418427 """Load model from HuggingFace with layer-by-layer memory offloading.
419428
@@ -439,6 +448,9 @@ def from_hf_memory_efficient(
439448 prefix are loaded. The prefix is stripped before assigning.
440449 Use for multimodal checkpoints where text weights live under
441450 a prefix (e.g. ``"language_model."``).
451+ disable_embedding_quantization: iOS only. When True, the
452+ embedding table is not quantized to int8.
453+ Ignored for non-iOS model classes.
442454 """
443455 model_dir = snapshot_download (
444456 huggingface_model_id ,
@@ -450,7 +462,11 @@ def from_hf_memory_efficient(
450462
451463 config = cls ._get_reauthored_config (hf_config , max_context_length , num_layers = num_layers )
452464
453- model = cls (config , model_device = "meta" )
465+ # disable_embedding_quantization is only accepted by the iOS base class.
466+ init_kwargs : dict = {"config" : config , "model_device" : "meta" }
467+ if issubclass (cls , BaseForCausalLMForiOS ):
468+ init_kwargs ["disable_embedding_quantization" ] = disable_embedding_quantization
469+ model = cls (** init_kwargs )
454470 model .to (dtype = target_dtype )
455471
456472 safetensors_files = _resolve_safetensors_files (model_dir )
0 commit comments