mindformers.models.Qwen3ForCausalLM
- class mindformers.models.Qwen3ForCausalLM(config, *inputs, **kwargs)[源代码]
Provide Qwen3 Model for training and inference. :param config: The config of Qwen3 model. :type config: Qwen3Config
- 返回:
Tensor, the loss or logits of the network.
- __init__(config, *inputs, **kwargs)
Methods
__init__(config, *inputs, **kwargs)add_flags(**flags)Add customized attributes for cell.
add_flags_custom(is_first_iteration)Add customized attributes for specific cells in the model.
add_flags_custom_mcore(is_prefill)Add customized attributes for specific cells in the model.
add_flags_recursive(**flags)If a cell contains child cells, this method can recursively customize attributes of all cells.
apply(fn)Applies fn recursively to every subcell (as returned by .cells()) as well as self.
auto_offload()Enable automatic offload for this Cell.
buffers([recurse])Return an iterator over cell buffers.
can_generate()Returns whether this model can generate sequences with .generate().
cast_inputs(inputs, dst_type)Cast inputs to specified type.
cells()Returns an iterator over immediate cells.
cells_and_names([cells, name_prefix])Returns an iterator over all cells in the network, including the cell's name and itself.
chat(tokenizer, query[, history, ...])Dia-logical text generation inference with large language models.
check_names()Check the names of cell parameters.
check_names_and_refresh_name()check_pipeline_stage()check pipeline_stage and num_layers
chunk_prefill_infer(input_ids, ...[, ...])Preprocessing of chunk prefill inference
compile(*args, **kwargs)Compile Cell as a computation graph, the input must be consistent with the input defined in construct.
compile_and_run(*args, **kwargs)Compile and run Cell, the input must be consistent with the input defined in construct.
construct(*args, **kwargs)Defines the computation to be performed.
convert_concat_name(weight_name)convert HuggingFace weight name to MindFormers weight name.
convert_map_dict(source_dict, **kwargs)convert HuggingFace map dict to MindFormers map dict
convert_name(weight_name)convert HuggingFace weight name to MindFormers weight name.
convert_pin_model_inputs(model_inputs)convert_to_transformer_config(config[, ...])convert_weight_dict(source_dict, **kwargs)convert HuggingFace weight dict to MindFormers weight dict
extend_repr()Expand the description of Cell.
forward(input_ids, valid_length_each_example)Model forward process.
forward_mcore(input_ids, ...[, ...])Model forward process.
from_pretrained(...)Instantiates a model by the pretrained_model_name_or_dir.
from_pretrained_experimental_mode(...[, ...])Instantiate a pretrained mindspore model from a pre-trained model configuration.
from_pretrained_origin_mode(...)Instantiates a model by the pretrained_model_name_or_dir.
fuse_weight_from_ckpt(ckpt_dict)Fuse weight function, which fuse the weight and update parameter dictionary before loading weight into network.
gen_attention_mask(is_prefill)generate(input_ids[, generation_config, ...])Generate the words according to the given the input ids.
generate_scope()Generate the scope for each cell object in the network.
get_buffer(target)Return the buffer given by target if it exists, otherwise throw an error.
get_extra_state()Return any extra state to include in the cell's state_dict.
get_flags()Get the self_defined attributes of the cell, which can be added by add_flags method.
get_func_graph_proto()Return graph binary proto.
get_gpt_model()Obtain the GPT model instance.
get_gpt_transformer_config()Get the transformer config for GPT model
get_inputs()Returns the dynamic_inputs of a cell object within a network.
get_logits_processor(generation_config, ...)This class returns a [LogitsProcessorList] list object that contains all relevant [LogitsProcessor] instances used to modify the scores of the language model head.
get_logits_warper(generation_config)This class returns a [LogitsProcessorList] list object that contains all relevant [LogitsWarper] instances used for multinomial sampling.
get_mixed_precision_type(self)Get mixed precision type.
get_model_parameters([only_trainable])get_parameters([expand])Returns an iterator over cell parameters.
get_scope()Returns the scope of a cell object in one network.
get_sub_cell(target)Return the sub cell given by target if it exists, otherwise throw an error.
get_support_list()get_support_list method
infer(input_ids, valid_length_each_example)Do infer and return logits on next position, can choose do prefill or decode predict.
infer_mcore(input_ids, valid_length_each_example)Do infer and return logits on next position, can choose do prefill or decode predict.
init_parameters_data([auto_parallel_mode])Initialize all parameters and replace the original saved parameters in cell.
insert_child_to_cell(child_name, child_cell)Adds a child cell to the current cell with a given name.
insert_param_to_cell(param_name, param[, ...])Inserts a parameter with given name to the cell.
is_experimental_mode(...)Check whether AutoModel.from_pretrained() should go into original or experimental mode.
is_moe_model()Check whether the model is a moe model.
is_mtp_model()Check whether the model is a multi-token prediction model.
kvcache(layer_idx)load_checkpoint(config)load checkpoint for models.
load_state_dict(state_dict[, strict])Copy parameters and buffers from
state_dictinto this cell and its descendants.name_cells()Returns an iterator over all immediate cells in the network.
named_buffers([prefix, recurse, ...])Return an iterator over cell buffers, yielding both the name of the buffer as well as the buffer itself.
obtain_name_map(load_checkpoint_files)obtain HuggingFace safetensor name_map dict to MindFormers
obtain_qkv_ffn_concat_keys()Obtain key list generated during weight concatenation of qkv/ffn concat operation.
offload([backward_prefetch])Set the cell offload.
parameters_and_names([name_prefix, expand])Returns an iterator over cell parameters.
parameters_broadcast_dict([recurse])Gets the parameters broadcast dictionary of this cell.
parameters_dict([recurse])Gets the parameters dictionary of this cell.
post_init()A method executed at the end of each Transformer model initialization, to execute code that needs the model's modules properly initialized (such as weight initialization).
postprocess(input_ids, is_finished, res, ...)Postprocess of the output from model generation.
prepare_inputs_for_generation(input_ids, ...)prepare inputs for generation.
prepare_inputs_for_generation_mcore(...[, ...])prepare inputs for mcore
prepare_inputs_for_predict_layout(input_ids, ...)prepare inputs for transform ckpt.
process_logits(logits[, current_index, keep_all])Process the logits
push_to_hub(...)Upload the {object_files} to the OpenMind Model Hub.
recompute(*[, use_reentrant, ...])Set the cell recomputed.
register_backward_hook(hook_fn)Register the backward hook function.
register_backward_pre_hook(hook_fn)Register the backward pre hook function.
register_buffer(name, tensor[, persistent])Add a buffer to the cell.
register_for_auto_class([auto_class])Register this class with a given auto class.
register_forward_hook(hook_fn, *[, prepend, ...])Register forward hook function for Cell object.
register_forward_pre_hook(hook_fn, *[, ...])Register forward pre hook function for Cell object.
register_load_state_dict_post_hook(hook)Register a post-hook to be run after cell's
mindspore.nn.Cell.load_state_dict()is called.register_load_state_dict_pre_hook(hook)Register a pre-hook to be run before cell's
mindspore.nn.Cell.load_state_dict()is called.register_parameter_forward_hook(hook)Register parameter forward hooks for current cell instance.
register_saved_tensors_hooks(pack_hook, ...)Register hook functions for packing and unpacking saved tensors.
register_state_dict_post_hook(hook)Register a post-hook for the
mindspore.nn.Cell.state_dict()method.register_state_dict_pre_hook(hook)Register a pre-hook for the
mindspore.nn.Cell.state_dict()method.remove_redundant_parameters()Remove the redundant parameters.
remove_type(config)remove type caused by save
run_construct(cast_inputs, kwargs)Run the construct function.
save_pretrained(save_directory[, save_name])Save the model weight and configuration file.
save_pretrained_experimental_mode(...)Save a model and its configuration file to a directory, so that it can be re-loaded using the [~PreTrainedModel.from_pretrained] class method.
save_pretrained_origin_mode([...])Save the model weight and configuration file.
set_boost(boost_type)In order to improve the network performance, configure the network auto enable to accelerate the algorithm in the algorithm library.
set_broadcast_flag([mode])Set parameter broadcast mode for this cell.
set_comm_fusion(fusion_type[, recurse])Set comm_fusion for all the parameters in this cell.
set_data_parallel()For all primitive ops in this cell(including ops of cells that wrapped by this cell), if parallel strategy is not specified, then instead of auto-searching, data parallel strategy will be generated for those primitive ops.
set_dynamic_inputs(**kwargs)Compile static graphs into dynamic shapes
set_extra_state(state)Set extra state contained in the loaded state_dict.
set_grad([requires_grad])Sets the cell flag for gradient.
set_inputs(*inputs, **kwargs)Save set inputs for computation graph.
set_jit_config(jit_config)Set jit config for cell.
set_mixed_precision_type(self, arg0)Set mixed precision type.
set_train([mode])Sets the cell to training mode.
shard(in_strategy[, out_strategy, ...])Defining the input and output layouts of this cell and the parallel strategies of remaining ops will be generated by sharding propagation.
show_support_list()show_support_list method
slice_incremental_inputs(model_inputs, ...)used for non-first iterations, slice the inputs to length 1.
state_dict(*args[, destination, prefix, ...])Return a dictionary containing references to the whole state of the cell.
to(*args, **kwargs)Move and/or cast the parameters and buffers of this Cell (and all subcells).
to_empty([device, recurse])Patch for
nn.Cell.to_empty(init.md):param.set_data(mint.empty_like(...)).to_float(dst_type)Add cast on all inputs of cell and child cells to run with a certain float type.
trainable_params([recurse])Returns all trainable parameters.
untrainable_params([recurse])Returns all untrainable parameters.
update_cell_prefix()Update the param_prefix of all child cells.
update_cell_type(cell_type)The current cell type is updated when a quantization aware training network is encountered.
update_model_kwargs_before_generate(...)update model kwargs before generate.
update_padding_index_to_inputs(model_inputs)update_parameters_name([prefix, recurse])Adds the prefix string to the names of parameters.
Attributes
IGNORE_LISTT_destinationbase_modelThe main body of the model.
base_model_prefixbprop_debugGet whether cell custom bprop debug is enabled.
cell_init_argscls_namecompile_cachecompile_phasecompiledGet whether Cell is compiled in graph mode.
concat_mappingcreate_timeenable_backward_hookexist_namesGet exist parameter names adding by tuple or list of parameter.
exist_objsframeworkIdentifies that this is a Mindspore model.
global_cellsis_parallelizablejit_config_dictmain_input_nameparallel_parameter_merge_net_dictparallel_parameter_name_listparam_prefixParam prefix is the prefix of current cell's direct child parameter.
parameter_layout_dictparameter_layout_dict represents the tensor layout of a parameter, which is inferred by shard strategy and distributed operator information.
phasephase_cachepipeline_segmentpipeline_segment represents the pipeline segment of current Cell.
pipeline_stagepipeline_stage represents the pipeline stage of current Cell.
supports_gradient_checkpointingtotal_instance_countweight_convertersweight_mapping