Text Generation
Transformers
PyTorch
Safetensors
Chinese
English
kclgpt
codeshell
wisdomshell
pku-kcl
openbankai
custom_code
Run this model with HF Jobs
Run WisdomShell/CodeShell-7B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/WisdomShell/CodeShell-7B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/WisdomShell/CodeShell-7B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/WisdomShell/CodeShell-7B. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/WisdomShell/CodeShell-7B. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use WisdomShell/CodeShell-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use WisdomShell/CodeShell-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="WisdomShell/CodeShell-7B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("WisdomShell/CodeShell-7B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use WisdomShell/CodeShell-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "WisdomShell/CodeShell-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "WisdomShell/CodeShell-7B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/WisdomShell/CodeShell-7B
- SGLang
How to use WisdomShell/CodeShell-7B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "WisdomShell/CodeShell-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "WisdomShell/CodeShell-7B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "WisdomShell/CodeShell-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "WisdomShell/CodeShell-7B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use WisdomShell/CodeShell-7B with Docker Model Runner:
docker model run hf.co/WisdomShell/CodeShell-7B
Update modeling_codeshell.py
Browse files456 unmodified lines4574584594604614624634644654664674684694704716 unmodified lines4784794804814824834844854864874884894901 unmodified line492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530428 unmodified lines959960961962963964456 unmodified linesGPT_BIGCODE_START_DOCSTRING = r"""This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods thelibrary implements for all its model (such as downloading or saving, resizing the input embeddings, pruning headsetc.)This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usageand behavior.Parameters:config ([`CodeShellConfig`]): Model configuration class with all the parameters of the model.Initializing with a config file does not load the weights associated with the model, only the6 unmodified lines`input_ids_length` = `sequence_length` if `past_key_values` is `None` else`past_key_values[0][0].shape[-2]` (`sequence_length` of input past key value states). Indices of inputsequence tokens in the vocabulary.If `past_key_values` is used, only `input_ids` that do not have their past calculated should be passed as`input_ids`.Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and[`PreTrainedTokenizer.__call__`] for details.[What are input IDs?](../glossary#input-ids)past_key_values (`Tuple[torch.Tensor]` of length `config.n_layers`):Contains precomputed hidden-states (key and values in the attention blocks) as computed by the model (see1 unmodified linetheir past given to this model should not be passed as `input_ids` as they have already been computed.attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:- 1 for tokens that are **not masked**,- 0 for tokens that are **masked**.If `past_key_values` is used, `attention_mask` needs to contain the masking strategy that was used for`past_key_values`. In other words, the `attention_mask` always has to have the length:`len(past_key_values) + len(input_ids)`[What are attention masks?](../glossary#attention-mask)token_type_ids (`torch.Tensor` of shape `(batch_size, input_ids_length)`, *optional*):Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:- 0 corresponds to a *sentence A* token,- 1 corresponds to a *sentence B* token.[What are token type IDs?](../glossary#token-type-ids)position_ids (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,config.max_position_embeddings - 1]`.[What are position IDs?](../glossary#position-ids)head_mask (`torch.Tensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:- 1 indicates the head is **not masked**,- 0 indicates the head is **masked**.inputs_embeds (`torch.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. Thisis useful if you want more control over how to convert `input_ids` indices into associated vectors than themodel's internal embedding lookup matrix.If `past_key_values` is used, optionally only the last `inputs_embeds` have to be input (see`past_key_values`).use_cache (`bool`, *optional*):428 unmodified linesprompt += ai_name.rstrip()max_new_tokens = max_new_tokens or self.generation_config.max_new_tokensmax_input_tokens = self.config.n_positions - max_new_tokensinput_tokens = tokenizer.encode(prompt)456 unmodified lines4574584594604614624634644654664674686 unmodified lines4754764774784794804814824834841 unmodified line486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515428 unmodified lines944945946947948949950456 unmodified linesGPT_BIGCODE_START_DOCSTRING = r"""This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods thelibrary implements for all its model (such as downloading or saving, resizing the input embeddings, pruning headsetc.)This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usageand behavior.Parameters:config ([`CodeShellConfig`]): Model configuration class with all the parameters of the model.Initializing with a config file does not load the weights associated with the model, only the6 unmodified lines`input_ids_length` = `sequence_length` if `past_key_values` is `None` else`past_key_values[0][0].shape[-2]` (`sequence_length` of input past key value states). Indices of inputsequence tokens in the vocabulary.If `past_key_values` is used, only `input_ids` that do not have their past calculated should be passed as`input_ids`.Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and[`PreTrainedTokenizer.__call__`] for details.[What are input IDs?](../glossary#input-ids)past_key_values (`Tuple[torch.Tensor]` of length `config.n_layers`):Contains precomputed hidden-states (key and values in the attention blocks) as computed by the model (see1 unmodified linetheir past given to this model should not be passed as `input_ids` as they have already been computed.attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:- 1 for tokens that are **not masked**,- 0 for tokens that are **masked**.If `past_key_values` is used, `attention_mask` needs to contain the masking strategy that was used for`past_key_values`. In other words, the `attention_mask` always has to have the length:`len(past_key_values) + len(input_ids)`[What are attention masks?](../glossary#attention-mask)token_type_ids (`torch.Tensor` of shape `(batch_size, input_ids_length)`, *optional*):Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:- 0 corresponds to a *sentence A* token,- 1 corresponds to a *sentence B* token.[What are token type IDs?](../glossary#token-type-ids)position_ids (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,config.max_position_embeddings - 1]`.[What are position IDs?](../glossary#position-ids)head_mask (`torch.Tensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:- 1 indicates the head is **not masked**,- 0 indicates the head is **masked**.inputs_embeds (`torch.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. Thisis useful if you want more control over how to convert `input_ids` indices into associated vectors than themodel's internal embedding lookup matrix.If `past_key_values` is used, optionally only the last `inputs_embeds` have to be input (see`past_key_values`).use_cache (`bool`, *optional*):428 unmodified linesprompt += ai_name.rstrip()max_new_tokens = max_new_tokens or self.generation_config.max_new_tokensmax_new_tokens = max_new_tokens or 128max_input_tokens = self.config.n_positions - max_new_tokensinput_tokens = tokenizer.encode(prompt)
modeling_codeshell.py+1-15