HCIP-AI EI Developer study materials
HCIP-AI EI Developer study resources

HCIP-AI EI Developer: Python and AI Development Frameworks

HCIP-AI EI Developer · Work through your exam, one topic at a time.

All guide sections

Python and AI Development Frameworks

What this domain covers

The exam tests practical Python plus the tensor, dataset, and model APIs used in MindSpore and comparable frameworks.

Core rules and concepts

  • NumPy broadcasting aligns shapes from the right; a dimension of size 1 is stretched, otherwise the shapes must match.
  • Pandas: .loc is label-based, .iloc is position-based.
  • MindSpore tensors are created with mindspore.Tensor; dtype and device are explicit.
  • Execution mode is set with context.set_context(mode=context.GRAPH_MODE or PYNATIVE_MODE, device_target="Ascend"). GRAPH_MODE compiles the graph; PYNATIVE_MODE runs op-by-op for debugging.
  • A model subclasses nn.Cell, defines layers in __init__, and implements construct(), which is the forward function. PyTorch uses forward(); MindSpore calls construct() itself.
  • Datasets come from mindspore.dataset, with map, batch, and shuffle operations.

Worked example

class Net(nn.Cell):
    def __init__(self):
        super().__init__()
        self.fc1 = nn.Dense(784, 128)
        self.relu = nn.ReLU()
        self.fc2 = nn.Dense(128, 10)
    def construct(self, x):
        return self.fc2(self.relu(self.fc1(x)))

Reasoning: nn.Dense(in_channels, out_channels) is the fully connected layer; layers must be assigned as attributes so parameters register; construct is invoked by the framework, so never call net.construct(x) manually in training code.

Traps

Writing forward() in a MindSpore Cell; forgetting super().__init__(); mixing torch.nn and mindspore.nn imports; creating tensors before setting device_target; assuming GRAPH_MODE supports arbitrary Python side effects.